How To Create an Air Quality Monitoring System with WisBlock, Helium, and Datacake

KHM-013-00.png

Overview

A healthy environment is essential for our well-being. This includes the air around you. So, how will you know if the air around you is clean and good, or if it is time to open a window and let some fresh air in?

With a few modules from our WisDuo and WisBlock product lines, it is easy to detect bad environmental conditions.

KHM-013-01.png

How Does It Work

One option to measure the quality of the air is to measure the concentration of volatile organic compounds (VOC). With the measured values of the Sensirion SGP40 and the Sensirion SHTC3, the Sensirion VOC algorithm calculates the VOC index from 0 to 500.

With the new WisBlock RAK12047 VOC Sensor, you can easily build a sensor system for your home or office that measures the VOC index of the air. Based on the Sensirion SGP40 and using the Sensirion Gas Index Algorithm, it is just Click-Code-Connect to build an air quality sensor.

KHM-013-02.png

The collected sensor data is transmitted over the Helium network to the Helium Console and then forwarded to the data processing tool Datacake.

In Datacake, the sensor values are not only visualized but also analyzed. A warning is sent to you if the VOC index indicates an air quality level that is not good for your health.

The sensor can be battery-powered and send the data every 2 minutes (configurable).

KHM-013-03.png

On Datacake, the received values are visualized.

KHM-013-04.png

Requirements

To create your air quality sensor system, you need the following:

Hardware

  • RAK3172 EVB - Evaluation Board with the low power RAK3172 based on the STM32WL5 MCU
  • RAK12047 - VOC module with the Sensirion SGP40 sensor
  • RAK1901 - Temperature and Humidity module with the Sensirion SHTC3 sensor
  • RAKBox-B3 Indoor Enclosure - Rated IP20 for indoor Industrial IoT Application matching WisBlock form factor board
  • RAKwireless Helium Hotspot - a Helium Hotspot or nearby Helium Hotspots in range

Software

How Does the Data Flow

The WisBlock VOC sensor reads data every 10 seconds (configurable) from the RAK12047 sensor module. It sends the sensor readings to the Sensirion Gas Index Algorithm, which calculates them along with the RAK1901 sensor's temperature and humidity values. The algorithm then generates a VOC index ranging from 0 to 500, indicating the quality of the surrounding air, with 100 being good and 500 being bad.

The calculated VOC index is then sent over the Helium Network every 2 minutes (configurable). The Helium Console registers the VOC sensor device and creates a flow to the Datacake integration. When a data packet containing sensor data arrives, the Helium Console forwards it to Datacake.

In Datacake, we configure the device and the visualization dashboard to view the measured values. In addition, a rule is created that sends an alarm message if the VOC index exceeds a certain level. This rule sends you an email with a warning about the poor air quality.

How to Build the Device

Set Up the Sensor Device

We are using the RAK3172-E Evaluation Board, which comes with the RAK5005-O Base Board. The Base Board has four sensor slots, and we place the RAK1901 and RAK12047 sensor modules in slots A and B.

KHM-013-05.png

Get the Sources

Next, we are downloading the application firmware for RAK3172. The application firmware is based on the RUI3 API, and the source code is available on GitHub.

The guides on how to compile the application firmware and upload the code can be found in the RAKwireless Documentation Center.

Set Up the Sensor Node

After the firmware is loaded to the RAK3172, set up the LoRaWAN credentials and other settings over the USB connection with AT commands.

Get the LoRaWAN credentials. The first one is the DevEUI, which is printed on the label of the RAK3172.

KHM-013-06.png

Set Up the Sensor Node in Helium

The next two will be provided by the Helium Console. Log in to the Helium Console and register a new device to obtain the required AppEUI and AppKey.

Go to the Devices tab and click the new device icon

KHM-013-07.png

Replace the Dev EUI with the RAK3172's Dev EUI and copy the App EUI and App Key (shown values are examples and should not be used).

KHM-013-08.png

đź“ť NOTE: After creating a new device, it will take several minutes before it is registered and can be used. Until then, the new device is labeled Pending:

KHM-013-09.png

Finish the Setup of the Sensor Node

Set up the credentials in RAK3172 using the AT command interface. Connect the evaluation board with the USB cable and start the RAK Serial Tool (or any other serial terminal application on your computer). Select the COM port and 115200 as the baud rate. Only six commands are required for the setup. Shown values below are examples and should not be reused.

KHM-013-010.png

Command Meaning
AT+NJM=1 Set LoRaWAN network mode
AT+DEVEUI=6081F940FA1A71C5 Set Device EUI
AT+APPEUI=6081F9C372FCDB36 Set Application EUI
AT+APPKEY=1B1FD3CA8F9D54D1FF4579063121BA5F Set Application Key
AT+BAND=10 Set LoRaWAN region (frequency band)
AT+JOIN=1:1 Start network join process

The complete AT command manual can be found in our RUI3 Documentation Center.

For the AT+BAND command, it depends on the country you live in because LoRaWAN uses different frequency bands for different countries.

Here is an overview:

Band Region Name Region
0 EU433 Europe
1 CN470 China
2 RU864 Russia
3 IN865 India
4 EU868 Europe
5 US915 North America
6 AU915 Australia
7 KR920 South Korea
8 AS923-1 Asia
9 AS923-2 Asia
10 AS923-3 Asia
11 AS923-4 Israel

