ESP8266 Developer Zone The Official ESP8266 Forum 2019-02-17T05:41:27+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=25998 2019-02-17T05:41:27+08:00 2019-02-17T05:41:27+08:00 https://bbs.espressif.com:443/viewtopic.php?t=25998&p=37683#p37683 <![CDATA[Re: MQTT reconnect fails]]>
The issue came from the fact that I was not doing network.disconnect(&network) after an issue occurred and before I was trying to reconnect to the MQTT client. In the ESP_SDK v2.x.x, they don't show this, but in the version v3.1 they show it properly.

Statistics: Posted by Guest — Sun Feb 17, 2019 5:41 am


]]>
2019-02-10T10:55:38+08:00 2019-02-10T10:55:38+08:00 https://bbs.espressif.com:443/viewtopic.php?t=25998&p=37445#p37445 <![CDATA[MQTT reconnect fails]]>
I am using the ESP8266_RTOS_SDK_2.x.x version and I connect to my cloud (Google Cloud) using MQTT secured protocol. The flow of functions I call is chronological as follow:
1) NetworkInitSSL()
2) MQTTClientInit()
3) NetworkConnectSSL()
4) MQTTConnectWithResults()
5) MQTTSubscribe()
6) MQTTPublish()
Everything works just fine, and I can see that my messages are published to the cloud with no issue.

My problem happens if, for example, I publish a message that doesn't make it through (could happen for various reasons). Then MQTTPublish() returns an error code and the function closes the session by calling

Code:

MQTTCloseSession(c)
. This is where my problems begin because I want to be able to restart a connection in the event this happens. But so far I have been unable to do this successfully. I tried to reconnect by calling

Code:

MQTTDisconnect(&client)
after MQTTPublish() returns the error, and going through all the steps described above when first connecting but it doesn't work. It actually works once, but then doesn't work a second time. It fails at NetworkConnectSSL() and says it couldn't connect...

Any thoughts on what I could be doing wrong here? I would really appreciate some help.

Thanks!

Statistics: Posted by Guest — Sun Feb 10, 2019 10:55 am


]]>