MQTT reconnect fails

Posts: 5
Joined: Wed Jan 23, 2019 8:41 am

MQTT reconnect fails

Postby fmuller-pi » Sun Feb 10, 2019 10:55 am


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: Select all

. 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: Select all

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.


Who is online

Users browsing this forum: Google [Bot] and 10 guests