The use of the ESP8266 in the world of IoT

User avatar
By maverickchongo
#83479 Hi,

I am using https://github.com/tuanpmt/esp_mqtt mqtt client

I am facing few issues when my mqtt client loses connectivity to broker or I need to disconnect/reconnect it, for instance,

short interruption of WIFI (ESP disconnects from WIFI AP):

In this case I don't get the MQTT_OnDisconnected callback neither the client reconnects after WIFI connection is re-established (I have changed the keep alive and reconnect timouts but still no luck). As I need the mqtt client to be up as soon as possible, what I do is to force a disconnection, delete client and try to connect again:

Code: Select allMQTT_Disconnect(&mqttClient);
MQTT_DeleteClient(&mqttClient);

MQTT_InitConnection(&mqttClient, pchost, MQTT_PORT, TWO_WAY_ANTHENTICATION);
MQTT_InitLWT(&mqttClient, vcStatusTopic, MQTT_OFFLINE, 0, 1);
MQTT_OnConnected(&mqttClient, _mqttConnectedCb);
MQTT_OnDisconnected(&mqttClient, _mqttDisconnectedCb);
MQTT_OnPublished(&mqttClient, _mqttPublishedCb);
MQTT_OnData(&mqttClient, _mqttDataCb);
MQTT_OnTimeout(&mqttClient, _mqttTimeoutCb);

MQTT_Connect(&mqttClient);


Is this the right approach?

The problem I am facing is that when the cliend tries to reconnects and is doing the ssl handshake, it crashes:

Code: Select allrst cause:4, boot mode:(3,7)
Which I believe is watchdog reset, it seems it gets stuck somewhere while doing the handshake...

Something similar ocurs when the broker reboots or disconnects from network for few seconds minutes or when I need to disconnect the client to connect it to another broker...

Any ideas what might be happening?
Any help is much appreciated!
User avatar
By davydnorris
#83481 That's the approach I have taken too, and it seems to work pretty well.

In terms of the SSL crashes, make sure you completely clean up and delete the tcp connection and rebuild it from scratch, otherwise you may be holding onto memory for the SSL buffers and then you run out. Also it's worth tuning your SSL buffer size on a connection by connection basis - I have found that different sites will use different amounts of buffer depending on the cipher selected.
User avatar
By maverickchongo
#83509
davydnorris wrote:That's the approach I have taken too, and it seems to work pretty well.

In terms of the SSL crashes, make sure you completely clean up and delete the tcp connection and rebuild it from scratch, otherwise you may be holding onto memory for the SSL buffers and then you run out. Also it's worth tuning your SSL buffer size on a connection by connection basis - I have found that different sites will use different amounts of buffer depending on the cipher selected.


Thanks, I'll keep trying.