question

flovic avatar image
flovic asked

Some MQTT topics stop getting updated for a while

I have a strange problem that I couldn't get a firm hold on yet...


I'm using dbus-serialbattery for a JK BMS and I'm reading values from Victron via MQTT into HomeAssistant (my main mosquitto is bridged to the venus one).

Every day, around the same time e.g. the StateOfCharge is not updated anymore. After 5-60 minutes it's working again. Other values for the battery are still published/updated via MQTT.

Also it's strange that e.g. the SoC is suddenly increasing or dropping (e.g. from 30% to 42%). This is only for the MQTT value. I'm reading from the JK BMS also directly via BLE and I don't see that spike. Also in VRM it's not visible. And the console seems to show the correct value.


Using dbus-spy I see that the values are correct in DBUS. I've also check if the bridge between the mosquittos might be a problem, but connecting directly to the venus one, it has the same issue.


My hunch is that the problem might be a part of dbus-mqtt. But I'm not sure how to debug this.


Did anyone else have a similar experience? Or tips on how to debug this?





MQTT
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
captainpalapa avatar image
captainpalapa answered ·

(Please note: I came up with the solution near the bottom of this reply...as I wrote this entire post.)

When I have the http://venus.local/app/ open, immediately it tells me "Your Dashboard is Empty. Make sure your services are properly connected."

1701058650906.png

Everything is enabled as it's supposed to. After a few seconds, data will start coming in to the dashboard.

1701058685805.png

I didn't even know about the venus.local/app until today. I've connected to the IP straight up which mirrors the control panel nicely), shown here, plenty of times.

1701058604305.png

However, the Venus web app is doing something else. When I watch the mqtt topics with MQTT-Explorer (great app, by the way), the topics simply do not exist when I connect. But if I start up the Venus app, when IT starts receiving data, so does MQTT-Explorer, but not until.

Before I start the Venus app web page, showing MQTT-Explorer:

1701056762074.png

After I start the Venus app pages, after a few seconds, the MQTT-Explorer lights up with the expected topics:

1701056832717.png

After I close the Venus app web page, after a bit they go away again:

1701056730821.png


In the middle screenshot, notice the >R topic at the bottom:

1701056869751.png

That was added by the Venus app webpage code, somehow. I can't see anything in the Chrome headers for the websocket connection that seem overly obvious to me, but I'm not very familiar with websockets. Here is the entire JSON for that keepalive key:

[
  "N/+/system/0/Serial",
  "settings/0/Settings/System/VncLocal",
  "system/0/Dc/Battery/Voltage",
  "system/0/Dc/Battery/Current",
  "system/0/Dc/System/Power",
  "system/0/Batteries",
  "system/0/Dc/Pv/Power",
  "system/0/Dc/Pv/Current",
  "charger/+/DeviceInstance",
  "inverter/+/DeviceInstance",
  "vebus/+/DeviceInstance",
  ...plus 50 more lines I removed for brevity
]

While the Venus app is connected, the primary topic values update frequently, about every 5 seconds it seems. I'm specifically watching key "N/e8eb11e512f4/system/0/Batteries" because it is a JSON object with several values in it.

After I've closed the Venus app page, and disconnect/reconnect MQTT-Explorer (which refreshes the available topics), that keepalive key is no longer visible.

Connecting directly to the mqtt server in the Victron setup (mosquitto version 1.6.10), or connecting to my own mosquitto server (mosquitto version 2.0.18) and utilizing a bridged connection -- neither show the topics I'm looking for.

SUCCESSFUL RESULTS:

It's quite obvious that the giant array above contains topics. I grabbed the system/0/batteries value and did a publish of:

R/e8eb11e512f4/keepalive with a value of ["system/0/Batteries"]

This IMMEDIATELY causes that SINGLE item to appear and refresh every 5 seconds, both in the direct connection and in the bridged connection:

1701057573865.pngThis is my own MQTT server, showing the bridge connection receiving the updates.

After about 1 minute, the Batteries topic disappears. It seems to me that this is some sort of power-saving feature, reducing CPU overhead by not pushing data from the source to the mqtt server topics. Unless someone is actively seeking it. This means that a simple bridged connection won't pull new data, because it's not there. Any app or dashboard will have to republish that keepalive message to ensure that the keys you seek are published. Interestingly enough, I was able to publish the same message to the bridged mqtt broker and it is transferred across, but only because of my mosquitto.conf for that connection, using the "both" keyword.

# -----------------------------------------------------------------------------
# Bring in topics from other MQTT brokers (in 0, 0 represents QoS)
# -----------------------------------------------------------------------------
# Bridge Victron Topics to DWO Dragon Mosquitto
connection dwo-to-victron
address 192.168.60.16:1883
keepalive_interval 10
start_type automatic
remote_clientid dwo-dragon-mosquitto
try_private false
cleansession true
topic N/e8eb11e512f4/system/0/Batteries both 0
topic N/e8eb11e512f4/system/0/Serial both 0
topic R/e8eb11e512f4/keepalive both 0

I hope all this information helps someone who stumbles across this. Basically, tl;dr is you have to push a keepalive to the server every (less than 1 minute) to keep the topics you seek continuing to be published.

Please note: I'm NOT any kind of mqtt expert. In fact, other than looking at all this about two years ago, going "poke, poke, huh??" and then the last two days reading up on mqtt and trying to get a bedtter grip on it, then running into this problem, and TEARING it all apart and EXPERIMENTING, that's all I know.

Maybe the keepalive is a standards or protocol thing, but I suspect not. I more suspect this is what Victron is looking for under the hood to save power and CPU cycles. (They are a "power company", you know.) Earlier today, I connected to the testing server (aka "you shouldn't use it for anything production or expect consistent results and it's all publicly visible") at test.mosquitto.org and I saw thousands of topics being updated, without my pushing any data to it whatsoever.

What I'd like to know is if there is a setting, a more "passive", or "connection-based" way to do this without requiring some trick to push a keepalive every minute to get the desired keys to keep updating. Right now, I'm thinking some form of "healthcheck" is going to be the trick.


1701056730821.png (7.6 KiB)
1701056762074.png (8.0 KiB)
1701056832717.png (15.8 KiB)
1701056869751.png (10.4 KiB)
1701057573865.png (8.2 KiB)
1701058604305.png (86.1 KiB)
1701058650906.png (64.6 KiB)
1701058685805.png (135.4 KiB)
1 comment
2 |3000

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

mvader (Victron Energy) avatar image mvader (Victron Energy) ♦♦ commented ·

Hi, nice write up; few comments (I have to keep it short, sry):


1) don’t use those selective keep alives; we’re dropping support for them. Instead use the generic one. The new MFD HTML5 app also no longer does such selective keepalives.

2) documentation is here: https://github.com/victronenergy/dbus-mqtt

3) Mosquitto is being replaced by FlashMQ: https://github.com/victronenergy/venus/issues/1098

0 Likes 0 ·
kevgermany avatar image
kevgermany answered ·

@flovic @CaptainPalapa

Thanks, really helpful.

Moving this to the modifications space as it belongs there.


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