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:
MQTT_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:
rst cause:4, boot mode:(3,7)
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!