AWS IoT Embedded C Device SDK
Auto Reconnect

Any time the SDK detects that the network is disconnected, this feature will attempt to reconnect as part of the next yield call. On top of reconnecting the MQTT connection, all the topics will be re-subscribed. Auto Reconnect feature can be enabled or disabled using the aws_iot_mqtt_autoreconnect_set_status() API. The auto-reconnect feature could be enabled at any point of time after aws_iot_mqtt_connect(). It should not be enabled before aws_iot_mqtt_connect(). You could verify if the auto-reconnect feature is enabled or disabled using the aws_iot_is_autoreconnect_enabled() API.

Exponential back-off is used to decide the time between 2 reconnect attempts. There are 2 configuration parameters associated with exponential back-off, AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL


After all reconnect attempt failure based on the maximum back-off time, #NETWORK_RECONNECT_TIMED_OUT is returned by aws_iot_mqtt_yield(). There will be no more reconnect attempts. If a reconnect is needed after this based on some external conditions then use aws_iot_mqtt_attempt_reconnect() API to reconnect and re-subscribe. This API could be manually used without turning on the auto-reconnect feature. It will attempt to reconnect only once. aws_iot_mqtt_attempt_reconnect() is a blocking call.

In the following cases a network disconnect is detected.

  1. As part of MQTT Keepalive functionality, if we dont get back the Ping Response, then we flag a disconnect and call the iot_disconnect_handler()
  2. If we are not able to send the Ping in the first place then it is flagged as a disconnect.

The iot_disconnect_handler() is invoked even if the auto-reconnect feature is enabled. It is invoked only once before the beginning of the reconnect attempt. Any time a disconnect is detected because of the keep alive logic then this disconnect handler is invoked.

To optimize the auto-reconnect attempt a new API is introduced to check if the Physical Network is up - iot_tls_is_connected(). Every time before performing a TLS handshake the return value of this function will be checked. This could be underlying Cellular connection or Wifi Connection.

Yield return values could be one of these while using the reconnect feature





Known Issues