Azure IoT central Device connection status read from REST API

Mohammad, Khaja Moinuddin 41 Reputation points
2022-03-25T14:03:43.407+00:00

Hi team,

I am trying to read the DEVICE CONNECTION STATUS through REST API to implement a PLC switching condition and also to show the device status on my webpage. I have searched almost all the REST APIs which can support IoT Central. But sadly, I didn't find any of it. Can you please tell me there is a REST API that I missed?

When I tried to get it from the Azure CLI, then I am able to generate the Device Status. But how can I implement it on my code to read status? I tried using Powershell in Azure Functions for enabling "az login" and "az iot central show device twin" commands, but it doesn't work at all. There is no proper documentation of adding Azure CLI in Azure Functions - Powershell.

Can you please help me with reading the Connection Status of each and every device to automate my system? It's really important and urgent for me.

Azure IoT Central
Azure IoT Central
An Azure hosted internet of things (IoT) application platform.
352 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,128 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
208 questions
{count} votes

Accepted answer
  1. Roman Kiss 2,246 Reputation points
    2022-03-26T14:36:26.897+00:00

    Hi,

    based on the az iot central show device twin you can use an undocumented REST GET request to obtain a device twin with an extended info, where is a connectionState property, such as:

    https://<appId>.azureiotcentral.com/system/iothub/devices/<deviceId>/get-twin?api-version=1.1-preview&extendedInfo=true

    for Authorization header use the <apiToken>

    Another way how to obtain a device connection state is to use an eventing, where the Device connectivity events are exported to the Azure Event Grid in the PUSH manner.

    The following code snippet shows an example of the events transformation query in the Data Export:

    {  
      specversion:"1.0",  
      id:.applicationId,  
      source: .device.id,  
      subject:.messageSource,  
      type:.messageType,  
      time:.enqueuedTime,  
      dataschema:"#"  
    }  
    

    For destination is used a Webhook to forward the cloudevent message to the custom topic of the Azure Event Grid:

    187145-image.png

    Note, that there are some limitations for device connection state/events, see more details here.

    Thanks
    Roman

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful