annotate victron.py @ 33:7125b13d0528

Hide complaints from mkdir
author Daniel O'Connor <darius@dons.net.au>
date Mon, 13 Dec 2021 23:04:12 +1030
parents 91bfaba8f6b6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 #!/usr/bin/env python
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 import dbus
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 import time
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 class Victron(object):
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 def __init__(self, obj):
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 self.obj = obj
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 self.bus = dbus.SystemBus()
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 def get_data(self):
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 ACIn_L1_volts = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/V').GetValue().real
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 ACIn_L1_freq = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/F').GetValue().real
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 ACIn_L1_current = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/I').GetValue().real
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 ACIn_active = bool(self.bus.get_object(self.obj, '/Ac/ActiveIn/Connected').GetValue())
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 ACOut_L1_volts = self.bus.get_object(self.obj, '/Ac/Out/L1/V').GetValue().real
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 ACOut_L1_freq = self.bus.get_object(self.obj, '/Ac/Out/L1/F').GetValue().real
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 ACOut_L1_current = self.bus.get_object(self.obj, '/Ac/Out/L1/I').GetValue().real
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 Battery_Voltage = self.bus.get_object(self.obj, '/Dc/0/Voltage').GetValue().real
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 Battery_Current = self.bus.get_object(self.obj, '/Dc/0/Current').GetValue().real
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 def main():
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 v = Victron('com.victronenergy.vebus.ttyUSB0')
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 while True:
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 try:
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 v.get_data()
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 except (AttributeError, dbus.exceptions.DBusException) as e:
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 print('Error getting data, sleeping 30 seconds:', str(e))
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 time.sleep(25)
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 time.sleep(5)
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 if __name__ == '__main__':
91bfaba8f6b6 Add victron dbus parser
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 main()