Additional device states (say error states), which is the right place device twin or telemetry?

Aurovind Sagar Epari 80 Reputation points
2023-08-09T07:56:01.9566667+00:00

Hello Team,

We are setting up IoT solution for our new device. The device is a complex device, hence there would be various states and error-states. I am trying to figure out which is the right place to update the states - device twin or telemetry?

As of now we can think of the following requirements,

  • We are going to use a stream analytics. So might be a good idea to keep it in telemetry so that stream analytics can parse the live data to get various states (while its connected)?
  • So my next question is - When its disconnected, how can stream analytics be updated about it?
  • We can store the additional states in device twin as properties? And the user (say apps) can be notified on device twin change. So my next questions on this are,
    • Is it the right idea to update the states via device twin?
      • Is it the right idea to let Apps/ users notified through an additional subscription topic? via event-grid & function through the IoTHub service SDK. Or any better solution is there.
        • And for stream analytics (to notify it to PowerBI), how can it access the states from device twin?
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 Stream Analytics
Azure Stream Analytics
An Azure real-time analytics service designed for mission-critical workloads.
333 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sander van de Velde 29,281 Reputation points MVP
    2023-08-09T08:53:55.51+00:00

    Hello @Aurovind Sagar Epari ,

    welcome to this moderated community forum.

    There are several options for distributing your state.

    You can send the state with every telemetry message. This is by far the easiest solution but it also means more data communication because the state will not change that much so you keep sending the same state over and over again.

    Another solution is writing the state in the reported properties of the device twin. This means you probably only update it when the state changes. There is this possibility to create non-telemetry device twin change message streams. So these messages can be picked up as a stream also. The state is available for other services too to read it (pull) from the device twin.

    The third solution is message enrichment. You update the reported properties in the device twin. Each incoming telemetry message (without state) is enriched by the IoT Hub. There could be a small delay between writing the reported properties and the enrichment enriching the new state.

    Now you have one or two streams that can be picked up by Stream Analytics. From there you can attach PowerBI directly because it comes with internal PowerBI storage (for a limited time) or you put some database in between (output messages to tables in Sql Azure or Azure Data Explorer) and attach PowerBI to one of these databases.

    Stream Analytics just works on incoming messages. If there are no messages (the device is disconnected), there will be no output.

    An easy way to listen to the device connection/disconnection messages on the IoT Hub and route them as an extra stream to stream analytics/power bi.

    Or write a time-triggered Azure Function which checks the connectivity of your devices.

    Check out the different IoT HUb routing options here.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful