Skip to main content
shopping_basket Basket 0
Log in

The Interactive Air Quality Map Part 2: Making a Mobile ESDK Air Quality logger

A big part of the air quality map is the live data it needs to operate, in this article I'll walk you through how I've converted my ESDK to a mobile air quality data logger, it should also be interesting to collect some real-time data.

Hardware and Connections

Unfortunately, I did not receive a GPS antenna with my sensor kit, so I could not use the GPS position function conveniently built-in with the sensor kit, luckily my plan isn't dependent on having it, as I already purchased a GSM/GPRS/GPS module to interface with the kit, I figured if I was going to be collecting live mobile sensor data, mobile internet would be essential, so, I got the A9G module with GPRS and GPS functions.

A9G module with GPRS and GPS functions

The A9G module is controlled via predefined commands called AT commands sent over serial, GPS data from the module can also be read on this serial connection. I took apart my ESDK and broke out the required serial lines, as well as 5v and GND.

ESDK Main board - Screen side

ESDK Main board - PCB Side

My plan was to have a separate python script running on the pi, reading the GPS data from the module and appending it to the air quality data read from the sensor kit. Implementation was not so straight forward though; for one, I found out I could not communicate with the A9G module directly from the Raspberry Pi's serial pins due to timing and synchronization issues, so the only way I could communicate with the module from a raspberry pi was to use a USB to serial adapter (FTDI) which I, unfortunately, did not have on hand. I wasn't going to let that stall me tough, so I reprogrammed one of my Arduinos as a serial relay, I could then connect the Arduino to the Raspberry Pi, which then relays serial data to and from the A9G module, similar to a regular USB to serial device, but done via software. You’ll see my connections below, and the code will also be attached to this article.

Circuit Schematic

A9G Board and Arduino housed in 3D Printed Enclosure

For the ESDK to be mobile, I need a way to power it on the move; for this, I got a pretty beefy 27000mAh power bank, I then modelled and printed a few parts to help attach the power bank to the kit.

Finished Mobile ESDK Air Quality Logger - Front View

Finished Mobile ESDK Air Quality Logger - Rear View

Software

The python script running on the pi has a simple task, it reads the sensor data via mqtt from the ESDK, it also reads the GPS data from the A9G module and then concatenates the information into a single string, which is then written into a csv file, I have also programmed the script to create a .kml file from the GPS data and the sensor data, this way I get a normal excel sheet as well as a file (.kml) which I can load directly into google earth to properly visualize the live data from the kit.

The code has four main sections:

The first is the mqtt setup, this allows the script to connect to the kit’s mqtt broker to get the actual sensor readings.

The second section is the serial communication setup section. Here I simply setup the raspberry pi to communicate with the Arduino that I'm using as the makeshift USB - serial adapter, it’ll work just the same if I use a proper FTDI module.

The third main section of the code sends some basic AT commands to the GPS board so we can get it to start reporting its GPS data over serial.

The main code loop is where all the cool stuff happens, the first thing I do is check if there is usable data to process, hence all the if statements.

If there is valid air quality data from the kit as well as valid GPS data from the A9G board, the next three lines joins the air quality data and the GPS data into a single string, which is then written into the .csv log for that day, the line “datalogfile = open(strftime('%d-%m-%Y') + "_airqlog.csv", "a")” ensures that only one csv is created per day, so the script will not generate a new file whenever the kit is restarted in the same day.

After writing to the csv file the script proceeds to write to the .kml file, kml files require latitude, longitude and altitude to generate a valid point on a map, so I have a few lines of code that’ll extract the longitude, latitude and altitude from the NMEA data format reported by the A9G board.

The kml file is a very specific type of file so I am doing some convoluted string formatting to get the file just right for google earth to read properly, I’ll recommend reading more about kml files here to better understand the file format and syntax, my full code is also attached to this article for your reference.

I want to also point out that the ESDK is designed for indoor air quality measurements, and for that, the combination of sensors currently featured on the kit is perfect, however, in an outdoor environment: CO2, VOC, Temperature, Humidity and Particulates are not quite enough to tell the whole story, Carbon monoxide (CO) and Nitrogen dioxide (NO2) would be more telling in an outdoor air quality logger, so I'll probably find a way to implement those sensors soon.

All the CAD and Code I used in this article will be attached below, so feel free to reference them as needed.

For more information on this project, Part 1 of this series, discusses making the cells for the Air Quality Map. 

Downloads

I am a passionate Hardware Engineer, with interests in Embedded systems and Robotics. I enjoy learning new skills and challenging myself with finding creative technological solutions.
DesignSpark Electrical Logolinkedin