Azure IOT Hub , Device Twin vs Device to Cloud messages , can both be used together? - azure

We have use case where Device Twin to be used for executing commands (by changing desired properties). Also , there is telemetry data flow and we are planning to use device to cloud message. The question stands
Can both (twin and messaging) be used , if so how to manage updating reported properties of device twin ? Understand updating it for every device to cloud message will affect performance
If device twin alone can be used for managing telemetry message and commands. What will be the performance consideration for reading device twin reported properties on right side of Iot Hub
The frequnecy of telemetry messages will be every hour and total device will be around 50k
We tried device to cloud and cloud to device messages , but as per customer needs Device Twin for futuristic Devices which can directly read and update Device Twin

Related

Azure Digital Twins <---> The Things Network (2 way communication)

I am working on a project that requires two-way communication between Azure Digital twins and the Things Network. Right now I am able to connect my AZDT to the TTN via an IoT HUB to update the twin with "read variables" for example I have a CO2 sensor that sends data via the IoT HUB instance to the AZDT.
However I am not sure how to do the communication the other way around, when I send a signal to a "write" variable, and this message is carried over to the device, for example I have a smart plug that can be turned off via the AZDT.
anyone could give me some ideas? or support on that?
thanks
did you check out the TTI IoT Hub integration documentation page?
There is a section that explains Desired Properties for updating values between The Things Stack and IoT Hub
https://www.thethingsindustries.com/docs/integrations/cloud-integrations/azure-iot-hub/device-twin/#desired-properties
To generate a downlink you need to update the shadow of the device and save it, which will schedule a downlink for the device on The Things Stack.
To trigger this from the twin itself, you need to update the Digital Twin state that contains the property of the device in question
I would take a look at additional docs from MSFT on this
e.g.,
Updating device twin in IoT Hub: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-device-twins
Updating Digital Twin: https://learn.microsoft.com/en-us/azure/digital-twins/how-to-manage-twin#update-a-digital-twin
Hope this helps

Azure function missing IoT hub trigger messages

I have created an Azure function to route messages from an IoT hub to an Azure SQL DB using the IoTHubTrigger following mostly the instructions in this link Azure Functions - how to set up IoTHubTrigger for my IoTHub messages?.
Each IoT device captures data every 8 minutes. When capturing is done, the device streams the data in 4 different messages. Then the azure function takes over to write these 4 different messages to the database.
When only one device was streaming, I had no issues with the data, which where written in the db and I could also see/monitor events/messages using az iot hub monitor-events.
When a second device started streaming in the same IoT hub, I started missing messages, meaning that from each device only one message is being stored in the db. Also when using iot hub monitor-events only one message appears from each device. I was also expecting that if I disable the 2nd device, then the 1st one will go back to normal. Unfortynately the issue remains the same.
So my question is: how is it possible a 2nd device screwing up the way that the 1st one interacts with the hub?
If that's not the case, then how we are supposed to figure out what causes the problem at this stage?
Thanks :)
Difficult to say without more details. Are you routing messages in IoT Hub somewhere else? I would go back to a clean IoT Hub with one device and create a consumer group on the IoT Hub for the function. Before running the function I would monitor that consumer group (I like to use the Azure IoT Explorer application) to see if data is coming through as expected, then add another device and keep monitoring the same consumer group. If data is coming through then start the function (consuming data from the consumer group).
If telemetry was not getting read from the IoT Hub consumer group then you will need to look at your device code for any issues.

Can Azure IOT hub be used to read(Get) data from some devices?

