Azure IoT DeviceClient SDK Python demonstration, the basics

In the past, I wrote a blog about the Azure IoT device SDK. This example was written in C#.

Last year, I noticed an increased number of questions coming from Python users trying to connect devices to the cloud. Luckily, the driving force behind this is the growing community of ML developers using Python. They are increasingly involved in IoT projects.

That’s why I scrambled some samples together into one demonstration showing the capabilities of Azure IoT Hub-connected devices.

We will see how device-to-cloud messages are sent from the device to your IoT Hub. And we will see several ways of cloud-to-device communication so we can enforce actions on the device.

Update: recently, I added a second Python script with an individual Device Provisioning Service Enrollment based on a symmetric key. The example is exactly the same, you only need to provide other variables for this provisioning.

This introduction will get you started within a moment.

Doorgaan met het lezen van “Azure IoT DeviceClient SDK Python demonstration, the basics”

Connecting Advantech ICR to Azure IoT using NodeRed

In the past, I have written about that perfect NodeRed node for Azure IoT. Using this node, you can connect to eg. Azure IoT and Azure IoT Central from any NodeRed solution.

I came across the Advantech ICR devices which offer cellular (4G) router connectivity in a ruggedized format and you can add your own custom logic:

You can either put C or Python apps on them and you also can use NodeRed on the V3 and V4 platforms.

Let’s dive into this NodeRed support and have an ICR connected to Azure:

Doorgaan met het lezen van “Connecting Advantech ICR to Azure IoT using NodeRed”

Positioning GPS devices on a map using Azure Functions, Azure SignalR Service and Azure Maps

Last year, I bought this RAK7200 Lora Tracker with the idea to track my bicycle in the neighborhood.

This month, I finally found some time to have this device connected to the cloud and map its position.

This tracker from RAK Wireless, running on a rechargeable battery for multiple days, has several sensors aboard and is connected to a Lora network:

RAK7200 LoRa® Tracker | The Things Network

Here you see the payload as presented in The Things Network console:

Potentially, I could even do some alerting based on the movement of the device, even if there is no GPS fix (acceleration, magnetometer).

An uplink payload formatter can be found here. I changed it a bit so the latitude, longitude, etc. are decimals, not strings:

The same goes for the battery power.

Showing a generic location in Azure Maps is not that hard, there are many samples available. But I wanted to have the map updated IN REAL-TIME!

The TTN portal now supports the Azure IoT Hub natively so I was looking for a way to represent the ingested location in Azure Maps.

Azure Maps tiles live inside the browser. I also needed something like Websockets to update the page representing the map. For this, I wanted to use Azure SignalR Service.

Last but not least, I was looking for a lightweight website because I need to host the pages somewhere.

This is the solution I came up with:

Let’s check out how this is done.

Doorgaan met het lezen van “Positioning GPS devices on a map using Azure Functions, Azure SignalR Service and Azure Maps”

Sending IoT Hub telemetry to a Blazor Web App

For those who are interested in software development for the web using the C# programming language, Blazor is a viable alternative for building progressive websites as compared to Asp.Net Core / Angular / JavaScript.

Blazor lets you build interactive web UIs using C# instead of JavaScript. Blazor apps are composed of reusable web UI components implemented using C#, HTML, and CSS. Both client and server code is written in C#, allowing you to share code and libraries.

In the past, I already implemented Blazor on the Edge, including message routing.

Now, let’s see how we can integrate a Blazor website with telemetry coming from an Azure IoT Hub in the cloud.

For this to happen, we need this architecture:

So, the moving parts are:

  • An IoT Hub with message routing enabled
  • Azure Function with IoT Hub / EventHub trigger
  • Server-side Blazor website with API Controller integration

Let’s see how this is set up.

Doorgaan met het lezen van “Sending IoT Hub telemetry to a Blazor Web App”

Belgische Rijksregisternummer checksum testen (Dutch)

Note: This text is written in Dutch, one of the three official Belgian languages. The code example is annotated in English.

Iedere Belgsiche inwoner heeft een rijksregister nummer. De Belgische overheid kan hiermee alle persoongegevens achterhalen van die persoon. Dit is dus een uniek nummer.

Bij ‘unieke’ nummers in het algemeen is het verstandig om deze nummers slim te kiezen. Als deze direct opvolgend zouden zijn (1, 2, 3, etc.) dan is een typefout snel gemaakt en niet direct op te merken. Daarom worden unieke nummers (zoals nummers op papiergeld of bankrekeningnummers) versterkt met bijvoorbeeld een 11-proef. Het idee is dat alleen correcte nummers dan deelbaar moeten zijn door een priemgetal, zoals elf in dit geval. Als dan toch een typefout wordt gemaakt, wordt dit direct opgemerkt. Een typefout die nog steeds uitkomt op een getal dat ook door 11 deelbaar is, is dan heel klein.

