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:
Note, that there are some limitations for device connection state/events, see more details here.
Thanks
Roman