Local MQTT connection times out

Hi, all. I have this weird problem.
I made LED visualization of my cerbo GX data using MQTT messages (battery status, grid status, …).
Everything works OK, but when I go to sleep and wake up in the morning, the MQTT disconnects and is not able to reconnect.
As soon as I start my PC and open the local cerbo GX GUI (I use the new gui), the MQTT restarts and my LED visualizer springs to life without me doing anything.
I looked into the JS for the GUI, it seems it does not connect using MQTT, but using MQTT over websocket.
Any idea what should I do to keep the MQTT alive?

Are you sending a keepalive message?

No :frowning: Any idea how can I do that?

Have a read on the mqtt page on git. Has all the info you are looking for.

Thanks. Turns out it’s just 1 line in arduino pubsub client lib. I’ll test it overnight. Thanks a lot for the hint!

So, even with MQTT keepalive I have the same issue - overnight the connection simply times out.
A soon as I start my PC in the morning and navigate to the local cerbo page, suddenly the LED visualizer starts to do its job.

Further investigation - if I connect using mosquitto_sub to the MQTT on cerbo, I will get only:
Mar 29 14:32:11 N/c061XXXXXXXX/system/0/Serial {“value”:“c061XXXXXXXX”}

Nothing happens there, there is no data.
However, as soon as I open browser and navigate to the gui-v2, the MQTT messages start to flow like crazy.
So it clearly has nothing to do with keep alive.
On top, just wget-ing the cerbo’s page does nothing, I think the “wake up” is sent using websocket MQTT, but I cannot find out what command it is :frowning:

OK, simple reverse engineering did the trick.
I noticed when I log in using mosquitto, I get message like this:
N/c061XXXXXXXX/system/0/Serial {"value":"c061XXXXXXXX"}

I found out that the websocket MQTT actually then responds with something like this:
R/c061XXXXXXXX/keepalive { "keepalive-options" : [ { "full-publish-completed-echo": "6e6a0c0428942bd0" } ] }

Not sure what the number is, but I took the message and changed my arduino code - instead of keep alive, I am now sending this message every 20 seconds.
And voila - even without running the webpage in browser, the visualizer works OK :slight_smile:

I am keeping it here for anyone who needs to do the same trick.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.