i have a problem how to post temperature and humidity data into cloud. anybody can help me how to write a phyton program. i have a draf as below. but not working
from datetime import datetime
import Adafruit_DHT
import time
import network
DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
You can generate a Token from the “Tokens Tab” in the UI
data = “room1,host=raspberry1 temperature=43.43234543”
data = “room1,host=raspberry1 humidity=83.43234543”
write_api.write(bucket, org, data)
while True:
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("Temp={0:0.1f}*C Humidity={1:0.1f}% ".format(temperature, humidity))
print(temperature, humidity)
else:
print("Failed to retrieve data from humidity sensor")
time.sleep(3)
@shahrilmajid - welcome to the community! What error are you seeing? You didn’t explain what is not working. You appear to be using the InfluxDBClient correctly except you are only writing the humidity value because you are overwriting data. Use two calls to write_api.write(bucket, org, data). If you are having problems with the Adafruit library, we likely won’t be able to help you with those here.
from datetime import datetime
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
You can generate a Token from the “Tokens Tab” in the UI
#----------------------------------------------------------------
import Adafruit_DHT
import time
import network
DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4
while True:
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("Temp={0:0.1f}*C Humidity={1:0.1f}% ".format(temperature, humidity))
print(temperature, humidity)
else:
print("Failed to retrieve data from humidity sensor")
time.sleep(3)
#___--
data = “room1,host=raspberry1 temperature=(temperature)”
write_api.write(bucket, org, data)
Per the error message, you have an extra in the line protocol right after room1,. The tag key host has to come right after the measurement name and comma like room1,host=raspberry1 ...