IoT & Blockchain — A demo application with Microsoft Azure

Axel Banderet
6 min readMar 3, 2020

Objective

Following the growth of Blockchain and Smart Contract across multiple applications, I was curious to figure out if we could leverage on their intrinsic benefits to optimize the use of collected IoT data. As a result, this article presents a Blockchain based demo application fed by a Sigfox IoT device that triggers Smart Contract related actions on Microsoft Azure.

Introduction

Sigfox 0G network allows to collect unprecedented amount of data from wide types of sources that were not possible to connect so far. However, this huge amount of information does not reveal a relevant value unless it is analysed and processed appropriately. Once correctly handled, this extracted data reveals a tremendous amount of value. This is the power of IoT and this is also why Sigfox-based value propositions are never only about collecting the data but more importantly about creating value out of it.

On the other hand, Blockchain has emerged in the past decade as one of the most useful and democratized technology. As a result, many applications in multitude of verticals are now adopting it. To quickly recap, a Blockchain is a series of blocks of information linked by cryptographic hashes which are distributed across a network of nodes. Each of them has a local copy of the blockchain and verifies the new blocks by reaching an agreed consensus. Hence, the Blockchain becomes a public distributed ledger of information which is inherently immutable, transparent and secure. This is how it defines a new way of storing and exchanging information.

Following this growth potential, several edge technologies have been developed on top of the Blockchain. Smart Contracts are one of those. The concept is basically to pre-define logical rules and actions that will be triggered depending on the data processed within the Blockchain. Among others, it allows us to use the Blockchain data as an input and define modular, automatic, instantaneous and administrative-free actions based on it.

This article makes an overview of the related tutorial available here on Github.

Here we will directly start from the end with a demo of the solution and discuss briefly about the architecture in a second phase.

Demo

In this demo, the related Smart Contract enforces certain rules related to conditions during transport. Specifically, receiving and evaluating temperature and humidity data against an agreed and acceptable range. If the Smart Contract identifies that the telemetry is out of the range, it will immutably shift into an OutOfCompliance state and appropriate remedies will be sought. By default, the contract starts in the Created state. Then, as it transits through each intermediary of the chain, it will shift in In Transit state and finally ends up as Completed.

In the happy path, the device sends readings, which are in compliance throughout the transportation process, while the involved counterparties transfer responsibility until the transportation is completed.

Let’s present the solution through an example. A pharmaceutical company “VitalPharma” requires their products including vaccines to be shipped to hundreds of pharmacies across Europe. Since those products require a strong integrity management and conditions monitoring, VitalPharma is partnering with a highly reliable delivery company “deliver.it” specialized in the shipment of such products.

In order to commit to its reliability, deliver.it guarantees a full refund of the amount of the shipment if the pre-defined rules are not respected. At the end of the chain, the pharmacist “Joe Bloggs” will confirm the reception of the package. All those users are listed into an Azure Active Directory instance which makes it easy to manage.

Every counterparty can log on to the WebApp to follow the shipment and Take Action. Here we log in as VitalPharma and first define the smart contract rules:

The shipment appears as Created:

Once the shipment is handled by deliver.it, VitalPharma is able to transfer the responsibility.

When logging in with deliver.it account, it appears we are now responsible for the shipment. The same process will continue until shipment is accepted by the last element of the chain.

Now comes the interesting part. If the Sens’it measures for instance an out of rage temperature, here is what happens:

The said contract shift automatically into an OutOfCompliance state.

Automatic alerts and remedies such as a refund can be set up:

Such mechanisms should help in optimizing and automating future IoT data processing.

Architecture

Starting with a simplified diagram of the data flow:

While here below is an overall picture of what is actually implemented:

Following sections will deep dive into the various elements of the architecture while additional information can be found on GitHub.

1. Write into Azure

The Sigfox Sens’it sends some data over Sigfox 0G network. Then the Sigfox Cloud pushes it through an HTTPS callback up to Microsoft Azure IoT Hub.

2. Prepare the data

A suite of Azure services are then being solicited. First we use a Function App to parse the data into Temperature and Humidity decimal values. It is then collected in a Service Bus that is responsible of routing it up to a Logic App.

This Logic App has a simple objective: formatting the previously mentioned data into something that can be ingested by Azure Workbench Blockchain.

3. Push into the Blockchain

Two consumer services are listening for incoming messages into the previous service bus. The first one is a Database Consumer that will automatically push event informations into a simple SQL database.

The second one is a Data Ledger Technology Consumer responsible of forwarding the metadata for transactions to be written to the blockchain. The Transaction Builder & Signer assembles the blockchain transactions based on the related input data. Once assembled, every transaction is signed and delivered to Azure Blockchain Service through a specific router. Private keys are stored in Azure Key Vault.

4. Interact from WebApps

Finally, Azure Workbench Blockchain provides plug and play interaction tools such as a Client web app and a Smartphone app. They are connected to an Azure Active Directory for users and roles management.

Conclusion

IoT and Blockchain can be an interesting mix in many verticals: Industry 4.0, Supply Chain, Retail.. while the development of tools such as Azure Workbench Blockchain allows to deploy a proof of concept in just a few days. If you are interested in reproducing, more information will be soon available on Sigfox Build Platform.

To finish, here we discussed about a private blockchain usage however I believe we could also imagine further applications based on public blockchains.

Get your Sens’it!

Sources

https://docs.microsoft.com/en-gb/azure/blockchain/workbench

--

--