Clear all

Raspberry Pi Send Data to Favoriot [Video]

Mazlan Abbas
Trusted Member Moderator

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 = ""
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 ""
        print "Failed to get reading. Try again!"
This topic was modified 2 years ago 2 times by Mazlan Abbas
Topic starter Posted : 07/04/2019 9:07 pm

Copyright © 2021 All rights reserved