-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (33 loc) · 974 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 sdm_modbus, configparser
from time import sleep
from influxdb import InfluxDBClient
config = configparser.ConfigParser()
config.read_file(open('./token.config', mode='r'))
host = config.get('config', 'host')
user = config.get('config', 'user')
password = config.get('config', 'password')
dbname = config.get('config', 'dbname')
client = InfluxDBClient(host, 8086, user, password, dbname)
meter = sdm_modbus.SDM120(
device='/dev/ttyUSB0',
stopbits=1,
parity='N',
baud=9600,
timeout=2,
unit=1
)
def write(data):
write_data = {}
write_data['measurement'] = "energy"
write_data['tags'] = {}
write_data['fields'] = data
write_data['tags']['name'] = "SDM120"
if client.write_points([write_data]):
return
else:
print("Daten konnten nicht gesendet werden.")
if __name__ == '__main__':
while True:
data = meter.read_all(sdm_modbus.registerType.INPUT)
write(data)
sleep(1)