mqtt connect loss
-
- Valued Contributor
- Posts: 1635
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 142 times
- Been thanked: 761 times
-
- Valued Contributor
- Posts: 1635
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 142 times
- Been thanked: 761 times
Re: mqtt connect loss
Hi,
Sorry - I've no experience of MQTT. I tried connecting to a test broker (https://www.emqx.com/en/mqtt/public-mqtt5-broker) using an esp32 and connection seems to work and is stable. However - I've no idea what needs to be written /read to get data into/out of the broker? (I'll have to take a peek at the docs
)
What I also did was also add an UART component to allow some debug messages to be displayed on my PC (I'm using 'putty') - although there is no data received the connection remains solid - so I've not seen an error/reconnect occur.
Martin
Sorry - I've no experience of MQTT. I tried connecting to a test broker (https://www.emqx.com/en/mqtt/public-mqtt5-broker) using an esp32 and connection seems to work and is stable. However - I've no idea what needs to be written /read to get data into/out of the broker? (I'll have to take a peek at the docs

What I also did was also add an UART component to allow some debug messages to be displayed on my PC (I'm using 'putty') - although there is no data received the connection remains solid - so I've not seen an error/reconnect occur.
Martin
-
- Matrix Staff
- Posts: 1952
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 510 times
- Been thanked: 698 times
Re: mqtt connect loss
Hello,
The MQTT has a timeout period defined by the server, usually something like a minute.
To keep the connection alive you need to send out the ping within this timeout period. If you can don't send this constantly but try and send it say once every 10 or 20 seconds and that should resolve the problem.
You can do this by having an incrementing counter based on number of times around your main loop or as part of a timer interrupt. Once the count reaches a certain value reset the count to 0 and send the ping.
The MQTT has a timeout period defined by the server, usually something like a minute.
To keep the connection alive you need to send out the ping within this timeout period. If you can don't send this constantly but try and send it say once every 10 or 20 seconds and that should resolve the problem.
You can do this by having an incrementing counter based on number of times around your main loop or as part of a timer interrupt. Once the count reaches a certain value reset the count to 0 and send the ping.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Matrix Staff
- Posts: 1952
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 510 times
- Been thanked: 698 times
Re: mqtt connect loss
Great glad that's fixed it.
Have you seen this video we made on MQTT it may help.
viewtopic.php?f=9&t=319&p=1668
Have you seen this video we made on MQTT it may help.
viewtopic.php?f=9&t=319&p=1668
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel