influxdb.py 761 B

12345678910111213141516171819
  1. from influxdb_client import InfluxDBClient, Point
  2. from influxdb_client.client.write_api import SYNCHRONOUS
  3. class InfluxDB:
  4. def __init__(self):
  5. self.client = InfluxDBClient(url="http://localhost:8086", token="XPBViJ3s4JL9_wPffwd5M2EgXj5hcUgT0n4jNhv7m6-NC-6SSxQ3run4kXtWBvOk-FYr1VG5Tj5WcoHgjge9jw==", org="laempe")
  6. self.bucket = "energy-monitor"
  7. self.write_api = self.client.write_api(write_options=SYNCHRONOUS)
  8. self.query_api = self.client.query_api()
  9. def write(self, values):
  10. points = []
  11. for meas in values:
  12. p = Point("24v").time(meas.timestamp).tag("source", meas.source).tag("channel", meas.channel).field("current", meas.current)
  13. points.append(p)
  14. self.write_api.write(bucket=self.bucket, record=points)