5

Best way to Fetch connectionState from 1000's of devices. Currently there is not that much devices, but need an efficient solution.

Based on my understanding, currently I can fetch connectionState using

  1. IotHub Queries(select * from devices) or registryManager.GetDevicesAsync(100); -- these methods are not real time when querying for 1000's of devices, or wont be efficient when number of devices increase.
  2. HeartBeat - I don't prefer this as this will overload quota when the number of devices is large which results in sending too many messages.
  3. Operations Monitoring/Diagnostics Monitoring -- First one is good but its getting deprecated by October, 2018 and second one takes about 2 minutes to get message in eventhub(this latency I have tried myself and found out).

Please Suggest some ways and also correct me if I am wrong about any of the above.

Bulat
  • 720
  • 7
  • 15
Renil Joseph
  • 163
  • 3
  • 11
  • Presently, the best way to obtain a device connectionState in the real-time manner is via the Operation Monitoring. This is valid like you mentioned in the 3. by 10/10/2018. After that, there is no a way to obtain a device connectionState close to the real-time (<10 seconds) in the push eventing manner. It will be nice, if this issue will be handled by the Event Grid. – Roman Kiss Apr 17 '18 at 15:43
  • @RomanKiss : Thank you for the answer. I have one more doubt, when a device get connected or disconnected, its get updated in Device Twin. But when i use route to send device twin notifications to EventHub and log it via Azure functions, the 'connectionState' property is missing; ie only desired, reported properties and some other system properties are present. Any way to get connectionState in it ? – Renil Joseph Apr 17 '18 at 17:08
  • It seems only solution back end has access to [twin tags](https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-csharp-csharp-twin-getstarted#create-the-service-app)(like ConnectionState). Still, need `registryManager` to get twin update data. – Rita Han Apr 18 '18 at 08:05

1 Answers1

2

ConnectionState field is only suggested to use during development and debugging not in the product solution.

And there is a limitation of retrieving connectionState because the Maximum number of device identities returned in a single call is 1000.

If your IoT solution needs to know if a device is connected, you should implement the heartbeat pattern.

Since considering the overhead of heartbeat that you concerned, you can set a smaller timeout using this API: DeviceClient.OperationTimeoutInMilliseconds.

This pattern achieves the same result as maintaining a device connection state registry using the heartbeat pattern, while being more efficient.

Rita Han
  • 9,574
  • 1
  • 11
  • 24
  • 2
    Can you show an example of how to implement heartbeat with DeviceClient.OperationTimeoutInMilliseconds? – TacoEater Feb 06 '20 at 15:25