Notifications
Clear all

Raspberry Pi Send Data to Favoriot [Video]

Mazlan Abbas
(@mazlan-abbas)
Trusted Member Moderator

https://www.youtube.com/watch?v=7ER4_cWE7No

By Shahrul Nizam

All details HERE.

import time
import Adafruit_DHT
import requests
import json
from decimal import Decimal

sensor = Adafruit_DHT.DHT22
pin = 18
url = "https://api.favoriot.com/v1/streams"
headers = {
    'apikey': "YOUR API KEY HERE",
    'content-type': "application/json"
    }

while 1:
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    if humidity is not None and temperature is not None:
        root = {}
        root["device_developer_id"] = "Sensor@Shahrul"
        data = {}
        data["temperature"] = round(temperature,1)
        data["humidity"] = round(humidity,1)
        root["data"] = data       
        body = json.dumps(root)
        print body
        response = requests.request("POST", url, headers=headers, data=body)
        print response.text
        print ""
    else:
        print "Failed to get reading. Try again!"
    time.sleep(1)
This topic was modified 2 years ago 2 times by Mazlan Abbas
Quote
Topic starter Posted : 07/04/2019 9:07 pm
Share:

Copyright © 2021 All rights reserved