An Azure software development kit that facilitates building applications that connect to Azure IoT services.
Hello @Hadi Deknache ,
Welcome to Microsoft Q&A .Thank you for reaching out to us.
The observed behavior is caused by network idle timeout mechanisms dropping inactive MQTT/TCP sessions during long telemetry gaps, with the SDK correctly detecting the condition and reconnecting when keep‑alive responses fail. Successful reconnection confirms that authentication and service availability remain intact.
Based on the logs and observed behavior, the intermittent disconnects are most consistent with network‑level idle connection termination combined with MQTT keep‑alive timing behavior.
The key indicators in the logs include:
- Mqtt Ping Response was not encountered
- IOTHUB_CLIENT_CONNECTION_NO_PING_RESPONSE
These messages indicate that the MQTT client sent a PINGREQ but did not receive a PINGRESP within the expected timeframe. When this occurs, the Azure IoT C SDK intentionally considers the connection unhealthy and performs an automatic disconnect followed by a reconnect. This behavior is expected by design and is used to safely recover from silent or half‑open TCP connections.
During the reconnect sequence, the SDK may temporarily report the connection state as UNAUTHENTICATED. This is a transient state while the MQTT session is being re‑established and does not indicate SAS token expiry or authentication failure. Authentication is automatically completed once the connection is recreated. A 24‑hour SAS token lifetime is sufficient and is not contributing to this behavior.
The most likely root cause in this scenario is:
- Network NAT or firewall idle timeout, or short‑lived network interruption combined with
- Long idle period between telemetry messages (10 minutes)
During these idle windows, intermediate network components—such as NAT gateways, firewalls, Wi‑Fi routers, or cellular networks—may silently close inactive TCP sessions. When the next MQTT keep‑alive exchange occurs, the session may already be partially or fully dropped, resulting in the missing PINGRESP and triggering a reconnect.
Please check if the following help -
- Aligning MQTT keep‑alive with network behavior To reduce idle session termination:
- Configure the MQTT keep‑alive interval to a value lower than any network idle timeout
- Typical guideline ranges:
- 30–60 seconds for cellular or unstable networks 60–120 seconds for stable enterprise networks
- Introduce lightweight heartbeat telemetry between the 10‑minute data sends to keep the connection active
- Ensuring proper SDK event loop execution When using the Azure IoT C SDK low‑level API:
- Ensure IoTHubDeviceClient_LL_DoWork() is called frequently - recommended every 100 ms–1 s
- Please avoid blocking operations that delay the event loop
- Delays in this loop can prevent timely MQTT keep‑alive processing and lead to false disconnect detection
- Validating network path behavior Please review the network path for:
- NAT gateway idle session timeouts
- Firewall or proxy TCP timeout policies
- Cellular or Wi‑Fi power‑saving behavior
- Intermittent packet loss affecting MQTT control packets
- Enabling SDK diagnostics logging Consider enabling detailed SDK trace logging to observe:
- MQTT PINGREQ / PINGRESP exchange timing
- Reconnect triggers and reasons
- Transport‑level warnings or delays
- Network‑level packet drops
- Application‑level event loop delaysEnable detailed SDK trace logging to observe:
- MQTT PINGREQ / PINGRESP exchange timing
- Reconnect triggers and reasons
- Transport‑level warnings or delays
- Network‑level packet drops
- Application‑level event loop delays
The following references might be helpful , please check them out
- Monitor and Troubleshoot Azure IoT Hub Device Connectivity | Microsoft Learn
- Manage device reconnections to create resilient applications - Azure IoT | Microsoft Learn
- Use MQTT to communicate with Azure IoT Hub - Azure IoT Hub | Microsoft Learn
- https://github.com/Azure/azure-iot-sdk-c/blob/main/doc/Iothub_sdk_options.md - iot-hub-device-and-module-client-options
Thank you