IoT Central Device Connection Status and Image with REST API

Anonymous
2022-07-06T08:12:22.92+00:00

I created a Static Web React App that connects to an IoT Central App with the REST API and lists the devices.
I want to display the connection status like it is already shown in the IoT Central, but I can't find an option where I can get the connection status for all devices.
The same goes for trying to get the image assigned to the device.

218087-image.png 218073-image.png

What options do I have to get the connection status and images for all devices or on a per-device basis?

Any kind of insight or help would be greatly appreciated.
Thank you in advance!

Azure IoT Central
Azure IoT Central
An Azure hosted internet of things (IoT) application platform.
376 questions
0 comments No comments
{count} votes

Accepted answer
  1. Roman Kiss 2,246 Reputation points
    2022-07-06T09:59:54.277+00:00

    There is no REST API for getting a connection status of the device(s) in the IoT Central App. However, you can use the Device connectivity events in the Data export feature with a webhook destination to the Azure Event Grid custom topic as a CloudEvents message.

    The following is an example of the exported CloudEvents message:

    Data transformation:

    if .messageSource == "deviceConnectivity" then  
    {  
      specversion:"1.0",  
      id:.applicationId,  
      source: .device.id,  
      subject: ("/" + .applicationId + "/" + .device.id + "/" + .messageSource),  
      type:.messageType,  
      time:.enqueuedTime,  
      dataschema:"#",  
       data:{    
        reportedProperties: .device.properties.reported,  
        cloudProperties: .device.cloudProperties  
      }  
    }  
    else  
      empty  
    end  
    

    CloudEvents message:

    {  
      "data":{  
        "cloudProperties":[],  
        "reportedProperties":[]  
      },  
      "dataschema":"#",  
      "id":"2922a1f6-7214-490a-88bc-a1e1d4351d12",  
      "source":"device101",  
      "specversion":"1.0",  
      "subject":"/2922a1f6-7214-490a-88bc-a1e1d4351d12/device101/deviceConnectivity",  
      "time":"2022-07-06T10:27:05.829Z",  
      "type":"disconnected"  
    }  
    

    Note, that the webhook destination header Content-Type must be configured for application/cloudevents+json

    UPDATE:

    I have found an undocumented REST API to get the device twin with an extended info such as the connectionState, status, modelId, etc.

      https://<applicationId>.azureiotcentral.com/system/iothub/devices/<deviceId>/get-twin?extendedInfo=true  
      Authorization: <apiToken>  
    

    Thanks
    Roman

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.