So, it is time to dive into this protocol by running an MQTT broker on the edge and consuming it:
Yes, we are going to deploy a regular MQTT broker as a docker container within Azure IoT Edge (which uses Moby under the covers). Then, we bridge messages sent to MQTT topics to the cloud using Azure IoT Hub.
For this exercise, I have chosen HiveMQ as a broker.
Most of you Azure IoT developers are connecting devices to the Azure cloud using the Azure IoT Device SDKs.
Using these SDKs, you can connect a device to the cloud in an easy and secure way with your favorite programming language like C#, C, Java, Python, or Node.js.
This is the recommended way because it offers a convenient and optimized way to support all Azure IoT Hub features like Device Twin, Direct methods, and Cloud messages. It takes away a lot of the code wiring and you can focus on functionality.
Still, in a few instances, like working with very constrained devices, there could be a need for bare MQTT support:
MQTT is the de-facto standard for stateful communication in the IoT World (btw. Bare AMQP is offered too).
Let’s see how the Azure IoT Hub supports bare MQTT.
Do you have cloud-connected IoT devices to the Azure IoT Hub and have you specified the specific public ‘Baltimore’ TLS certificate currently in use by the IoT Hub? Do you know customers having (low-powered) devices connected to Azure IoT and possibly pinned that certificate?
It all started with this workshop back in 2016 that I built together with my friend Jan Willem Groenenberg where we connected the TTN backend with the Azure Cloud. Over the years, we organized many events based on the workshop.
We needed a ‘bridge’ to bring two worlds together: The Things Network backend applications and the Azure cloud.
I created this TTN azure bridge based on the MQTT protocol supporting a stateful exchange of D2C (uplink) messages from Lora devices to an Azure IoT Hub and supporting C2D (downlink) messages back to the devices.
Since then, the TTN backend migrated twice and now we have this new Version 3 backend with lots of goodies!
I got already some questions about the original bridge and I was informed it is not sufficient anymore so I took some time to revisit the MQTT uplink and downlink support in TTN applications:
We will why this is still a solid solution but we will also look at a possible alternative.
A few month ago, I wrote about how to collect telemetry from The Things Network back-end and send them to an Azure IoT Hub.
The code was simple and it only provided telemetry for one device. But the technology used, was working.
Last month, I was involved in creating a workshop for the TechDays 2016 in Amsterdam. The two-hour workshop gives a good impression how to build an IoT Backend in Azure. During this workshop, we used a NodeJs bridge to pass the telemetry to Azure.
This bridge is available at using the NPM package installer: npm install –save ttn-azure-iothub@preview
I got inspired by this bridge and now I have rebuilt my bridge to handle multiple devices and more!
Somewhere in December 2015, I was made aware of this Lora initiative called The Things Network. Since then, as an IoT enthusiast, I am researching how to implement this platform in my other IoT projects.
Update 8-11-2016: this blog gives an introduction to MQTT and accessing the TTN network. A full implementation of a C# TTN->Azure bridge is available at GitHub. More details are available here.
Lora stands for Long Range and it fills a gap between Wifi and GMS, thinking about wireless connectivity for IoT sensor boards:
At the moment there are two serious implementations of Lora in The Netherlands. KPN is offering a commercial solution so it’s reliable but it does not come free. And then there’s The Things Network, a Kickstarter solution. It offers free connectivity :-).
What they ‘sell’ are gateways. These come fairly cheap (starting at ~ 250 euros) but with their gateway, you can connect up to 5 kilometers (keep on dreaming about 10 :-)) around your house with Arduino’s, ESPs, RaspberryPi etc. And with a couple of these gateways, you can cover your village or city. So get your friend involved!
The telemetry of the nodes (say twenty bytes of date every minute) are received by the gateways and forwarded to the TTN backend. But you have to do ‘something’ yourself to get the data from the backend. I will tell you how to do that using C# all the way.