In my case I have 1000+ of devices that stores activity inside. I need to send a http get request to this device to get those data in csv or json format and save it in a storage hosted on azure.
Cab IOT hub require data using get request and can it be scheduled to read daily/weekly?
What other azure services would you suggest to facilitated this scheduled reads?
You have not mentioned which the Azure IoT Hub scale tier is used. Basically there are two price groups such as Basic and Standard with a significant different cost and capabilities. The Basic tier offers only services for one-way communications between the devices and Azure IoT Hub.
Based on that, the following scenarios can be used for your business case:
1. Basic Tier (non event-driven solution)
The device pushs periodicaly a telementry and non-telemetry messages based on the needs to the Azure IoT Hub, where the non-telemetry messages are routed to the Azure Function via the Service Bus Queue/Topic. Responsibility for this non-telemetry pipe is to persist a real device state in the database. Note, that the 6M messages will cost only $50/month. The back-end application can any time to query this database for devices state.
2. Standard Tier (event-driven solution) In this scenario you can use a Device Twin of the Azure IoT Hub to enable storing a real-device state in the cloud-backend (described by #HelenLo). The device can be triggered by C2D message, changing a desired property, invoking a method or based on the device edge trigger to the action for updating a state (reported properties).
The Azure IoT Hub has a capabilities to run your scheduled jobs for multiple devices.
In this solution, the back-end application can call any time a job for ExportDevicesAsync to the blob storage, see more details here. Note, that the 6M messages will cost $250/month.
As you can see the above each scenario needs to build a different device logic model based on the communications capabilities between the devices and Azure IoT Hub and back. Note, there are some limitations for these communications, see more details here.
You can consider using Device Twin of IoT Hub
https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-device-twins
Use device twins to:
Store device-specific metadata in the cloud. For example, the deployment location of a vending machine.
Report current state information such as available capabilities and conditions from your device app. For example, a device is connected to your IoT hub over cellular or WiFi.
Synchronize the state of long-running workflows between device app and back-end app. For example, when the solution back end specifies the new firmware version to install, and the device app reports the various stages of the update process.
Query your device metadata, configuration, or state.
IoT Hub provides you with the ability to connect your devices over various protocols. Preferred protocols are messaging protocols, such as MQTT or AMQP, but HTTPS is also supported. Using IoT hub, you do not request data from the device, though. The device will send the data to the IoT Hub. You have to options to implement that with IoT Hub:
The device connects to the IoT Hub whenever it has some data to be sent, and pushes the data up to IoT Hub
The device does not send any data on its own, but stays always or at least regularly connected to IoT Hub. You then can send a cloud to device message over IoT Hub to the device, requesting the data to be sent. The device then sends the data the same way it would in the first option.
When the data then has been sent to IoT Hub, you need to push it somewhere where it is persistently stored - IoT Hub only keeps messages for 1 day by default. Options for this are:
Create a blob storage account and push to that directly from IoT Hub using a custom endpoint This would probably be the easiest and cheapest. Dependening on how you need to access your data, a blob might not be the best option, though
Create a function app, create a function with an EventHubTrigger, connect it to IoT Hub and let the function process incoming data by outputting it into any kind of data sink, such as SQL, CosmosDB, Table Storage...

Synchronize Data From Event MQTT Endpoint to Device Twin In Azure

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 ?
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.

How does device anti-spoofing work in Azure IoT hub?

From Azure development guide https://azure.microsoft.com/en-us/documentation/articles/iot-hub-devguide, there is a small section (shown as below) talking about device anti-spoofing. It is not clear for me, it says IoT hub stamps every message with properties, but for me device anti-spoofing is that IoT hub to stop receiving messages sent from any spoofed device. Please help to explain how does this work?
Anti-spoofing properties
To avoid device spoofing in device-to-cloud messages, IoT Hub stamps
all messages with the following properties:
ConnectionDeviceId
ConnectionDeviceGenerationId
ConnectionAuthMethod
In IoT Hub there is a device registry that is used to authorize devices to the gateway. After authentication the device is checked against the registry.
When a device is registered with IoT Hub, the device's identity and key are saved in the device registry. This device and key is what the device uses to authenticate to the service.
The generation ID is a key part of this too. When the device is first registered with IoT Hub, a generation ID is assigned to the device. The purpose of this is to distinguish between identity registrations of the same device ID (added, removed, and then later added).
If you're interested in a deeper dive into the IoT Hub architecture see Clemen's 2015 Build talk here.

Resources