mqtt connect loss

For general Flowcode discussion that does not belong in the other sections.
mnfisher
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

Re: mqtt connect loss

Post by mnfisher »

Does it try to re-connect and fail - or not try?

d820513
Posts: 56
Joined: Thu Aug 19, 2021 1:14 pm
Has thanked: 2 times
Been thanked: 1 time

Re: mqtt connect loss

Post by d820513 »

he just doesn't answer

mnfisher
Valued Contributor
Posts: 1635
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 142 times
Been thanked: 761 times

Re: mqtt connect loss

Post 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.
mqtt.fcfx
(18.36 KiB) Downloaded 307 times

Martin

BenR
Matrix Staff
Posts: 1952
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 510 times
Been thanked: 698 times

Re: mqtt connect loss

Post 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.

d820513
Posts: 56
Joined: Thu Aug 19, 2021 1:14 pm
Has thanked: 2 times
Been thanked: 1 time

Re: mqtt connect loss

Post 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 ?

BenR
Matrix Staff
Posts: 1952
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 510 times
Been thanked: 698 times

Re: mqtt connect loss

Post 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

Post Reply