Reputation: 499
Is there any way which we can automatically sync data between device MQTT events and Device Twin data ?
For a given device in Azure IOT hub there is a mqtt event endpoint and a device twin endpoint associated to it.
I have tried sending MQTT event data to a particular device through device's event MQTT endpoint : devices//messages/events/ and it was successful. I was able to see the incoming data in the device explorer.
The Problem that I have is that, when we send some data to device through device's event mqtt endpoint, those data will not be automatically sync into the respective device's twin. I think it should happen automatically. In azure we have to manually (programmatically) do a twin data push for each event data that we receive through device's event endpoint.
This can be done through pushing mqtt data to device twin endpoint : $iothub/twin/PATCH/properties/reported/?$rid=ID
Is there anyway that we can do it automatically ? - Means automatically synchronize data from event mqtt stream to Device Twin ?
Upvotes: 0
Views: 412
Reputation: 8235
The primary focus of the Azure IoT Hub is to ingest a device telemetry data into the Azure IoT Stream Pipeline in the real time.
Beside that, each device has a capability to save its state in the Azure storage known as a device-twin such as a json formatted document. The device twin has built-in a support for sync the states between the device and backend cloud in the modern event driven distributed architecture.
The differences between the above two communications such as device-to-cloud and device twin is described in the Reference - IoT Hub quotas and throttling.
Based on this document, you can see, that the device twin is used for non-frequently persistence of the device state, for example: device firmware version, some device configurations, threshold for alert, etc.
In other word, the device twin is not designed for storing a real-time device telemetry data in the cloud backend. In the Internet of things all telemetry data (things) from the devices go to the stream pipeline for their real-time analyzing, etc.
However, the Azure IoT Hub has a capability to help you with your scenario, when a device telemetry data and its device twin changes can be stored in the Azure Blob Storage in the real time, see this feature here. You can use an Azure Function and/or Stream Job for analyzing, query, etc. this blob for your business logic.
Upvotes: 1