SensorApp

Introduction

SensorApp is an IoT device application which is used to send messages back and forth (over MQTT protocol) to corresponding mobile App. The mobile side App may read sensor data from device or send command to it. The real device show is as the following image:

Some short demo videos are listed at https://github.com/sushenghua/IoT_ESP32_SensorDoc/blob/master/Demo, more information about the device can be found here. And the mobile apps are iOS App and Android App

Program features

As the SensorApp device contains an ESP32 chip (integrated in the ESP32-WROOM-32D module) as its MCU, this SensorApp IoT application is mainly build on framework eps-idf by Espressif Systems. To make the underlayer C interface easier to use, the application provides some components that wrap the eps-idf C interface into corresponding C++ classes. Besides the official esp-idf framework, this application also uses some other great libraries like Mongoose Networking, ILI9341 LCD Driver, QRCode and et al. The following lists the features in this application:

  • SPI: Wraps esp-idf C spi

  • I2C: Wraps eps-idf C i2c

  • UART: Wraps eps-idf C uart

  • Wifi: Wrap eps-idf C wifi

  • MQTT Client: Implemented with the mongoose lib

  • HTTP Server: Implemented with the mongoose lib

  • Command Engine: Interpretes remote command bytes or strings and executes it accordingly

  • App Updater: Wraps the esp-idf OTA mechanism, data transmitted over MQTT channel

  • Display Controller: Management of LCD device control and screen content display

  • Power Manager: Device battery power management with TI BQ24295 chip

  • Pripheral Sensor Interface: CO2 (over Uart), PM (over Uart), SHT3xSensor (over I2c), TSL2561 (over I2c), MPU6050 (over I2c)

  • Application System: Combines all stuff together and launches different tasks accordingly

Hardware

Board, Chips, Sensors, Programmer

The SensorApp main board chooses ESP32 chip (in ESP32-WROOM-32D module) as its MCU which ingrates Wifi and Bluetooth/BLE providing greate and rich functionalities. Based on that, this board integrates battery management chip TI BQ24295, DC-DC converter TI TPS62130, Montion tracking InvenSense MPU6050, Load switch Micrel MIC9409X, ESD protection TI TPD4E1U06

The extended FPC contains Humidity and Temperature Sensor SENSIRION SHT3x, Light to digital converter TAOS TSL2561

The separated off-board sensors used in this application are Air pollution particles sensor Plantower PM and Carbon dioxide gas sensor Plantower CO2

The programmer board is merely the CP2102 related parts from Espressif's official ESP32-DevKitC development board

The following images show the board, chips, sensors and the programmer

Schematic and BOM

The schematic of board can be found in the following list:

For the BOM list:

Build and Run

To build this project, latest esp-idf is required to setup properly, just by following the step-by-step instructions. An ESP32-DevKitC board or similar compitable development boards can be used to deploy the firmware of this project(switch to branch 'esp32_devkit_board'). As these boards don't have the peripheral chips as this SensorApp board has, some related tasks in file System.cpp had been commented out. Also, a MQTT broker is required to depoly on a server, Mosquitto is used in this project. To make the OTA update enabled, a MQTT subscriber service is needed to response the Device App (SensorApp) or the mobile App.

build and flash the firmware

git clone git@github.com:sushenghua/IoT_ESP32_SensorApp.git
cd IoT_ESP32_SensorApp
idf.py set-target esp32
idf.py menuconfig
idf.py build
idf.py flash monitor

The following images show the different screens of a running device

MQTT broker

In this project, Mosquitto is used as the MQTT broker, just follow Steve's Internet Guide to setup the configuration. This site also provides instructions about how to apply user password in mosquitto and Certificates in mosquitto. A handy script to generate CA files can be found at here. For more learning resource about MQTT, please visit HiveMQ

OTA service over MQTT

Another python project IoT_Firmware_MQTT_Updater implemented the OTA over MQTT. It's simply a MQTT subscriber/publisher based service, as it will setup an unique communication channel between the device and this service node to transmit data upon the OTA request.