Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLID and automated test examples for AirGradient #1

Merged
merged 104 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
a734b7c
Updated references.
EricLauber Sep 22, 2023
a981b62
Copying a bunch of stuff in that doesn't work yet.
EricLauber Sep 23, 2023
385ebed
Warnings everywhere, but it compiled.
EricLauber Sep 23, 2023
45ea1a4
Has warnings but builds
EricLauber Sep 23, 2023
7d8b00b
Fighting with strings and chars.
EricLauber Sep 23, 2023
1a251f3
Minor readability changes.
EricLauber Sep 23, 2023
efaab75
Trying to pull string variables out, weird compilation issues.
EricLauber Sep 24, 2023
1edcc10
Errors with order of includes. Putting the my header at the end of th…
EricLauber Sep 24, 2023
271b611
Making progress on the strings.
EricLauber Sep 24, 2023
d13072a
It works! Needs more work but at least is functional.
EricLauber Sep 25, 2023
6ddc0fd
New class for air quality sample.
EricLauber Sep 26, 2023
d91c0c8
Breaking out mqtt config.
EricLauber Sep 26, 2023
4d91415
Moving interval data to dedicated class.
EricLauber Sep 26, 2023
d35230e
Comments
EricLauber Sep 27, 2023
40687bc
Several experimental changes to improve reuse within the main program.
EricLauber Sep 30, 2023
584924d
Got some test files using DI properly. Sample wrapper around an exter…
EricLauber Oct 3, 2023
3a43a4e
Folder restructuring to help with organization.
EricLauber Oct 5, 2023
dd9e4aa
It compiles, end of day.
EricLauber Oct 5, 2023
0c26ee8
Taking a first pass at some unit test files.
EricLauber Oct 6, 2023
25e9552
I want to add EpoxyDuino, but not have its source included in this pr…
EricLauber Oct 6, 2023
1b12583
One test ran.
EricLauber Oct 7, 2023
9f231ad
This structure compiles in Arduino IDE and tests run.
EricLauber Oct 7, 2023
8d748e3
Providing instructions on how others can test.
EricLauber Oct 7, 2023
4b71d33
Running into issues getting tests to reference the source.
EricLauber Oct 7, 2023
7ff64ac
May have figured out the makefile syntax to find the source locally.
EricLauber Oct 8, 2023
16681ae
Cleaner readme
EricLauber Oct 8, 2023
f8fcc67
AQI calc fix.
EricLauber Oct 9, 2023
caca908
Combined sample-related classes with a single header.
EricLauber Oct 9, 2023
3569f57
Created namespace for related classes.
EricLauber Oct 9, 2023
92c53a1
Display namespace and associate tests. Some renames.
EricLauber Oct 9, 2023
c74452a
More reorg and namespace work.
EricLauber Oct 9, 2023
d401872
Need to make state value public to test against it.
EricLauber Oct 9, 2023
06f982e
major state transition tests
EricLauber Oct 10, 2023
cf4e7e4
Moving toward enabling DI of the Button.
EricLauber Oct 11, 2023
629c307
IButton implementation.
EricLauber Oct 11, 2023
1f53ac3
mockbutton
EricLauber Oct 11, 2023
b2f783b
Merge branch 'add-diy4_2-sensors-and-capabilities' of https://github.…
EricLauber Oct 11, 2023
b4b05ec
Folder restructure and starting button tests.
EricLauber Oct 11, 2023
4470769
Going down a path to try and integration-test the Button functionalit…
EricLauber Oct 11, 2023
4d8cba5
State machine loop now skips the initial state.
EricLauber Oct 12, 2023
cf86cd7
Machine now owns changing its state. States have Enter and Exit funct…
EricLauber Oct 12, 2023
6fcd62c
Working to let a state call machine to write to display.
EricLauber Oct 13, 2023
649667f
Found the bug! nullptr.
EricLauber Oct 13, 2023
0509750
Beginning to build out the EEPROM access.
EricLauber Oct 13, 2023
6f97079
More file system access work.
EricLauber Oct 14, 2023
bf168e3
Implemented logic to store child class of MachineBase as an enum with…
EricLauber Oct 14, 2023
2a3e793
Different implementations depending upon compiler config.
EricLauber Oct 15, 2023
41f5bcf
Added details about RTTI
EricLauber Oct 16, 2023
0b53f13
Added some basic mkdocs
EricLauber Oct 16, 2023
1aff83c
Attempting a github action that publishes mkdocs
EricLauber Oct 16, 2023
0fe31ca
Wrong branch.
EricLauber Oct 16, 2023
d0401b7
Get the yml right
EricLauber Oct 16, 2023
085d574
Typo in my own name.
EricLauber Oct 16, 2023
f5701b6
It would help if I pointed to the right repo for the docker container.
EricLauber Oct 16, 2023
2536134
Testing updating the docs with the GitHub action.
EricLauber Oct 16, 2023
0b82d66
temporary flag cleanup
EricLauber Oct 17, 2023
5bb0834
Test of setting the milliseconds works once and then doesn't again la…
EricLauber Oct 17, 2023
78e9352
Button tests pass. Getting eeprom objects built.
EricLauber Oct 18, 2023
726d53f
Continuing to experiment with config classes.
EricLauber Oct 18, 2023
985e79d
Removed some interfaces that didn't make sense.
EricLauber Oct 19, 2023
1fd141f
Read and write DisplayConfigurations.
EricLauber Oct 19, 2023
2268584
DisplayConfig states.
EricLauber Oct 19, 2023
0287bc7
Can save a config selection.
EricLauber Oct 19, 2023
10b6d2d
More coverage.
EricLauber Oct 20, 2023
5fd4db0
Break COnfig work to two files to ease the maint.
EricLauber Oct 21, 2023
113de95
Docs updates.
EricLauber Oct 21, 2023
11f3e56
New idea...
EricLauber Oct 21, 2023
c2e0be7
Integrated the switchboard header.
EricLauber Oct 22, 2023
0410e9f
MockSystem.
EricLauber Oct 22, 2023
717dc18
Call the restart.
EricLauber Oct 22, 2023
8418482
added a todo
EricLauber Oct 22, 2023
baf5717
Improved MockSystem to check call.
EricLauber Oct 23, 2023
05fd961
Clear saved data.
EricLauber Oct 23, 2023
6eca9c1
Moving these files, but getting errors.
EricLauber Oct 28, 2023
658c230
Mocks moved to dedicated test Mocks folder.
EricLauber Oct 28, 2023
0fb8522
Misc semicolon
EricLauber Oct 28, 2023
8f8868b
Starting class to include device's main logic.
EricLauber Oct 29, 2023
4a6f4d4
stubbed in functions
EricLauber Oct 29, 2023
4f308cd
Figuring out which namespace and class names are not permitted and st…
EricLauber Oct 31, 2023
77868e6
Getting around some compiler issues.
EricLauber Nov 1, 2023
f740784
it builds in the arduino ide again!
EricLauber Nov 1, 2023
caec9e6
Trying to change a bunch of names, but broke some tests along the way.
EricLauber Nov 2, 2023
f853351
Unneccesary header.
EricLauber Nov 3, 2023
ed3bef1
Getting some namespaces and folders I like.
EricLauber Nov 3, 2023
772401b
Moving Button within the IO namespace.
EricLauber Nov 3, 2023
610d422
enable mermaid integration for docs
EricLauber Nov 22, 2023
acf008f
Many doc-updates.
EricLauber Nov 23, 2023
ad813ec
Typo in the readme img src
EricLauber Nov 23, 2023
f2d23ac
More doc-related things.
EricLauber Nov 24, 2023
38dcc02
Added first pass at goals, fixed D1Mini include bug
EricLauber Nov 25, 2023
edb0c32
Move some things around.
EricLauber Nov 25, 2023
e6316b0
Interface and class wrapper for SHTSensor.
EricLauber Nov 25, 2023
7e76531
whitespace adjustment
EricLauber Nov 26, 2023
3caab81
MockHTSensor
EricLauber Nov 26, 2023
6123dec
Adding wrapper for sgp41, getting weird deleted function error.
EricLauber Nov 26, 2023
8196869
GasIndex seems to build properly.
EricLauber Nov 26, 2023
8f51725
Making progress...
EricLauber Nov 26, 2023
42433e5
CO2 Sensor.
EricLauber Nov 27, 2023
436d6f3
Changing a lot of folders and namespaces.
EricLauber Nov 27, 2023
ef37f6a
Adding new sensors to AirGradient class.
EricLauber Dec 1, 2023
5f4a60a
Starting on a particulate matter sensor.
EricLauber Dec 1, 2023
7291d43
PMSensor class builds.
EricLauber Dec 5, 2023
758449f
Initial work to cleanup repo.
EricLauber Aug 13, 2024
12f3f04
Preparing for repo name change.
EricLauber Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish docs to GitHub Pages
on:
push:
branches:
- main

