Mercurial > ~darius > hgwebdir.cgi > vanlogger
changeset 31:91bfaba8f6b6
Add victron dbus parser
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 13 Dec 2021 18:16:39 +1030 |
parents | a9df202d14b7 |
children | b6f96e8738ca |
files | victron.py |
diffstat | 1 files changed, 34 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/victron.py Mon Dec 13 18:16:39 2021 +1030 @@ -0,0 +1,34 @@ +#!/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()