Het Belgische rijksregisternummer is echter niet zomaar een ‘willekeurig’ uniek. Het is opgebouwd uit oa. de geboortedatum.

Hoe is dan het nummer ‘beveildigd’ tegen typefouten?

Doorgaan met het lezen van “Belgische Rijksregisternummer checksum testen (Dutch)”

Attach Blazor to Azure IoT Edge routing, showing live message feed

In the last couple of months, I have fallen in love with Blazor. I can almost shout out: “imma firin mah Blazor!”

ASP.NET Blog | Blazor now in official preview!

Blazor makes it possible to produce interactive web UIs using C# instead of JavaScript:

Blazor is a web framework based on Asp.Net core:

Blazor apps are composed of reusable web UI components implemented using C#, HTML, and CSS

In the past, I have already shown how to deploy a Blazor app as a container using the Azure IoT Edge deployment mechanism. This makes it possible to deploy and run a Blazor app on the Edge. There is no interaction with the Azure IoT Edge routing mechanism, though.

Wouldn’t it be nice if a Blazor app could actually receive IoT Edge messages or even could send IoT Edge messages to the cloud using that same routing mechanism?

This is what we want:

tldr; yes, this can be done.

Let’s see how this you can pull this off too.

Doorgaan met het lezen van “Attach Blazor to Azure IoT Edge routing, showing live message feed”

IoT Edge Docker Module with GPIO support on RPi

The C# .Net Core framework is pretty versatile. Next to all the operating system features and Windows features, it also supports GPIO for a variety of devices: Raspberry PI, Hummingboard, Windows 10 (core), etc.

I was interested in accessing the GPIO in an Azure IoT Edge solution on a Raspberry Pi.

I am aware of the elevated rights needed. It’s the same with serial ports access I encountered in the past.

So I did a test, quite similar to the setup of this GPIO introduction:

Let’s check out how we can get this running in an IoT Edge module.

Doorgaan met het lezen van “IoT Edge Docker Module with GPIO support on RPi”

Uploading an image to Azure Blob storage

Adding an image to the Azure Blob storage is a basic skill for developers. But working with images is not something developers do on a regular basis.

If you are using hardware independent code, .Net Core does not make it any simpler, a lot of the examples found on the internet are written for the regular .Net framework.

Image handling was bound to a lot of OS related features. But Microsoft had to learn .Net Core some GDI tricks.

Here is a simple example of how to construct and send images, created in memory, to Azure Blob storage.

Doorgaan met het lezen van “Uploading an image to Azure Blob storage”

Visualize Azure IoT Edge device routes as a flowchart in Asp.Net MVC

If you look at the routes page in Azure IoT Edge configuration wizard, what do you prefer?

The current notation:

Or do you prefer a flow chart like this:

The routes in Azure IoT edge are a clever solution to describe how messages from one module are sent to another. But the JSON notation can become less readable once you add more (up to twenty) modules. That could end up eg. nineteen routes or more!

Just as an experiment I was thinking about how the ease the experience using a graphical interface.

I prefer the second solution, probably just like you.

So let’s look at how you can create the same experience with your routes of your IoT Edge device.

Doorgaan met het lezen van “Visualize Azure IoT Edge device routes as a flowchart in Asp.Net MVC”

Create your own local Azure IoT Edge dashboard

Earlier this year, when Azure IoT Edge was still in Public Preview, I wrote a couple of blogs about Visualizing Azure IoT Edge using local dashboard.

Back then, I had to do some magic with both a C# IoT Edge module, a custom NodeJS docker container, and a Docker network to get it running.

Since then, a lot has changed. Microsoft already released a ton of new features. a And there is still more to come regarding the Azure IoT platform.

But that awkward local dashboard solution was nagging me. A few months ago, Microsoft introduced a NodeJS module as a first-class citizen for IoT Edge modules.

So it was time to pick up the gauntlet and use NodeJS for this awesome local IoT Edge dashboard:

#tldr;  If you like to dig into the code, zip it, clone it, extend it or even make a pull request, I made this project open source. If you only want to use it the easy-going way, pull it from docker eg. ‘svelde/localdashboard:1.0.1-amd64’.

At this moment, only Linux containers are supported. It is tested both on Windows and Ubuntu as host OS.

Interested in this module? Let’s see how you can use it.

Doorgaan met het lezen van “Create your own local Azure IoT Edge dashboard”