12345678910111213141516171819 |
- from influxdb_client import InfluxDBClient, Point
- from influxdb_client.client.write_api import SYNCHRONOUS
- class InfluxDB:
- def __init__(self):
- self.client = InfluxDBClient(url="http://localhost:8086", token="XPBViJ3s4JL9_wPffwd5M2EgXj5hcUgT0n4jNhv7m6-NC-6SSxQ3run4kXtWBvOk-FYr1VG5Tj5WcoHgjge9jw==", 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)
|