jobs:
build:
name: Deploy docs
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v1

- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# todo! need to get or clone all referenced libraries

# name: Run AUnit tests with EpoxyDuino
# on:
# pull_request:
# branches:
# - main

# jobs:
# build:

# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v3

# - name: Setup environment
# run: |
# cd ..
# git clone https://github.com/bxparks/EpoxyDuino

# - name: Run Tests
# run: |
# make -C tests
# make -C tests runtests
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Environment Files
*.env

# Root directory of EpoxyFS
epoxyfsdata
epoxyeepromdata
4 changes: 4 additions & 0 deletions .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"configuration": "xtal=80,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=3232,non32xfer=fast,eesz=4M2M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=921600",
"board": "esp8266:esp8266:d1_mini"
}
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
all:
$(MAKE) -C tests

runtests:
$(MAKE) -C tests runtests

clean:
$(MAKE) -C tests clean
82 changes: 11 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,17 @@
# AirGradient MQTT
# AirGradient for Arduino with Automated Tests

Simple script that reads AirGradient air quality sensors and publishes data to an MQTT server.
<img src="./docs/assets/images/airgradient.png" align="right" width="200">

I use it along with my DIY AirGradient boards. Information on how to get the components and build the boards is available [here](https://www.airgradient.com/open-airgradient/instructions/diy/)
This is an Arduino software implementation for the AirGradient DIY Air Quality Sensor Pro, PCB version 4.2. I have paused development for this project.

This script allows you to host your own solution instead of connecting the DIY Sensor to the AirGradient Dashboard. That's a very convenient option if you don't want to host yourself, you can find all the information you need [here](https://www.airgradient.com/open-airgradient/instructions/diy-connect-to-dashboard/)
I created this fork of [AirGradient's Arduino code](https://github.com/airgradienthq/arduino) prior to their implementation of MQTT and local web server support. My intention was to add that functionality while also bringing in other software development best practices such as automated testing and Continuous Integration and patterns like SOLID. [Click here for detailed documentation about the implementation](https://ericlauber.github.io/airgradient_with_tests/).

Instead of running an HTTP server and polling from Prometheus as in Jeff Geerling’s solution, I like better the approach of the boards reporting the values to the MQTT server. This code is based on the solution that Jeff describes in [his blog](https://www.jeffgeerling.com/blog/2021/airgradient-diy-air-quality-monitor-co2-pm25)
Please feel free to use this project as an example of applying modern software development best practices to Arduino projects.

I'm not using the OLED display to show the values, but you can find the relevant code in the blog post above.
## Getting Started and uploading this sketch

## Configuration

Update the `arduino_config.h` file with your details. I use one config file per device.

- `SECRET_SSID`: WiFi ssid
- `SECRET_PASS`: WiFi password
- `MQTT_SERVER_ADDRESS`: The MQTT server address, you can use `test.mosquitto.org` if you're not running your own MQTT server yet. I use a dockerized Mosquitto MQTT server https://mosquitto.org/
- `IP_LAST_CHUNK`:
- `MQTT_TOPIC`: The MQTT topic that the values will be published to. I define one topic per device.
- `DEVICE_ID`: A friendly name for your device
- `TEMP_DEVIATION`: The temperature deviation from the sensor to the room. I use 2.5 degrees in my setup. I guess the deviation comes from the heat generated by the board.
- `HUM_DEVIATION`: Same idea as `TEMP_DEVIATION`. I use 2% in my setup.

## Home Assistant

I use Home Assistant to track and display the sensor status. Define the sensors in your `configuration.yaml` as follows:

```yaml
# Air Gradient sensors
mqtt:
sensor:
- name: 'Temperature office'
state_topic: 'esp/dht/office'
unit_of_measurement: '..C'
value_template: '{{ value_json.atmp | round(1) }}'

- name: 'Humidity office'
state_topic: 'esp/dht/office'
unit_of_measurement: '%'
value_template: '{{ value_json.rhum }}'

- name: 'CO2 office'
state_topic: 'esp/dht/office'
unit_of_measurement: 'ppm'
value_template: '{{ value_json.rco2 }}'

- name: 'PM2 office'
state_topic: 'esp/dht/office'
unit_of_measurement: 'ppm'
value_template: '{{ value_json.pm02 }}'
```

## License

MIT License

Copyright (c) 2022 @nsbk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1. Download and Install the [Arduino IDE](https://www.arduino.cc/en/software), [Arduino CLI](https://arduino.github.io/arduino-cli/0.19/installation/), or [VS Code](https://code.visualstudio.com/) with the [Arduino extension](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino) to your system.
1. Clone this repo or download the latest release (a zip of the source code).
1. Open `airgradient_mqtt.ino` with your chosen Arduino tools.
1. Install all required Arduino reference libraries.
1. Plug in the microcontroller for your AirGradient (such as an ESP8266 Wemos LOLIN D1 mini) and upload the sketch to the controller.
Loading