forked from Dr-Gigavolt/dbus-aggregate-batteries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbusmon.py
138 lines (117 loc) · 4.68 KB
/
dbusmon.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
# Version 2.2
import sys
sys.path.append('/opt/victronenergy/dbus-systemcalc-py/ext/velib_python')
from dbusmonitor import DbusMonitor
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
import logging
class DbusMon:
def __init__(self):
dummy = {'code': None, 'whenToLog': 'configChange', 'accessLevel': None}
self.monitorlist = {'com.victronenergy.battery': {
'/Connected': dummy,
'/ProductName': dummy,
'/CustomName': dummy,
'/Mgmt/Connection': dummy,
'/DeviceInstance': dummy,
'/Dc/0/Voltage': dummy,
'/Dc/0/Current': dummy,
'/Dc/0/Power': dummy,
'/InstalledCapacity': dummy,
'/ConsumedAmphours': dummy,
'/Capacity': dummy,
'/Soc': dummy,
'/Dc/0/Temperature': dummy,
'/System/MaxCellTemperature': dummy,
'/System/MinCellTemperature': dummy,
'/System/MaxVoltageCellId': dummy,
'/System/MaxCellVoltage': dummy,
'/System/MinVoltageCellId': dummy,
'/System/MinCellVoltage': dummy,
'/System/NrOfCellsPerBattery': dummy,
'/System/NrOfModulesOnline': dummy,
'/System/NrOfModulesOffline': dummy,
'/System/NrOfModulesBlockingCharge': dummy,
'/System/NrOfModulesBlockingDischarge': dummy,
'/Alarms/LowVoltage': dummy,
'/Alarms/HighVoltage': dummy,
'/Alarms/LowCellVoltage': dummy,
'/Alarms/HighCellVoltage': dummy,
'/Alarms/LowSoc': dummy,
'/Alarms/HighChargeCurrent': dummy,
'/Alarms/HighDischargeCurrent': dummy,
'/Alarms/CellImbalance': dummy,
'/Alarms/InternalFailure_alarm': dummy,
'/Alarms/HighChargeTemperature': dummy,
'/Alarms/LowChargeTemperature': dummy,
'/Alarms/HighTemperature': dummy,
'/Alarms/LowTemperature': dummy,
'/Io/AllowToCharge': dummy,
'/Io/AllowToDischarge': dummy,
'/Voltages/Cell1': dummy,
'/Voltages/Cell2': dummy,
'/Voltages/Cell3': dummy,
'/Voltages/Cell4': dummy,
'/Voltages/Cell5': dummy,
'/Voltages/Cell6': dummy,
'/Voltages/Cell7': dummy,
'/Voltages/Cell8': dummy,
'/Voltages/Cell9': dummy,
'/Voltages/Cell10': dummy,
'/Voltages/Cell11': dummy,
'/Voltages/Cell12': dummy,
'/Voltages/Cell13': dummy,
'/Voltages/Cell14': dummy,
'/Voltages/Cell15': dummy,
'/Voltages/Cell16': dummy,
'/Voltages/Cell17': dummy,
'/Voltages/Cell18': dummy,
'/Voltages/Cell19': dummy,
'/Voltages/Cell20': dummy,
'/Voltages/Cell21': dummy,
'/Voltages/Cell22': dummy,
'/Voltages/Cell23': dummy,
'/Voltages/Cell24': dummy,
'/Voltages/Cell25': dummy,
'/Voltages/Cell26': dummy,
'/Voltages/Cell27': dummy,
'/Voltages/Cell28': dummy,
'/Voltages/Cell29': dummy,
'/Voltages/Cell30': dummy,
'/Voltages/Cell31': dummy,
'/Voltages/Cell32': dummy,
'/Voltages/Diff': dummy,
'/Voltages/Sum': dummy,
'/Info/MaxChargeCurrent': dummy,
'/Info/MaxDischargeCurrent': dummy,
'/Info/MaxChargeVoltage': dummy},
'com.victronenergy.vebus': {
'/Dc/0/Current': dummy,
'/ProductName': dummy},
'com.victronenergy.solarcharger': {
'/Dc/0/Current': dummy,
'/ProductName': dummy}
}
self.dbusmon = DbusMonitor(self.monitorlist)
def print_values(self, service):
for path in self.monitorlist['com.victronenergy.battery']:
logging.info('%s: %s' % (path, self.dbusmon.get_value(service, path)))
logging.info('\n')
return True
################
# test program #
################
def main():
logging.basicConfig(level=logging.INFO)
DBusGMainLoop(set_as_default=True)
batterymonitor = BatteryMonitor()
#GLib.timeout_add(1000, batterymonitor.print_values, 'com.victronenergy.battery.ttyUSB2')
batterymonitor.print_values('com.victronenergy.vebus.ttyUSB0')
batterymonitor.print_values('com.victronenergy.solarcharger.ttyUSB1')
# Start and run the mainloop
logging.info("Battery monitor: Starting mainloop.\n")
mainloop = GLib.MainLoop()
mainloop.run()
if __name__ == "__main__":
main()