0

Once I got a devices connected to my hub, I would like to listen its own status changes and catch them.

Moreover the classic pattern (creating an async task, given the previous device obtained through query, repeat and see if the status has been changed then get the event's datetime) is there any kind of built-in method which could help me?

Istorn
  • 485
  • 1
  • 5
  • 23
  • Can you be more specific for a device status? Is this a non-telemetry data? – Roman Kiss Jul 10 '19 at 11:33
  • I'm referring about the "Status" device' attribute itself: I would like to catch through C# function when it'll change – Istorn Jul 10 '19 at 11:36
  • what do you mean with "Status" attribute? – silent Jul 10 '19 at 11:39
  • OK, that's my assuming (non-telemetry data), when I made my answer about using a device twins properties and their eventing. – Roman Kiss Jul 10 '19 at 11:40
  • @silent https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.device?view=azure-dotnet – Istorn Jul 10 '19 at 11:41
  • that Status is actually only on the service-side of the IoT Hub. You can set this attribute (only) from the service-side (=Cloud) which controls whether a device can connect to IoT Hub in the first place – silent Jul 10 '19 at 11:42
  • @silent I don't wanna to update it! I want to listen its own changes! – Istorn Jul 10 '19 at 11:44
  • The status does not update at all unless some other service client changes it. This Status field has nothing to do with the status of the device (if it's connected, sending data, etc.) https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-endpoints – silent Jul 10 '19 at 11:45
  • Independently by the service that changes it or if it has or not nothing to do with the status of the device I've to catch its changes. That's all. – Istorn Jul 10 '19 at 11:46

2 Answers2

1

The integration of IoT Hub with Azure Event Grid sounds exactly like what you are looking for: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-event-grid

enter image description here

There is also a sample/tutorial using Logic Apps: https://learn.microsoft.com/en-us/azure/event-grid/publish-iot-hub-events-to-logic-apps

silent
  • 14,494
  • 4
  • 46
  • 86
  • Nice, but I need to build it with a C#/.NET solutions. By the way, the event I'm trying to catch isn't available in the list... – Istorn Jul 10 '19 at 11:37
  • the Logic App is only one way to react to event grid events. There are also .NET SDKs. – silent Jul 10 '19 at 11:40
1

The following docs can help you for your eventing:

The above documents described how to capture and route the device twin change events to the EventHubTrigger function.

Roman Kiss
  • 7,925
  • 1
  • 8
  • 21
  • Afraid but not: the "non-telemetry events" guide will redirect to your third link with no fully functional solution... – Istorn Jul 10 '19 at 12:10
  • the device twins represents a device state in the distributed and disconnected IoT model. The real device state has a "twin" on the cloud (server) side. Any changes made at the ends (device side or cloud side) are captured by IoT Hub and the notification message is distributed to the outgoing endpoint based on the custom rules. The notification message can triggered an Azure function to handle the business requirements. Note, that this events can be also analyzed in the stream pipeline using an Azure Stream Analytics job. – Roman Kiss Jul 10 '19 at 12:48
  • Everything you said is available only with the Azure cloud client but not available with "from scratch" C# solutions. – Istorn Jul 10 '19 at 12:49
  • Btw. what is your device protocol to Azure IoT Hub? – Roman Kiss Jul 10 '19 at 12:51
  • I don't know because I'm working at this side of the project. – Istorn Jul 10 '19 at 12:52
  • OK, the Azure IoT Hub supports only the following protocols, connection-less: **https**, connection-oriented: **MQTT** and **AMQP**. The device twin can be used only for connection-oriented protocols. So, for generic solution, your telemetry stream pipeline should also contained the device state and analyzed by Azure Stream Analytics job for generating a change notification event to the Azure HttpTrigger function for a business logic. – Roman Kiss Jul 10 '19 at 13:06
  • Ok well, my question right now is: why Microsoft didn't provide built-in methods to deploy everything you said? There's no documentation about query system (intended as table and their own attributes), methods to create notification system with concrete examples and esaustive solutions. – Istorn Jul 10 '19 at 13:29