Skip to content

A simple MicroPython application written for an ESP32 microcontroller, used for reading air quality values from a Plantower PMS5003 sensor and publishing them to an MQTT topic.

License

VirtualWolf/esp32-air-quality-reader-mqtt

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

esp32-air-quality-sensor-mqtt

This is a version of my esp32-air-quality-reader that reads from a Plantower PMS5003 air quality sensor and publishes the results to an MQTT topic. It uses Peter Hinch's mqtt_as MicroPython library for MQTT functionality.

It reads the sensor every three minutes, warming it up for 30 seconds beforehand.

Setup

Create a file called config.json at the root of the src directory with the following contents:

{
    "client_id": "<MQTT client ID for the ESP32",
    "server": "<address of MQTT broker>",
    "port": 1883,
    "topic": "<MQTT topic to publish to>",
    "ssid": "<wifi network name>",
    "wifi_pw": "<wifi network password>"
}

You can optionally add the following to override the default library values of true for clean and clean_init:

    "clean": false,
    "clean_init": false,

Message content

Messages are published as stringified JSON in the following format:

{
    "pm_1_0": 0,
    "pm_2_5": 0,
    "pm_10": 0,
    "particles_0_3um": 0,
    "particles_0_5um": 0,
    "particles_1_0um": 0,
    "particles_2_5um": 0,
    "particles_5_0um": 0,
    "particles_10um": 0
}

On an Adafruit HUZZAH32, the red LED on the board will light up when it has connectivity to the MQTT broker and will go out when the connectivity stops.

About

A simple MicroPython application written for an ESP32 microcontroller, used for reading air quality values from a Plantower PMS5003 sensor and publishing them to an MQTT topic.

Topics

Resources

License

Stars

Watchers

Forks

Languages