An Azure software development kit that facilitates building applications that connect to Azure IoT services.
Hello @Hadi Deknache ,
Thank you for your patience while we were working on this.
The observed behavior, where intermittent disconnects occur with IOTHUB_CLIENT_CONNECTION_NO_PING_RESPONSE, is consistent with an MQTT keep‑alive response not being received in time. In such cases, the SDK correctly identifies the connection as unhealthy and performs an automatic reconnect. This recovery mechanism is expected; however, the frequency of reconnects can be reduced with proper alignment of configuration and environment.
Based on the understanding shared, the interpretation regarding DoWork() is largely correct with the following clarification.
The usage of DoWork() depends on the API layer:
Low-level (LL) API (IoTHubDeviceClient_LL_*)
-
IoTHubDeviceClient_LL_DoWork()must be explicitly called by the application - It is responsible for:
- MQTT keep‑alive processing (PINGREQ/PINGRESP)
- Message send/receive
- Reconnection handling
- Message send/receive
- MQTT keep‑alive processing (PINGREQ/PINGRESP)
- If not executed frequently, keep‑alive timing may be impacted
- Non-LL (convenience) API (
IoTHubDeviceClient_*) - A background worker thread is managed internally
- No manual
DoWork()call is required
- No manual
Thus
-
DoWork()is only required in LL API - It is not invoked automatically in LL API
- It is handled internally in non-LL API
The variation across devices indicates environmental differences rather than a single application defect. Contributing factors can include:
- Network idle timeout differences (NAT/firewall behavior)
- Cellular versus Wi‑Fi stability
- Packet loss or latency affecting MQTT control packets
- Device-side scheduling delays impacting
DoWork()(LL API) - Power-saving or network interface sleep behavior
Additionally, telemetry intervals (10 minutes) and heartbeat intervals (2 hours) create extended idle periods where intermediate network components may silently close TCP sessions. This increases the likelihood of missed keep‑alive responses.
Please check if the following help to stabilize the connection and reduce reconnect frequency:
- Verifying SDK execution model
- Confirm whether LL or non-LL API is used
- If LL API is used, ensure continuous execution
- Tuning MQTT keep‑alive
- Default keep‑alive for C SDK is configurable (~240 seconds)
- Recommended adjustment:
- Use 60–120 seconds
- Ensure value is lower than expected network idle timeout
- Enabling diagnostic logging Helps identify root cause patterns:
- PINGREQ not sent - application/event loop delay
- PINGREQ sent but no PINGRESP - network-related issue
- Validating network path Review:
- NAT/firewall idle timeout policies
- Cellular/Wi‑Fi stability differences
- Packet loss affecting MQTT control messages
- Reducing quota consumption during reconnects Frequent reconnects can increase:
- Message usage
- Twin reads and updates
- Resynchronization traffic
- Cache device state locally
- Use twin versioning to send only incremental updates
- Avoid full state resync after each reconnect
In summary ,
The reconnect behavior itself is expected, but the trigger (missed keep‑alive response) is influenced by a combination of network characteristics, idle intervals, and if using LL API event loop execution frequency. With proper tuning of keep‑alive settings, validation of DoWork() execution, and awareness of network conditions, the reconnect frequency and quota impact can typically be significantly reduced.
Thank you