1. Introduction

In this post I will show the build of a Secure IoT Air Quality Sensing Station, a device based on the Avnet Azure Sphere MT3620 Starter Kit.

The proof of concept device has the following features:

  • air quality monitoring using the PMS7003 sensor - measures the concentration of the < 1.0, 2.5, 10.0 um particles in the air
  • atmospheric pressures and temperature monitoring
  • OLED display
  • Azure IoT Central application
  • A7 high level + M4 real time applications, with inter-core communication

 

1.1 Azure Sphere

Azure Sphere is Microsoft's secured, high-level application platform for Internet of Things solutions.

 

It consist's of 3 main parts:

  • a secure Azure Sphere MCU micro-controller unit (MCU), right now the MediaTek MT3620 is supported
  • the Azure Sphere OS, a Linux-based operating system maintained by Microsoft
  • the cloud based Azure Sphere Security Service (AS3)

 

Currently there are 3 official development kits that we can use to experiment with the Azure Sphere platform:

          Avnet MT3620 Starter Kit                     Seeed MT3620 Dev Board & Mini Dev Board

 

 

All of these are based on the MediaTek MT3620 MCU which was designed by MediaTek in collaboration with Microsoft.

 

The MCU has the following main features:

  • 1 x ARM Cortex A7 core for high-level applications
  • 2 x ARM Cortex M4 cores for real-time control
  • Wifi Subsystem with dual band, 2.4 + 5 GHz, support
  • I/O: 76 x GPIO, 12 x PWM,  5 x I2C / SPI / UART, 8 x 12-bit ADC, etc

 

Nothing too interesting so far..

 

What makes the MT3260 interesting is the Microsoft Pluton Security Subsystem built in it. The Pluton subsystem has its own M4 processor, contains a true random number generator, accelerators for different cryptographic tasks (SHA, AES, EEC), two EEC private/public key-pairs generated in-chip during the manufacturing.

 

Pluton also implements a secure boot system with remote attestation. This means the authenticity of the loaded boot image (OS + application) is verified with the Azure Sphere Security Service (AS3). If the loaded image is valid / up to date, the AS3 issues short living client certificates (~1 day validity) for the device, which then can be used to connect to other online services. If the loaded image in not valid / up to date, a client certificate is not issued, forcing the devices to do an update.

 

2. Getting Started

 

In this section we will see how to set up and run examples the Azure Sphere Starter Kit.

 

(Note: a more detailed description of this section can be found in my Azure Sphere based Secure Anti-Theft Device project)

 

2.1 Prepare

There are a couple steps that need to be done to get started with the Azure Sphere Starter Kit:

 

After these are done, we can try running examples on the device.

 

2.2 Examples

 

There are three types of examples that we can run:

 

The last two examples are based on the following two tutorials:

 

I used the source code from the first one as the base for my project.

 

3. Hardware

The components used in this project are the following:

 

3.1 Avnet MT3620 Starter Kit

The Avnet MT3620 Starter Kit is a development kit based Azure Sphere module AES-MS-MT3620-M-G.

 

It has the following features:

  • on-board sensors: Accelerometer + Gyroscope, Ambient Light, Pressure
  • support for 2 Click modules
  • support for Grove sensors
  • support for a 4 pin OLED display
  • on-board debugger

 

 

3.1 Plantower PMS7003 - Laser Dust Sensor

The Plantower PMS7003 is an air quality sensor, which measures the concentration of particles of different sizes in the air. The sensor measures particles with a diameter between 0.3um and 10um.

 

The PMS7003 uses UART communication with a custom data packet format.

 

To connect the PMS7003 to the Sphere Started Kit I fabricated a DIY adapter that exposes the 3.3V, GND, RX, TX pins of the Click connector.

 

 

 

 

3.2 OLED Module

A 4 pin OLED module can be used to display useful information:

 

 

3.3 Enclosure


As the air quality sensor will be placed outdoors, it is recommended to use a protective case / enclosure. I used a IP65 junction box:

 

with a 3D printed adapter for the PMS7003:

 

3.4 Assembly

The assembly was pretty easy. I just needed a little bit of hot glue to fix everything in place:

4. Software

The software running of the Azure Kit has two parts:

  • a high level application running on the A7 application processor
  • a real time capable application running on one of the A4

The two cores are communicating through inter-core communication.

 

