12345678910111213141516171819 |
- from influxdb_client import InfluxDBClient, Point
- from influxdb_client.client.write_api import SYNCHRONOUS
- class Database():
- def __init__(self):
- self.client = InfluxDBClient(url="http://localhost:8086", token="Jqv8THpAkRo3zzSQjz-mOHJDNJk3FzL8pDkbgPvgjMUwHigBEGbFJdbcoFJlauURkTaWvHUqJ_yiO9xYN66NXA==", org="laempe")
- self.bucket = "energy-monitor"
- self.write_api = self.client.write_api(write_options=SYNCHRONOUS)
- self.query_api = self.client.query_api()
- def write(self, values):
- points = []
- for meas in values:
- p = Point("24v").time(meas.timestamp).tag("source", meas.source).tag("channel", meas.channel).field("current", meas.current)
- points.append(p)
-
- self.write_api.write(bucket=self.bucket, record=points)
|