2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RaspbeeryPiからのセンサーデータの可視化(SORACOM Harvest編)

Last updated at Posted at 2018-07-16

#目的
RaspberryPiで取得したセンサーデータをSORACOM Harvestに送信(JSON形式)

#参照
SORACOM公式サイト
SORACOM Harvest でデバイスのデータをクラウドで収集・取得・可視化する

温湿度データ取得のget_temp()については、以下参照
RaspberryPiでDHT11センサーから温湿度データを取得

#SORACOM Harvestの設定

#ソースコード

sendharvest.py
# coding: UTF-8

import sys
import time
import json
import requests
from gettemp import get_temp

while True:

    try:
        # 温湿度データ取得
        temperature, humidity = get_temp()
        if temperature == 0:
            continue

        # jsondata編集
        data = {"temperature": temperature, "humidity": humidity}

        # SORACOM Harvestに送信
        r = requests.post('http://harvest.soracom.io', data=json.dumps(data),
                          headers={'Content-Type': 'application/json'})
        print r
    except:
        pass

    # 指定された秒数スリープ
    time.sleep(30)

#実行
実行
sudo python sendharvest.py

※成功するとレスポンスコード201が返ってきます

実行結果をSORACOMのコンソールから確認。
赤い線が温度、青い線が湿度です。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?