Notifications
Clear all

Raspberry Pi Send Data to Favoriot [Video]

1 Posts
1 Users
0 Likes
1,316 Views
Mazlan Abbas
(@mazlan-abbas)
Posts: 93
Member
Topic starter
 

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 5 years ago 2 times by Mazlan Abbas
 
Posted : 07/04/2019 9:07 pm
Share:

Copyright © 2024 All rights reserved