I have a Cerbo GX to which I have added two services which communicates using the dbus.
The two services are:
Service A: An MQTT client which receives updates five times a second and writes that to the dbus for Service B.
Service B: Performs actions based on the value set by Service A. Detected with the onchangecallback method.
Sometimes (as in after several hours it seems) it times out and it wont work again until the service is restarted.
The problem is that I can't seem to figure out a way to detect a timeout (beyond maybe checking the time passed). My question is if there is a way to get a timeout error or callback when this happens? Or if I'm doing something fundamentally wrong when writing my services?
Here is the code I'm using when receiving an MQTT message:
def on_message(self, msg): payload = msg.payload.decode() jsonPayload = json.loads(payload) frequency = jsonPayload["frequency"] self._dbusservice['/Frequency'] = frequency has_service_b = 'com.victronenergy.service-b.ttyO1' in self._dbusservice.dbusconn.list_names() if has_service_b: item_import = VeDbusItemImport( bus=self._dbusservice.dbusconn, serviceName='com.victronenergy.service-b.ttyO1', path='/Frequency', eventCallback=None, createsignal=True ) item_import.set_value(frequency)
In the above example it is the init of VeDbusItemImport which seems to timeout.
Before I used to do the opposite, meaning Service B reads the value from Service A but then the problem seemed to occur more frequently than when writing from Service A to Service B.
Any help would be appreciated because I'm quite stumped as to what the problem actually is or how to deal with it. Worst case I guess measuring the write time myself and do exit_on_error is a way forward but it seems a bit hacky :)