And then, the frequency for the packet transfer needs to be set up. For this, a custom AT command is defined in the code.

ATC+SENDFREQ

This AT command expects the time interval in seconds between two data packets. The time is stored in the device's flash memory, and it is only necessary to set the time once. To save battery life, the frequency should not be too frequent. Every two minutes is a good time interval.

ATC+SENDFREQ=120
OK

Now, the VOC sensor will send its data every 2 minutes.

Once we've configured the device and registered it in the Helium Console, it can join the network and begin sending sensor data. You will see in the Helium Console the incoming data packets.

KHM-013-011.png

Once this is achieved the data flow in the Helium Console needs to be setup.

Set Up Helium Data Flow

We need an encoder for the incoming data. To make things easier, a matching decoder is available in the same GitHub repository as the source codes. The [Helium-Ext-LPP-Decoder.js] (https://github.com/beegee-tokyo/RUI3-RAK12047-Air-Quality/tree/main/decoders) can be found in the decoders folder.

You can use this decoder in the Helium Console by creating a new Function. Go to the Functions tab and click New Function.

KHM-013-012.png

In Step 1, give the function a name. For this case, Ext-Lpp-Decoder. Select the function Decoder, and then the type is Custom Script. After that, the window will extend and you will see an example decoder function.

In Step 2, overwrite this example with the javascript from Helium-Ext-LPP-Decoder.js.

KHM-013-013.png

To send the data from the Helium Console to Datacake, we need to create an Integration. Go to the Integrations tab, select the add New Integration icon, and then click Datacake Integration.

KHM-013-014.png

In the next window click on Add Integration.

KHM-013-015.png

  • Enter the Datacake Token (Datacake URL), and give the integration a name.

KHM-013-016.png

That’s all on the Helium Console. The next steps are on the Datacake Console.

Set Up Datacake

  • If you do not yet have a Datacake account, you can create one for free at Datacake to visualize a limited number of sensor nodes.

  • In the Datacake Console, go to Devices and click on + Add Device.

KHM-013-017.png

  • Choose LoRaWAN from the opening window and click Next.

KHM-013-018.png

  • In the next window, choose New Product. Give it a product name, and click Next.

KHM-013-019.png

  • Then, select Helium Network and click Next.

KHM-013-020.png

  • In the DEVEUI field, enter the device EUI and give the device a NAME. Then click Next.

KHM-013-021.png

  • If this is your first Datacake device, you can select the Free plan and then click Create.

KHM-013-022.png

  • Now that you have created the device, open it from the Devices tab.

KHM-013-023.png

  • At first, there will be an empty dashboard because we need to configure the device. To proceed, click Configuration.

KHM-013-024.png

  • In the Configuration tab, scroll down until you see the Payload Decoder. Overwrite the example decoder with the content of Datacake-Ext-LPP-Decoder.js from the decoders folder.

KHM-013-025.png

  • Scroll further down until you see the section Fields. Use the + Add Field button to add the following data fields:
Name Identifier Type
Gas resistance RAK1906 ANALOG_IN_9 Float
Barometric Pressure RAK1906 BAROMETER_8 Float
Humidity RAK1906 HUMIDITY_6 Float
Temperature RAK1906 TEMPERATURE_7 Float
VOC RAK12047 VOC_16 Integer
Battery VOLTAGE_1 Float

KHM-013-026.png

Don’t forget to push the Save button after updating each configuration section.

  • Open the Debug tab and check if the data from the sensor is arriving and being decoded correctly.

KHM-013-027.png

  • To visualize the incoming data, open the Dashboard and click the edit icon on the right side. The setup of the visualization widgets is very simple, so only the setup of the first widget is shown.

KHM-013-028.png

  • After clicking Add Widget, select Chart in the opening window.

KHM-013-029.png

  • In the Basic tab, give the widget a name, and in the Data tab, choose the field to display.

KHM-013-030.png

  • In the Axes tab, you can specify where the axis data should be displayed, and in the Timeframe tab, you can specify the time range for the data to be displayed.

KHM-013-031.png

  • To complete the first widget, click the Save button. I created a few of these widgets to display the various data from the WisBlock VOC sensor node.

KHM-013-032.png

  • Push the edit icon on the right side to save your dashboard.

  • To receive notifications if the VOC index is showing bad air around the sensor, we use the Rules function of Datacake. Click Rules to view the defined rules, then click Add Rule.

KHM-013-033.png

  • Click Please Choose, and select your device. Then, click Field, and select VOC RAK12047.

KHM-013-034.png

  • Change the criteria to larger than or equal to. Choose the value you want the warning to be sent out at and set the hysteresis.
  • The warning can be sent via email, SMS, or by initiating a downlink. For this case, email was chosen. In the email text, you can use placeholders to add the measured value of the VOC sensor.

KHM-013-035.png

Now, everything is ready, and you will be informed if it is time to open the windows and get some fresh air. Below is a sample email I received to do so.

KHM-013-036.png

bernd-giesecke.png

Bernd Giesecke

Electronics Engineer, 23 years of experience in industrial and automotive HW and SW R&D. Supporting Arduino open-source community since 2014.

Updated