31
|
1 #!/usr/bin/env python
|
|
2
|
|
3 import dbus
|
|
4 import time
|
|
5
|
|
6 class Victron(object):
|
|
7 def __init__(self, obj):
|
|
8 self.obj = obj
|
|
9 self.bus = dbus.SystemBus()
|
|
10
|
|
11 def get_data(self):
|
|
12 ACIn_L1_volts = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/V').GetValue().real
|
|
13 ACIn_L1_freq = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/F').GetValue().real
|
|
14 ACIn_L1_current = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/I').GetValue().real
|
|
15 ACIn_active = bool(self.bus.get_object(self.obj, '/Ac/ActiveIn/Connected').GetValue())
|
|
16 ACOut_L1_volts = self.bus.get_object(self.obj, '/Ac/Out/L1/V').GetValue().real
|
|
17 ACOut_L1_freq = self.bus.get_object(self.obj, '/Ac/Out/L1/F').GetValue().real
|
|
18 ACOut_L1_current = self.bus.get_object(self.obj, '/Ac/Out/L1/I').GetValue().real
|
|
19 Battery_Voltage = self.bus.get_object(self.obj, '/Dc/0/Voltage').GetValue().real
|
|
20 Battery_Current = self.bus.get_object(self.obj, '/Dc/0/Current').GetValue().real
|
|
21 return ACIn_L1_volts, ACIn_L1_freq, ACIn_L1_current, ACIn_active, ACOut_L1_volts, ACOut_L1_freq, ACOut_L1_current, Battery_Voltage, Battery_Current
|
|
22
|
|
23 def main():
|
|
24 v = Victron('com.victronenergy.vebus.ttyUSB0')
|
|
25 while True:
|
|
26 try:
|
|
27 v.get_data()
|
|
28 except (AttributeError, dbus.exceptions.DBusException) as e:
|
|
29 print('Error getting data, sleeping 30 seconds:', str(e))
|
|
30 time.sleep(25)
|
|
31 time.sleep(5)
|
|
32
|
|
33 if __name__ == '__main__':
|
|
34 main()
|