-
Notifications
You must be signed in to change notification settings - Fork 14
/
logupower.py
executable file
·66 lines (59 loc) · 1.73 KB
/
logupower.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
import sys
import datetime
import time
import minimalmodbus
from influxdb import InfluxDBClient
from UPower import *
# influx configuration - edit these
ifuser = "grafana"
ifpass = "solar"
ifdb = "solar"
ifhost = "127.0.0.1"
ifport = 8086
measurement_name = "solar"
up = UPower()
if (up.connect() < 0):
print "Could not connect to the device"
exit -2
# get timestamps
localtime = time.localtime()
timestamp = time.strftime("%H:%M:%S", localtime)
timestamp = datetime.datetime.utcnow()
# form a data record
body_solar = [
{
"measurement": measurement_name,
"time": timestamp,
"fields": {
"PVvolt": up.readReg(PVvolt),
"PVamps": up.readReg(PVamps),
"PVwatt": up.readReg(PVwattL),
"PVkwh": up.readReg(PVkwhL),
"PVtemp": up.readReg(PVtemp),
"BAvolt": up.readReg(BAvolt),
"BAamps": up.readReg(BAamps),
"BAwatt": up.readReg(BAwattL),
"BAah": up.readReg(BAah),
"BAtemp": up.readReg(BAtemp),
"ACvoltIN": up.readReg(ACvoltIN),
"ACvolt": up.readReg(ACvolt),
"ACamps": up.readReg(ACamps),
"ACwatt": up.readReg(ACwattL),
"ACtemp": up.readReg(ACtemp),
"IVwattL": up.readReg(IVwattL),
"IVwattH": up.readReg(IVwattH),
"IVherz": up.readReg(IVherz),
"IVvoltIN": up.readReg(IVvoltIN),
"IVvolt": up.readReg(IVvolt),
"IVamps": up.readReg(IVamps),
"IVstat": up.getIV(),
"ACstat": up.getAC()
}
}
]
print body_solar
# connect to influx
ifclient = InfluxDBClient(ifhost,ifport,ifuser,ifpass,ifdb)
# write the measurement
ifclient.write_points(body_solar)