esp-aws-iot
esp-aws-iot copied to clipboard
How to keep MQTT connection always alive to receive subscribe topics messages? (CA-225)
Hello,
With the example provided in thing_shadow, it will disconnect after the full demo routine is complete. However, even if we remove the line returnStatus = DisconnectMqttSession(); it will still disconnect after keep alive timeout.
This is the log from AWS IoT:
{
"clientId": "esp32",
"timestamp": xx,
"eventType": "disconnected",
"clientInitiatedDisconnect": false,
"sessionIdentifier": "xx",
"principalIdentifier": "xx",
"disconnectReason": "MQTT_KEEP_ALIVE_TIMEOUT",
"versionNumber": 4
}
How can we keep ESP32 continue to receive messages of the topics that have subscribed in the do while loop?
Thank you
I believe you're not passing through MQTT_ProcessLoop on a regular basis. The MQTT_ProcessLoop function will ping the server and keep the connection alive on its own. MQTT_ProcessLoop is also responsible for allowing the event handlers to fire when a message arrives.