victronenergy / node-red-contrib-victron

MIT License
87 stars 18 forks source link

Prepare for the D-Bus dict-updates #96

Closed dirkjanfaber closed 2 years ago

dirkjanfaber commented 2 years ago

See https://github.com/victronenergy/venus/issues/789

The Venus OS is going to reduce the D-Bus traffic in a (near) future update.

In the current situation devices send multiple PropertiesChanged signals every second for each D-Bus path. In the new situation only one PropertiesChanged signal is send every (for example) second, from root, with a Dict with all paths that have an updated value.

The node-red-contrib-victron code needs to be prepared for this change.

dirkjanfaber commented 2 years ago

Thanks to Izak for giving me instructions on how to test this. In order to monitor what changes from the root perspective: dbus-monitor --system path=/,member=PropertiesChanged. Further instructions:

In order to get the new situation to work on the dbus: swap out the velib_python that is used by systemcalc with this one: https://github.com/victronenergy/velib_python/tree/dict_updates. Then that changes any service that uses the "Dummy service" code to send dict updates. So you could then simply use something like dummypvinverter.py (in the scripts directory in systemcalc), call it from the systemcalc directory eg python3 scripts/dummypvinverter.py. That should send some dict updates.

dirkjanfaber commented 2 years ago

First thing to notice, when replacing the library with the new one, is that the code still seems to work, but only sees one in 5 updates. Now to figure out how to add the missing updates.

dirkjanfaber commented 2 years ago

What needs to be changed is src/services/victron-client.js, around line 42. As each incoming message now can contain multiple paths, it needs to be restructured.

dirkjanfaber commented 2 years ago

The above branch works with the sample code, but is likely too limited.

dirkjanfaber commented 2 years ago

Separating the messages based on path. If it is coming from the root path, the messages can contain multiple paths. Looping through each of the paths and triggering a callback for each one. The code remains backward compatible for the still current way of updating. The value is taken directly from the bus. Tested this with integer, double, strings and booleans.