IoT Hub C sdk not generating a new SaS Token

Axiom Works 1 Reputation point
2020-11-26T14:13:11.253+00:00

I'm using : NodeMCU programmed through arduino libraries (C SDK)
MQTT Protocol, IoTHub, Device configured as Symmetrical connection
the device is disconnecting after 65 minutes of connectivity but not generating a new SaS token,
then the connecting is remotely closed and the device is not connected anymore

note that: using the official SDKs

Errors:404104 404103

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,143 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
211 questions
{count} votes

1 answer

Sort by: Most helpful
  1. QuantumCache 20,106 Reputation points
    2020-12-01T00:58:36.157+00:00

    Hello @Axiom Works ,

    Symptom 1
    Devices disconnect randomly, and you see 404104 DeviceConnectionClosedRemotely in IoT Hub resource logs.

    Symptom 2:
    Devices disconnect at a regular interval (every 65 minutes, for example) and you see 404104 DeviceConnectionClosedRemotely in IoT Hub resource logs. Sometimes, you also see 401003 IoTHubUnauthorized and a successful device connection event less than a minute later.

    Cause 1
    The SAS token used to connect to IoT Hub expired, which causes IoT Hub to disconnect the device. The connection is re-established when the token is refreshed by the device. For example, the SAS token expires every hour by default for C SDK, which can lead to regular disconnects.
    Cause 2
    The device lost underlying network connectivity longer than the MQTT keep-alive,
    The device sent a TCP/IP-level reset but didn't send an application-level MQTT DISCONNECT.
    The device side application crashed.

    Cause 3
    IoT Hub might be experiencing a transient issue.

    Solution 1
    See 401003 IoTHubUnauthorized solution 1

    Solution 2
    Make sure the device has good connectivity to IoT Hub by testing the connection. If the network is unreliable or intermittent, we don't recommend increasing the keep-alive value because it could result in detection (via Azure Monitor alerts, for example) taking longer.

    Use the latest versions of the IoT SDKs.

    Solution 3
    See solutions to IoT Hub internal server errors.

    For more information, please refer to this documentation 404104 DeviceConnectionClosedRemotely.

    Please comment below to get more help on your query.

    1 person found this answer helpful.