Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
post data to influxdb
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Download data from webpage after POST request AlDe 0 2,200 Feb-02-2019, 06:26 AM
Last Post: AlDe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020