As a starting point for the software I used the Avnet Azure Sphere Starter-Kit: Advanced Tutorial by Peter Fenn. This already had examples application for both the A7 and M4 cores.

 

4.1 A7 High Level Application

 

The high level application running on the A7 application processor is responsible for:

  • reading the PMS7003 sensor (optional if the real-time app is used)
  • reading some of the sensors
  • handling the OLED display
  • handling the buttons / LED
  • could communication the Azure IoT Hub and Azure IoT Central
  • inter-core communication with the M4 cores

 

The OLED screen and Azure IoT Central related code was updated to include the data from the PMS7003 sensor.

 

4.2 M4 Real Time Application

 

One of the M4 Real Time capable core of the MT3260 is used the offload the handling of the PMS7003 sensor, for the main application processor.

 

The sensor data is transmitted using inter-core communication, supported by the MT3260 MCU.

 

(Note: the code for this part is done, but was not yet tested. The Sphere SDK on my PC got somehow corrupted and did not managed to fix it yet...)

 

4.3 PMS7003 Sensor Driver

 

As I did not found a C library for PMS7003 compatible with the MT3620, I decided to get a Arduino C++ Library and rewrite it to C / MT3620 compatible code:

 

The library I choose a library that also available from the Arduino IDE: https://github.com/fu-hsi/pms. As a first step, I checked with a ChipKit Uno30 that the library works.

 

Next I migrated / rewrote the library to work with the MT3620. This included multiple steps:

  • migrated the code from C++ to C
  • migrated the UART communication part to use the MT3620 UART libraries
  • refactored a little bit the API of the library to work better with the async nature of the UART library

 

The library was implemented both for the A7 high level and M4 real time application. The two version have just minimal differences.

 

5. Azure IoT Central Application

 

The UI of the project is done using Azure IoT Central.

 

To get started we can follow the tutorials from the Getting Started section

 

5.1 Device Template

 

The first thing to do is define the measurements for the fields we send form the device.

 

In my case these were the following:

  • PM 1.0, 2.5 and 10.0 values
  • PM 1.0, 2.5 and 10.0 values see level atmospheric pressure
  • atmospheric pressure data

.

 

5.1.1 Adding a device

Next we can add our device:

and create a connection for it:

 

Having this we can generate a connection string using the dps-keygen utility:

 

$ dps-keygen -si:<scopeID> -di:<deviceID> -dk:<privateKey>

 

 

 

Azure IoT DPS Symetric Key Generator v0.3.3

Connection String:

 

HostName=iotc-2e2dxxxx-xxxx-xxxx-xxxxxxxxxxxxxxx.azure-devices.net;DeviceId=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;SharedAccessKey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=

The resulting connection string need to be placed in the connection_strings.h file.

 

5.2 Measurements

 

After this the device should be able to send data to the Azure cloud.

 

And we should be able to visualize it.

(the diagram shows a 3 hour period, in a Friday afternoon)

 

In case we like more exact values, we can take a look at the telemetry tab:

(pretty much no smog today in Cluj )

 

5.3 Dashboard

We can also configure dashboards:

like the one bellow:

5.4 Rules and Notifications

Azure IoT central also allows to define different rules with action assigned to them.

 

For example, I configured a rule the sends an email if the PM 2.5 gets over 150 ug/m3:

 

If the rule is triggered, I get an email like this:

 

 

6. Future Enhancements

 

The main parts of the project that could be significantly enhanced, I think are:

 

Power:

  • right now the device runs from a power bank of 10000 mAh. This provides enough power to run for about ~24 hours
  • a solar panel based system could be added to enhance the run time

 

Connectivity:

  • the device connects to the Internet through Wifi. A problem is that the Wifi network and key are configured from a PC, so are not that easy to change
  • an idea would be to allow changing the Wifi network from the Azure IoT Central interface
  • an other idea would be to add support for complementary connection interfaces, like: GSM / 3G / 4G, LoRaWAN, SigFox, etc.

 

Interfacing with other systems:

  • seeing the data from our sensor is nice, but would be even better if we could publish the data to existing air quality monitoring systems like https://aqicn.org/

7. Resources

 

The source code, 3D model / CAD files, and other resources of the project can be found in the following GitHub repository:

https://github.com/bluetiger9/Azure_Sphere_AirQualityMonitor

 

Related projects from Hackster.io:

 

Useful articles about Azure Sphere:

 

Hope you enjoyed!