question

rkrantz avatar image
rkrantz asked

Occasional timeout when writing to DBus

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 :)


Venus OSpython
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

2 Answers
jeroen avatar image
jeroen answered ·

Well not sure about this particular case, but if service A and service B make blocking calls on each other, you can get into such a situation, since A is waiting for a reply from B (which won't be processed, since it is blocking) and B is waiting for a reply from A (which also won't be processed, since it is waiting for B).

In general you shouldn't do blocking calls, have a look at set_value_async.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

gone-sailing avatar image
gone-sailing answered ·

If you are doing updates 5 times a second, do you need to go through both mqtt and dbus? Could the two services just communicate through mqtt and only write to the bus when actually needed?

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Related Resources

Additional resources still need to be added for this topic

Victron Venus OS Open Source intro page

Venus OS GitHub (please do not post to this)