Cambio versione a influxdb3 per usare InfluxQL per le query

This commit is contained in:
2025-05-31 15:48:46 +02:00
parent 5f34f3169a
commit 25536e0842
6 changed files with 51 additions and 56 deletions

View File

@@ -7,9 +7,7 @@ import logging
import signal
import json
from influxdb_client.client.write.point import Point
from influxdb_client.client.influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import ASYNCHRONOUS, SYNCHRONOUS
from influxdb_client_3 import InfluxDBClient3, Point
# Get environment variables
env = dict(os.environ)
@@ -56,10 +54,9 @@ def main():
LOGGER.debug(json.dumps(env, indent=2))
run: SignalHandler = SignalHandler()
port = serial.Serial(port=env['PORT'], baudrate=int(env['BAUD']), bytesize=8, parity='N', stopbits=1)
write_client = InfluxDBClient(url=env['INFLUXDB_URL'],
write_client = InfluxDBClient3(host=env['INFLUXDB_URL'],
token=env['INFLUXDB_TOKEN'],
org=env['INFLUXDB_ORG'])
write_api = write_client.write_api(write_options=ASYNCHRONOUS)
database=env['INFLUXDB_DATABASE'])
while run.running:
try:
send(port, "Q1")
@@ -82,7 +79,7 @@ def main():
p = Point('ups')
for k,v in values.items():
p.field(k,v)
write_api.write(bucket=env['INFLUXDB_BUCKET'], org=env['INFLUXDB_ORG'], record=p)
write_client.write(record=p)
time.sleep(INTERVAL)
except Exception as e:
print(f"Unexpected exception: [{e}]")

View File

@@ -2,7 +2,7 @@ FROM python:3.12-alpine
RUN apk update && apk upgrade --no-cache
RUN pip install --no-cache-dir pyserial RouterOS-API influxdb-client
RUN pip install --no-cache-dir pyserial RouterOS-API influxdb3-python
COPY ./ups.py /home/ups.py