Determining Accurate Device Connection Status in IoT Hub

85141552 0 Reputation points
2023-10-13T12:38:50.2866667+00:00

Microsoft Team,
We are currently working on a setup to monitor the IoT Hub device status, specifically focusing on assessing the "DeviceConnect" status as recommended by Microsoft. This metric is vital for tracking device uptime and plays a significant role in our Gateway. we are currently monitoring "DeviceDisconnect" and "DeviceConnect" status from IoT hub logs to alert us on the offline devices for more than 1 hour. **

Problem**: However, we've encountered an issue. Despite reports from the Customer Support team indicating that certain devices are offline at our customer's site, these devices continue to show as online in IoT Hub.

We're seeking help from the community to identify the accurate indicator in the logs/metrics from IoTHub that can reliably inform us whether a device is offline or online. We've attached a screenshot for reference.Screenshot 2023-10-11 at 10.21.52

Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
385 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,136 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde 29,616 Reputation points MVP
    2023-10-13T13:30:57.03+00:00

    Hello @85141552,

    welcome to this moderated Azure community forum.

    The most reliable way to monitor devices connecting and disconnecting is to make use of the EventGrid events or via IoT Hub routes (routing device lifecycle events).

    Please compare these two ways to log events for the best response.

    More background information regarding implementing reconnected in the client is documented here.

    As an alternative, if you program the device connectivity yourself, you could write custom code to detect disconnections on the client:

    deviceClient.SetConnectionStatusChangesHandler(ConnectionStatusChangeHandler);
    
    private static void ConnectionStatusChangeHandler(ConnectionStatus status, ConnectionStatusChangeReason reason)  
    {
        Console.WriteLine($"Connection Status Changed to {status} ({reason}) at {DateTime.Now}");
    }
    

    This way, you can measure the connectivity both in the cloud and on devices.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    0 comments No comments