Receiving D2C messages from an IoT Hub in browser - azure

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.

Related

Which is an appropriate NodeJS code to send telemetry from device to IoT hub?

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!

Connect to Azure MQTT using SIM808

I want to send SIM808 GPS data to the Azure IoT hub using MQTT.
As mentioned in docs of azure, I have used the same parameters.
https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support#using-the-mqtt-protocol-directly
But it doesn't work. Did not published.
Can we connect to Azure MQTT using Username and password without attaching certificate? if not
How to create the certificate?
How to send SIM808 data to the Azure IoT hub using MQTT?
Suggest me a way to do it with an example.
Thanks!!!
Yes, you can do it. You can use tokens.
As a simplest alternative you may also use flespi telematics hub to reach same goal. Your device can send via HTTP or MQTT messages to flespi channel. And flespi will stream processed information to MS Azure and/or AWS in their specific protocols.

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.

Which is the secure way of reading the data from the Azure IoT hub?

I am working on internet of things, in one of my current project I am reading the data from Azure IoT hub in a Windows 10 UWP app, where I am passing my IoT Hub connection string to azure while reading data( using Cloud to Device concept).
Is it secure/fine way or not reading data from a client app.
Thanks,
Pradeep
Yes. The library uses https, however the contents of the message is not encrypted, so if you're super-sceptical, just encrypt it before sending.

Azure IoT Hub : retrieving messages via browser-side javascript API

Do you know if it is possible to retrieve device-to-cloud messages, with Microsoft Azure and IoT Hub, with a javascript client running in the browser (i.e. no node js) ?
It is my understanding that this is not currently possible, but I'd like to make sure (i.e. all current APIs can only work server side).
Edit1: REST APIs might be the obvious choice to attempt to do this; However, having tried these APIs via manual request, it seems the response does not provide the allow-access-control-origin header, so I can't call them from ajax due to CORS.
UPDATE: The example code was removed by requirement from Azure IoT Hub team, and they do not like users to connect to IoT Hub from browsers (https://github.com/Azure/azure-iot-sdk-node/issues/112#issuecomment-338073636).
Sorry for the broken links in this answer.
It seems this is an old question, however, I find there is still nobody can give the right answer.
In short, is there a way to read IoT Hub D2C messages in browser? The answer is absolute YES!
You shouldn't use RESTful API to loop checking messages, but use AMQP over WebSockets.
Before you start, you must know that IoT Hub has two sides, Device side and Service side. For Device side, you connect to IoT Hub using HTTP, AMQP and MQTT, however, for Service side you can ONLY connect to IoT Hub using AMQP.
Fortunately, Red Hat had already written a AMQP over WebSockets Node module, and you can do some simple work to make it working in browser.
You can learn more about the AMQP Node module from https://github.com/grs/rhea.
Also, we've made a web based tool for receiving D2C messages https://iotdevtool.com/service/, you can learn more about it from https://blogs.msdn.microsoft.com/zhiqing/2017/03/16/connect-to-azure-event-hub-in-browser-using-amqp-over-websockets/.
I haven't tried it myself but my understanding is that it's possible to retrieve cloud-to-device messages in JavaScript using the IoT Hub REST API.

Resources