Page 2 of 2
Re: mqtt connect loss
Posted: Sun Feb 05, 2023 7:40 pm
by mnfisher
Does it try to re-connect and fail - or not try?
Re: mqtt connect loss
Posted: Mon Feb 06, 2023 10:41 am
by d820513
he just doesn't answer
Re: mqtt connect loss
Posted: Mon Feb 06, 2023 10:28 pm
by mnfisher
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
Re: mqtt connect loss
Posted: Tue Feb 07, 2023 10:25 am
by BenR
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.
Re: mqtt connect loss
Posted: Tue Feb 07, 2023 8:54 pm
by d820513
Hi, so far it seems to work guys, thanks !
who knows which mqtt macro I can see the number, for example, I sent the number 32 to the INTOP1 topic, which macro can I see ?
Re: mqtt connect loss
Posted: Wed Feb 08, 2023 10:45 am
by BenR
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