Python Forum

Full Version: post data to influxdb
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi .. i have a problem to send a data to influx db. here i have 2 code, need to modified

this is for reading a sensor
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)
the another one if for write in influxdb

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
token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
org = "XXXX"
bucket = "DHT22"

client = InfluxDBClient(url="https:XXXXXXXXXX", token=token)



write_api = client.write_api(write_options=SYNCHRONOUS)

data = "room1,host=raspberry1 temperature=43.43234543"
i have to sample code. one for sending / push data to influx and one for reading temperature sensor. anybody can help me how
combine this two sample code