Skip to content

gdex1974/AirSensorExternalESP32

Repository files navigation

Air Quality Sensor - external unit

Description

The Air Quality Sensor project contains two parts:

  • Internal unit - the main unit placed inside the building
  • External unit - the unit placed outside the building This repository contains the hardware and software definitions for the external unit. In the current state it's based on ESP32C3 module from DFRobot and communicate with the internal unit by ESP-NOW protocol. The temperature, humdity and pressure are measured each minute. The PMx values are measured each hour.

Hardware

Alternalively, the ESP32-based compact boards like Lolin32-Lite could be used, the possible parts and schematics are described here

Software

Setup

The microcontroller, switch, step-up converter and BME-280 sensor are placed on the prototype board. It has to be cut to fit the size of the external cover. The SPS30 sensor and micro-USB socket module are placed aside and connected to the main board by the wires. The frame and cover parts are 3D printed.

Connection schema:

Beetle C3 based schema

Lolin32-lite based schema

Firmware

The firmware is based on ESP-IDF framework (tested version is 4.4.6) and is written in C++17 language. The main task is to read the data from sensors and send them to the internal unit via Esp-Now protocol. The firmware is divided into several modules:

  • components - contains the code of the external unit
    • general-support library - contains the code for general support functions, obtained from this repository.
    • SimpleDrivers - contains the code for the SPS30 and BME280 drivers, obtained from this repository.
  • main - contains the main code of the external unit's firmware
    • AppConfig - contains the code for the application's configuration
    • AppMain - contains the app_main() function and hosts the controller object.
    • EspNowTransport - contains the code for the communication with the main unit based on Esp-Now protocol
    • DustMonitorController - contains the code for the controller class handling the main logic of the firmware
    • PTHProvider - contains the code for the class providing the data from BME280 sensor
    • SPS30DataProvider - contains the code for the class providing the data from SPS30 sensor
  • CMakeLists.txt - main CMake file for the firmware
  • sdkconfig - default configuration file for the ESP-IDF framework.

Build

The main CMakeLists.txt file could be opened directly in IDE. To build manually, do the following steps:

mkdir build
cd build
cmake -DIDF_TARGET=esp32c3 -G Ninja  ..
cd ..
idf.py build