Which is an appropriate NodeJS code to send telemetry from device to IoT hub? - node.js

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!

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

I am trying to understand how to choose number of Azure IOT Hubs in a scenario where I have variety of devices sending variety of data

I am trying to understand on do I need to choose individual IOT HUB based on device category.
For Example I have devices sending GPS info.
Devices send stock info
Devices sending quality info.
Devices sending security info.
Devices sending fire safety info.
Each of the above category devices send versatile data in versatile format. In this scenario is it a best option to configure multiple IOT hubs or one IOT hub is suffice.
Thanks in Advance....
As the IoT Hub is totally agnostic to the actual data that you are sending, you would not need to have separate IoT Hubs per use case. You can still connect all the devices to one IoT Hub and then route the telemetry data, for example based on on device properties, to different downstream processing steps.
You might still want to use multiple IoT Hubs but mainly then for either scaling reasons or for geographical distribution.

Receiving D2C messages from an IoT Hub in browser

I am working on a simple dashboard for showing IoT data in a browser.
So far, I was using the Paho MQTT client library and a public MQTT broker to receive data. However, I'd like to use the Azure IoT Hub from now on.
The data I'm sending is just simple temperature and humidity values.
I already found out that I can't connect to the IoT Hub via MQTT. So my question is:
Is there a possibility to connect (eg. using javascript) directly to IoT Hub and read the data?
If not, what's my best option?
I thought about saving the messages to an SQL Database and reading from that, but that seems quite complicated for what should be a simple IoT use case (showing real-time data)
Thank you in advance!
You can connect to IoT Hub via MQTT. Please take a look at this documentation for detail. We also have a Node.js SDK for connecting to IoT Hub if you don't want to deal with MQTT directly. I know you are working on your own dashboard, but have you looked at Azure IoT Solutions Accelerator? It's completely open source and you can modify it as you want.

Creating a workflow for an IoT project

I was using ThingSpeak for an IoT project. I've decided to move on with Azure IoT. My project consists Raspberry Pi 3's sending data to an IoT platform using MQTT protocol which will be displayed over mobile app.
While using ThingSpeak, things were easier. I was sending data to IoT platform, ThingSpeak was storing them without me configuring almost anything and mobile app that I wrote was sending HTTP request to IoT platform with an interval. Then, I was parsing JSON response on mobile app to display important values in real time.
So far I've managed to send datas to IoT hub using Azure IoT C SDK. However I am very confused about how I am going to implement these on Azure IoT, what my workflow should be like.
Azure IoT Hub ingests data from your devices into the cloud and then delivers that data to other destinations for storage or processing. By default, IoT Hub delivers data from devices to an Event Hubs compatible end point (these Quickstarts illustrate this process: https://learn.microsoft.com/azure/iot-hub/quickstart-send-telemetry-node). IoT Hub can also use routing rules to send data to other locations, such as storage or a Service Bus queue. The following tutorial illustrates these options for you: https://learn.microsoft.com/azure/iot-hub/tutorial-routing.

Change record time for IoT DevKit AZ3166 language translator example

I am following the guide IoT DevKit AZ3166 to make a translator using the MxChip.
I was able to follow most of the steps at ease but was wondering How I can increase the recording time for the translation ? - this is such that it can translate phrases that are a bit longer.
Thank you.
The DevKitTranslator example is only a proof-of-concept to leverage the Azure IoT Hub, Functions and cognitive translator API to process audio sensor data. This example records the audio data and store it temporally in the device flash (1M). So due to this memory resource limitation it is hard to record a longer audio.
If you really want to expand the record time, it would probably need a re-architecture of this example:
Change the device code to use WebScoket streaming to upload the audio to cloud continually. We have already provided a WebSocket client library for DevKit.
Build a Azure Web App that supports WebSocket protocol to process the audio streaming from the device, and then invoke cognitive service translator API to do the translation.
Send the translation result back to the device via IoT Hub C2D message.
If you really want to try this solution architecture above you can refer to or try the DevKit Chat Bot example. This is a more sophisticated example to demonstrate the power of the IoT DevKit to integrate with more Azure AI Services which is transmiting the continuate audio data via WebSocket streaming.

Resources