- Ensure you have mpremote installed (
pipx install mpremote) - Copy
example-config.pytoconfig.py - Edit
config.pyto set your WIFI and PurpleAir details - Install Micropython 1.26+ on the Kano PixelKit
- Copy files to the device with mpremote, reset device, enjoy!
This command will copy all files, then reset the device and leave the serial connection attached. To leave the connection, press ctl-x.
mpremote cp -r boot.py config.py main.py lib : + reset repl
- Install VCP driver from https://ftdichip.com/drivers/vcp-drivers/
- After reboot, it should appear as
/dev/tty.usbserial-*or similar
- Install esptool (
pipx install esptool) - Download from and follow instructions on https://micropython.org/download/ESP32_GENERIC/
More information at https://docs.micropython.org/en/latest/esp32/tutorial/intro.html
Example:
esptool erase-flash
esptool write-flash 0x1000 ~/Downloads/ESP32_GENERIC-20250911-v1.26.1.binUses the pixelfonts package from https://github.com/benders/micropython-pixelfonts
Library can be updated with:
micropython -m mip install github:benders/micropython-pixelfonts/package-mpy-v6.json --target libThe project uses pytest for unit testing. Tests are located in the tests/ directory.
-
Install development dependencies:
python -m venv .venv ./venv/bin/pip install -r requirements-dev.txt
-
Make sure you are in the project root directory.
pytestTo run tests for a specific module:
pytest tests/test_utils.py
pytest tests/test_purpleair.pyTo run a specific test case:
pytest tests/test_utils.py::TestFormatTime
pytest tests/test_purpleair.py::TestUrlEncodeTo run a specific test method:
pytest tests/test_utils.py::TestFormatTime::test_format_time_8_tupleTo run tests with coverage report:
pytest --cov=libtests/test_utils.py: Tests for utility functions in theutils.pymodule.tests/test_purpleair.py: Tests for PurpleAir API interaction and AQI calculations in thepurpleair.pymodule.
Test cases are organized by function or logical group of functions within each test file.
The application is designed to be resilient against various types of errors:
- API Errors: When the PurpleAir API returns error status codes, the application will log the error, display a blank screen, and retry after a shorter timeout.
- Network Connectivity: If network connectivity issues occur, the application catches the errors, logs them, and continues operation without crashing.
- JSON Parsing Errors: If response data cannot be parsed, the application handles the error gracefully.
- The main loop is designed to never exit due to errors.
- If sensor data cannot be retrieved, the display shows a blank screen instead of invalid data.
- The system automatically retries failed operations after a short delay.
- All error states are logged to the console for debugging.
The test suite includes comprehensive tests for error conditions:
- API error responses
- Network connectivity issues
- Data parsing problems
Run the error handling tests with:
pytest tests/test_purpleair.py::TestFetchSensorData::test_fetch_sensor_data_api_error
pytest tests/test_purpleair.py::TestFetchSensorData::test_fetch_sensor_data_network_error
pytest tests/test_purpleair.py::TestFetchSensorData::test_fetch_sensor_data_value_error