20 lines
756 B
Python
20 lines
756 B
Python
|
import influxdb_client
|
||
|
from influxdb_client.client.write_api import SYNCHRONOUS
|
||
|
from dotenv import load_dotenv
|
||
|
import os
|
||
|
|
||
|
dotenv_path = join(dirname(__file__), '.env')
|
||
|
load_dotenv(dotenv_path)
|
||
|
|
||
|
bucket=os.environ.get('INFLUX_BUCKET')
|
||
|
org=os.environ.get('INFLUX_ORG')
|
||
|
token=os.environ.get('INFLUX_TOKEN')
|
||
|
url=os.environ.get('INFLUX_URL')
|
||
|
|
||
|
client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)
|
||
|
write_api = client.write_api(write_options=SYNCHRONOUS)
|
||
|
|
||
|
|
||
|
def publish_measurement(value):
|
||
|
p = influxdb_client.Point(f'KNX-{value["type"]}').tag("name", f'{value["name"]}').tag("destination", f'{value["destination"]}').tag("description", f'{value["description"]}').field("value", value["value"])
|
||
|
write_api.write(bucket=bucket, org=org, record=p)
|