Mercurial > ~darius > hgwebdir.cgi > vanlogger
view victron.py @ 34:5b03de9fb20b default tip
Log that we logged some data.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Tue, 14 Dec 2021 13:10:27 +1030 |
parents | 91bfaba8f6b6 |
children |
line wrap: on
line source
#!/usr/bin/env python import dbus import time class Victron(object): def __init__(self, obj): self.obj = obj self.bus = dbus.SystemBus() def get_data(self): ACIn_L1_volts = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/V').GetValue().real ACIn_L1_freq = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/F').GetValue().real ACIn_L1_current = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/I').GetValue().real ACIn_active = bool(self.bus.get_object(self.obj, '/Ac/ActiveIn/Connected').GetValue()) ACOut_L1_volts = self.bus.get_object(self.obj, '/Ac/Out/L1/V').GetValue().real ACOut_L1_freq = self.bus.get_object(self.obj, '/Ac/Out/L1/F').GetValue().real ACOut_L1_current = self.bus.get_object(self.obj, '/Ac/Out/L1/I').GetValue().real Battery_Voltage = self.bus.get_object(self.obj, '/Dc/0/Voltage').GetValue().real Battery_Current = self.bus.get_object(self.obj, '/Dc/0/Current').GetValue().real 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 def main(): v = Victron('com.victronenergy.vebus.ttyUSB0') while True: try: v.get_data() except (AttributeError, dbus.exceptions.DBusException) as e: print('Error getting data, sleeping 30 seconds:', str(e)) time.sleep(25) time.sleep(5) if __name__ == '__main__': main()