-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (30 loc) · 920 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import time
from ksem import KSEM
from piko15 import Piko15
from influx_client import InfluxClient
def create_points(instance, ts=None):
points = []
meta_tags = instance.tags
for result in instance.get_results(ts):
fields = dict(value=result['value'])
point = InfluxClient.create_idb_point(
measurement_name=result['measurement'],
tags=meta_tags,
fields=fields,
ts=result['ts']
)
points.append(point)
return points
def run():
client = InfluxClient()
ksem = KSEM()
inverter = Piko15()
while True:
ts = time.time_ns()
points = [*create_points(ksem, ts), *create_points(inverter, ts)]
if len(points) > 0:
client.write_points('PV', points)
print(f"[{len(points)}] Points written to influxdb")
time.sleep(1)
if __name__ == '__main__':
run()