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
Related
With the help of Azure IoT SDK node, I've been assigned to send telemetry data from device to IoT hub using NodeJS.
How do I write or how do I find an appropriate sample for d2c messages.
I'm quite confused which sample code to be used from this particular SDK for device to IoT hub telemetry.
https://github.com/Azure/azure-iot-sdk-node
"Suppose my device has a waste level sensor and sending waste fill level to IoT hub so how do I get an appropriate sample from this SDK to send data to Hub"
Thank you.
the easiest Node SDK sample I could find was this one". It's in the repository that you linked to.
If you want more information, and a step-by-step tutorial, I can recommend this tutorial in the docs. It uses a different sample in the same repository.
For all of these samples: they send a certain payload. You can change the payload to whatever you need it to be for your waste level sensor!
There is some confusion between two aspects of Azure IoT-Hub. I see here that Azure Digital Twins (with DTDL) simplify device state management (reported, desired properties) when compared to Azure IoT-Hub Device Twins. However, I see here that they appear to be separate but linkable entities.
So the question: Can Azure Digital Twins (and DTDL) be seen/used as REPLACEMENTS for Azure IoT-Hub Device Twins. How? If not, why not, since having two separate Twins appears overly complex?
Note that we use the IoT-Edge and leverage its offline features of reported and desired properties in the Iot-Hub Device Twins.
Thanks!
Short answer: No
Longer and arguably more friendly answer: To leverage the Device Twins in IoT Hub, you need Device Twins in IoT Hub, but you can link it to your Digital Twin in Azure Digital Twins (ADT). If you want to include your Device Twin properties in ADT, you need to route your Device Twin messages to a Function that will make the translation to ADT. In this subsection of the docs, you can see the differences in notation.
If you want to let ADT 'drive' your Device Twin, you need to subscribe to ADT change notifications, consume them in another Function and apply the changes in the Device Twin in IoT Hub. This is currently all custom work, you can base some of the work on the link you provided in your question.
With regards to your question about complexity: it might seem a little complex to set up ADT as your single source of configuration, but when it's done, you have your config in one place. In practice, I'm not seeing this happen a lot.
Important to note
To make things a little more confusing, the first link you provided mentioned Digital Twins and Device Twins as if they're two different things, while in fact, it's three. You have the Device Twin in IoT Hub, the Digital Twin in IoT Plug and Play context and a Digital Twin within Azure Digital Twins. It's important to understand the differences between the three, as ADT is a separate system, but PnP Digital Twins and Device Twins are accessible through your IoT Hub.
We have a Gateway device which is registered in IoT central application. This gateway device is connected to multiple similar Sensor devices such as Philips hue bulbs via ZigBee.
We are sending telemetry from sensors to IoT central via simple JSON
{"mac":"<mac address>","illumination":"200","bulb_status":"1"}
In IoT Central, we have registered our Gateway device as the IoT device with a device template which has telemetry properties related to Philips bulb and other sensors as well.
Now the challenge we are facing is, how to differentiate the data that is being sent by Philips bulb in room1 and Philips bulb in room2 in the IoT central as we have only 1 device registered in IoT Central.
The JSON has similar properties for both the bulbs and the telemetry values in IoT Central are being replaced by whichever device sends the last message.
Please provide me with the correct scalable approach for this kind of scenario.
Note: Consider our gateway device can't run IoT Edge runtime as of now. So we can't use it as Edge device.
There are two ways to tackle this. The first would be to program your gateway device to supply an identity to each of your bulbs. This means all your lamps will become a separate device in IoT Central (and you will be charged for them). Your gateway device will need to have the connection details for all of the devices it is sending telemetry for.
A second (not so pretty) way is to add a telemetry point to your interface for each lamp. So instead of brightness you would have lamp1_brightness and lamp2_brightness. I'm only including this in my answer because it is feasible and will result in seeing dashboard per lamp in IoT Central. It does not scale well either.
Eventually Azure IoT Edge will support Identy Translation, which can solve this and other questions
I have put up an E2E example of Nano BLE devices with data captured via a Central Gateway based on a Raspberry Pi using the Azure IoT Python SDK. This example is "in-progress", but I think you might find two files useful...
Main Project
https://github.com/Larouex/IoTCRaspberryPiProtocolTranslationGateway
BLE Project
https://github.com/Larouex/IoTCNanoBLESense33
File you might want to check out...
scandevices.py
https://github.com/Larouex/IoTCRaspberryPiProtocolTranslationGateway/blob/master/scandevices.py
This script uses BLEScan to find the BLE devices matching a naming pattern and writes them to a configuration file.
provisiondevices.py
https://github.com/Larouex/IoTCRaspberryPiProtocolTranslationGateway/blob/master/provisiondevices.py
This script and associated class use the Azure IoT SDK for Devices to read the devices in the configuration file and provision them in Azure IoT Central. The current code does a transparent approach and uses the identity of the BLE Device to provision and looks like a real device in Iot Central.
Over the next couple weeks I will continue to add the other scenarios like Opaque and Protocol Translation (which looks like the scenario you are interested in).
You may want to consider your differentiations of the Hues by modeling the locations and separate the telemetry values (versus plotting mac addresses), but you will hit some brittleness in versioning as you add or try to delete bulbs.
I recommend identify translation and associate each bulb with a model. Use the Device Groups for aggregate views. Then device properties because useful for location, etc.
I want to implement the following system.
There are users and each user will have an IoT device. The user should be able to do the following:
Login with their email and password.
Control the IoT device in real time (the user will perform some operation on the IoT device and the result will be displayed instantly on the app).
See the state of IoT device in real time. If something changes on the IoT device it should reflect on the app in real time.
I was wondering if this is doable using azure IoT Hub. I came across an architecture where the device is connected to IoT hub and the app is connected to signalR. The messages from IoT device will go to IoT Hub which will update the app using signalR.
But is there any way we can not have additional component like signalR? Can IoT device and mobile app be connected directly to azure IoT hub and exchange data between them without an entity in between other than IoT hub?
Connecting mobile app to IoT hub seems like an option but I did not find any way to implement email and password based authentication to allow users to connect to IoT hub.
Any help in this regard is appreciated.
You could absolutely go without SignalR. You can use the IoT Hub Service SDK to send C2D messages to your device from your phone, and also listen to the device telemetry with the same SDK.
However, it would probably be a better idea to have some restrictions on what you can do with that SDK. If the user first has to log in, I take it that they don't get access to every device in your application? Using some kind of role-based access might be preferable, you would build an API for that, which then uses the Service SDK to give you the data.
Also, even though you could listen to the device data directly from your phone, that means that if you have bad reception/wifi, data might not be received. You might want to consider storing it somewhere? I don't know the details about your application, but if you would then want to listen to events from that storage and send it to your app... SignalR might not be the worst idea.
"See the state of IoT device in real time. If something changes on the IoT device it should reflect on the app in real time."
For this EventGrid integration (https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-event-grid ) would help. For realtime telemetry as Matthijs said SignalR would be a better choice.If you are fine with some delay (say 10 sec) then Azure Time Series Insights can also be used.
How can an IoT device which connects to an IoT Hub using the Azure IoT Hub SDK retrieve larger amounts of sensitive data which is part of the device configuration?
I know i can use Device Twins as configuration documents per Device, but those are limited to 8K in total.
I need larger amounts of data in binary format to be transfered to the device when i a device - for example - gets reset to factory defaults or somehow loses it's local storage as part of a hardware fault.
I was thinking about using a D2C method triggering a request which results in a series of C2D or direct method calls to the requesting device transmitting the information in question (basically mimiking request/response behavior). However this feels like a workaround.
My other thought was about transmitting urls to a storage account as part of the device twin properties allowing the device to download the binary information using the Storage SDK, however given the sensitive nature of the information downloaded i can't directly expose this information to the internet using a public accessible container in Azure Storage.
So my last thought was to access a REST API which controls access to the information. However my concern is, that i break out of the secure communication channel, the IoT Hub SDK provides with it's build in communication methods and i have to secure the communication between device and the REST API using some kind of rotating secret anyway which could expose other risks along with a complicated custom implementation.
What is the suggested way of providing access to this kind of device-specific data for Azure IoT Clients?
I do recommend to use a new feature (still in the preview) of the Azure IoT Hub such as a Device Streams.
You can test this new preview feature using my updated tool Azure IoT Hub Tester (see Appendix A2)