Compare commits
197 Commits
feat/corre
...
feat/energ
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba250787e6 | ||
|
|
23f8c383fd | ||
|
|
c0ad1dbfad | ||
|
|
75be7d9fc5 | ||
|
|
309d322100 | ||
|
|
89ebe6c39f | ||
|
|
29db5469f5 | ||
|
|
5802cf17f6 | ||
|
|
4a4ce89f00 | ||
|
|
8985e08a00 | ||
|
|
e984aced18 | ||
|
|
73edf56c97 | ||
|
|
e54c62a2ef | ||
|
|
5c95f011e4 | ||
|
|
bed448e7d6 | ||
|
|
eb8378adfa | ||
|
|
f94ed5c5f5 | ||
|
|
9471f3e323 | ||
|
|
e6d90372c2 | ||
|
|
fabf0550fc | ||
|
|
ce0af5bf60 | ||
|
|
93bdbd85d5 | ||
|
|
29f583f20d | ||
|
|
0f6a2fe908 | ||
|
|
e3ce2c41be | ||
|
|
92b3c69b98 | ||
|
|
f4d518aa87 | ||
|
|
831c844c24 | ||
|
|
060a7f6815 | ||
|
|
d8eb6b3c1a | ||
|
|
77859bea22 | ||
|
|
969858b5cb | ||
|
|
09b5805686 | ||
|
|
b09b753339 | ||
|
|
ddb3dba131 | ||
|
|
e780b0ace6 | ||
|
|
e82da5401e | ||
|
|
50a98acde4 | ||
|
|
7049d21a41 | ||
|
|
d5cdeaa9f3 | ||
|
|
09207c6923 | ||
|
|
0a64424196 | ||
|
|
5b38ca222b | ||
|
|
9ee35341a5 | ||
|
|
cec0514444 | ||
|
|
21b9ddb2ed | ||
|
|
1ee05da5d1 | ||
|
|
626a2240fa | ||
|
|
174ec6568f | ||
|
|
6b55719399 | ||
|
|
e2084f0738 | ||
|
|
5e07923690 | ||
|
|
04049439b1 | ||
|
|
c148d256d7 | ||
|
|
02849a1938 | ||
|
|
074337a96d | ||
|
|
4daa817a0b | ||
|
|
81a4502952 | ||
|
|
764e2eae38 | ||
|
|
79bf9811be | ||
|
|
9475724d0c | ||
|
|
e7603a7659 | ||
|
|
9bba89722e | ||
|
|
81945a358e | ||
|
|
3d26a54d69 | ||
|
|
b70ee75d50 | ||
|
|
c6846c818a | ||
|
|
0b1c901a76 | ||
|
|
83504c8628 | ||
|
|
4487992748 | ||
|
|
3c8a65a329 | ||
|
|
673d564ddb | ||
|
|
423eb4808f | ||
|
|
18a710ffc2 | ||
|
|
040cb79a4d | ||
|
|
52d3dc03f1 | ||
|
|
1c6bc3ec55 | ||
|
|
34d7c93e14 | ||
|
|
fee1dc25d6 | ||
|
|
9fb01d42f4 | ||
|
|
7bb013939c | ||
|
|
0da21155e7 | ||
|
|
7a153cc0ea | ||
|
|
b079c35e6b | ||
|
|
6051e183b8 | ||
|
|
c95379b957 | ||
|
|
0cae8bc185 | ||
|
|
5902a4c8e4 | ||
|
|
66818cd075 | ||
|
|
c1a6ddc68f | ||
|
|
20a32dd22c | ||
|
|
263dc9934e | ||
|
|
61b863b7f1 | ||
|
|
e01c1029fe | ||
|
|
ba5d817739 | ||
|
|
a91747e379 | ||
|
|
029457c3fa | ||
|
|
55710dd4d9 | ||
|
|
4886163cda | ||
|
|
7c57477238 | ||
|
|
9ed58d1853 | ||
|
|
6c52b038e9 | ||
|
|
2f69932ef7 | ||
|
|
1d96a274a6 | ||
|
|
df9f6dfc95 | ||
|
|
3fc02b3f54 | ||
|
|
958ed0bd80 | ||
|
|
e9be9dcc83 | ||
|
|
7fbab82088 | ||
|
|
decdecdf22 | ||
|
|
145c612867 | ||
|
|
37de127887 | ||
|
|
baf80ce250 | ||
|
|
80100e2475 | ||
|
|
d9c3fc6ec4 | ||
|
|
67d377a514 | ||
|
|
fff982f35f | ||
|
|
86cd90b94a | ||
|
|
656509c74d | ||
|
|
01f83cb02e | ||
|
|
5c9c25c6b5 | ||
|
|
9291598209 | ||
|
|
429adb5e5e | ||
|
|
4e651afc8c | ||
|
|
859abbe177 | ||
|
|
f079bb30d2 | ||
|
|
070a103234 | ||
|
|
ef87cde9d6 | ||
|
|
ea5e23b307 | ||
|
|
c2a26e78a0 | ||
|
|
0297059e91 | ||
|
|
30622fca99 | ||
|
|
7c2aa35e4f | ||
|
|
e93009f31c | ||
|
|
26db6372cd | ||
|
|
d94ebbc570 | ||
|
|
299234ac40 | ||
|
|
76b2b3f940 | ||
|
|
bf09b746c7 | ||
|
|
b5c67cb0b1 | ||
|
|
5f40a327b3 | ||
|
|
66b0c63de5 | ||
|
|
cc3228f49a | ||
|
|
8728589ca1 | ||
|
|
4b356920c2 | ||
|
|
c94b886360 | ||
|
|
e056e44917 | ||
|
|
3b00fa69b8 | ||
|
|
e0720ac580 | ||
|
|
0861c2dcaa | ||
|
|
59fc0c409b | ||
|
|
6d63fdf643 | ||
|
|
033358e2c2 | ||
|
|
47034f62b4 | ||
|
|
71a21ce7e6 | ||
|
|
3f5e5eebbb | ||
|
|
f9be400a5d | ||
|
|
54808ac076 | ||
|
|
063bb2a227 | ||
|
|
93f79173b2 | ||
|
|
615c2389e7 | ||
|
|
f972637cca | ||
|
|
4c7e72b8e7 | ||
|
|
d4b4f51c3c | ||
|
|
1c42ff083d | ||
|
|
17d2e62b15 | ||
|
|
38aebeb50a | ||
|
|
b0f5263829 | ||
|
|
3226c14b6d | ||
|
|
0e26aa1b5d | ||
|
|
bd9dbec663 | ||
|
|
29d701780a | ||
|
|
afd498074b | ||
|
|
e851d0781c | ||
|
|
2c27c6904c | ||
|
|
03f1b969c2 | ||
|
|
85ba13de12 | ||
|
|
6ec545b00e | ||
|
|
05dbe60db2 | ||
|
|
d2ee3a5d24 | ||
|
|
1839664137 | ||
|
|
154f3ecf8a | ||
|
|
b75e40b800 | ||
|
|
84a358291b | ||
|
|
0e41b2d630 | ||
|
|
3e48a562e7 | ||
|
|
f0c4df42b7 | ||
|
|
a50e1e2472 | ||
|
|
c8f0e6a0d2 | ||
|
|
1537d5d480 | ||
|
|
32c78f6018 | ||
|
|
c5c0dae4bb | ||
|
|
92e74feabd | ||
|
|
56809a412c | ||
|
|
6a83743e2a | ||
|
|
faaf051e39 | ||
|
|
280ea5e997 |
84
.github/workflows/check.yml
vendored
@@ -1,5 +1,36 @@
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
trailing-whitespace:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Check for trailing whitespace
|
||||
run: |
|
||||
set -u
|
||||
|
||||
# Don't enforce checks on vendored libraries.
|
||||
readonly EXCLUDED_DIR='src/Libraries'
|
||||
|
||||
has_trailing_whitespace=false
|
||||
|
||||
while read -r line; do
|
||||
if grep \
|
||||
"\s$" \
|
||||
--line-number \
|
||||
--with-filename \
|
||||
--binary-files=without-match \
|
||||
"${line}"; then
|
||||
has_trailing_whitespace=true
|
||||
fi
|
||||
done < <(git ls-files | grep --invert-match "^${EXCLUDED_DIR}/")
|
||||
|
||||
if [ "$has_trailing_whitespace" = true ]; then
|
||||
echo "ERROR: Found trailing whitespace"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
compile:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -17,11 +48,14 @@ jobs:
|
||||
- "esp32:esp32:esp32c3"
|
||||
include:
|
||||
- fqbn: "esp8266:esp8266:d1_mini"
|
||||
core: "esp8266:esp8266@3.1.2"
|
||||
core: "esp8266:esp8266"
|
||||
core_version: "3.1.2"
|
||||
core_url: "https://arduino.esp8266.com/stable/package_esp8266com_index.json"
|
||||
- fqbn: "esp32:esp32:esp32c3"
|
||||
core: "esp32:esp32"
|
||||
core_version: "2.0.17"
|
||||
core_url: "https://espressif.github.io/arduino-esp32/package_esp32_index.json"
|
||||
board_options: "JTAGAdapter=default,CDCOnBoot=cdc,PartitionScheme=min_spiffs,CPUFreq=160,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=verbose,EraseFlash=none"
|
||||
core: "esp32:esp32@2.0.11"
|
||||
exclude:
|
||||
- example: "BASIC"
|
||||
fqbn: "esp32:esp32:esp32c3"
|
||||
@@ -31,30 +65,30 @@ jobs:
|
||||
fqbn: "esp32:esp32:esp32c3"
|
||||
- example: "OneOpenAir"
|
||||
fqbn: "esp8266:esp8266:d1_mini"
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run:
|
||||
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh |
|
||||
sh -s 0.35.3
|
||||
- run: bin/arduino-cli --verbose core install '${{ matrix.core }}'
|
||||
--additional-urls '${{ matrix.core_url }}'
|
||||
- run: bin/arduino-cli --verbose lib install
|
||||
WiFiManager@2.0.16-rc.2
|
||||
Arduino_JSON@0.2.0
|
||||
U8g2@2.34.22
|
||||
# In some cases, actions/checkout@v4 will check out a detached HEAD; for
|
||||
# example, this happens on pull request events, where an hypothetical
|
||||
# PR merge commit is checked out. This tends to confuse
|
||||
# `arduino-cli lib install --git-url`, making it fail with errors such as:
|
||||
# Error installing Git Library: Library install failed: object not found
|
||||
# Create and check out a dummy branch to work around this issue.
|
||||
- run: git checkout -b check
|
||||
- run: bin/arduino-cli --verbose lib install --git-url .
|
||||
env:
|
||||
ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL: "true"
|
||||
- run: bin/arduino-cli --verbose compile 'examples/${{ matrix.example }}'
|
||||
--fqbn '${{ matrix.fqbn }}' --board-options '${{ matrix.board_options }}'
|
||||
- uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: 'true'
|
||||
- uses: arduino/compile-sketches@v1.1.2
|
||||
with:
|
||||
fqbn: ${{ matrix.fqbn }}
|
||||
sketch-paths: |
|
||||
examples/${{ matrix.example }}
|
||||
libraries: |
|
||||
- source-path: ./
|
||||
cli-compile-flags: |
|
||||
- --warnings
|
||||
- none
|
||||
- --board-options
|
||||
- "${{ matrix.board_options }}"
|
||||
platforms: |
|
||||
- name: ${{ matrix.core }}
|
||||
version: ${{ matrix.core_version}}
|
||||
source-url: ${{ matrix.core_url }}
|
||||
enable-deltas-report: true
|
||||
|
||||
# TODO: at this point it would be a good idea to run some smoke tests on
|
||||
# the resulting image (e.g. that it boots successfully and sends metrics)
|
||||
# but that would either require a high fidelity device emulator, or a
|
||||
|
||||
5
.gitignore
vendored
@@ -3,3 +3,8 @@ build
|
||||
.vscode
|
||||
/.idea/
|
||||
.pio
|
||||
.cache
|
||||
.clangd
|
||||
logs
|
||||
gen_compile_commands.py
|
||||
compile_commands.json
|
||||
|
||||
6
.gitmodules
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[submodule "src/Libraries/airgradient-client"]
|
||||
path = src/Libraries/airgradient-client
|
||||
url = ../../airgradienthq/airgradient-client.git
|
||||
[submodule "src/Libraries/airgradient-ota"]
|
||||
path = src/Libraries/airgradient-ota
|
||||
url = ../../airgradienthq/airgradient-ota.git
|
||||
25
README.md
@@ -20,13 +20,32 @@ Make sure you have exactly the versions of libraries and boards installed as des
|
||||
|
||||
If you have an older version of the AirGradient PCB not mentioned in the example files, please downgrade this library to version 2.4.15 to support these legacy boards.
|
||||
|
||||
### Release Process
|
||||
|
||||
Releases published on GitHub are **not immediately deployed to all devices in the market**. Each release first goes through internal testing, including limited deployments in select locations to verify stability and functionality.
|
||||
|
||||
If the tests pass, the firmware is then made available for:
|
||||
- **FOTA (Firmware Over-The-Air) updates** from AirGradient dashboard
|
||||
- **Manual flashing** via [Airgradient](https://www.airgradient.com/documentation/firmwares/) website
|
||||
|
||||
Each GitHub release note will also include the planned rollout date for wider availability.
|
||||
|
||||
## Help & Support
|
||||
|
||||
If you have any questions or problems, check out [our forum](https://forum.airgradient.com/).
|
||||
If you have any questions or problems, check out [our forum](https://forum.airgradient.com/).
|
||||
|
||||
## Documentation
|
||||
## Development
|
||||
|
||||
Local server API documentation is available in [/docs/local-server.md](/docs/local-server.md) and AirGradient server API on [https://api.airgradient.com/public/docs/api/v1/](https://api.airgradient.com/public/docs/api/v1/).
|
||||
* See [compilation instructions](/docs/howto-compile.md) for details about how to customize AirGradient's firmware and flash it to your device.
|
||||
|
||||
## Over the air (OTA) updates
|
||||
|
||||
* See the [OTA Updates documentation](/docs/ota-updates.md) for details about how AirGradient monitors receive over the air updates.
|
||||
|
||||
## API documentation
|
||||
|
||||
* [Local server API documentation](/docs/local-server.md)
|
||||
* [AirGradient Cloud server API documentation](https://api.airgradient.com/public/docs/api/v1/).
|
||||
|
||||
## The following libraries have been integrated into this library for ease of use
|
||||
|
||||
|
||||
102
docs/howto-compile.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# How to compile AirGradient firmware on Arduino IDE
|
||||
|
||||
## Prequisite
|
||||
|
||||
Arduino IDE version 2.x ([download](https://www.arduino.cc/en/software))
|
||||
|
||||
> For AirGradient model ONE and Open Air, the codebase **WILL NOT** work on the latest major version of arduino-esp32 which is *3.x* . This related to when installing "esp32 by Espressif Systems" in board manager. Instead use version **2.0.17**, please follow the first step carefully.
|
||||
|
||||
## Steps for ESP32C3 based board (ONE and Open Air Model)
|
||||
|
||||
1. Install "esp32 by Espressif Systems" in board manager with version **2.0.17** (Tools ➝ Board ➝ Boards Manager ➝ search for `"espressif"`)
|
||||
|
||||

|
||||
|
||||
2. Install AirGradient library
|
||||
|
||||
#### Version < 3.2.0
|
||||
|
||||
Using library manager install the latest version (Tools ➝ Manage Libraries... ➝ search for `"airgradient"`)
|
||||
|
||||

|
||||
|
||||
#### Version >= 3.3.0
|
||||
|
||||
- From your terminal, go to Arduino libraries folder (windows and mac: `Documents/Arduino/libraries` or linux: `~/Arduino/Libraries`).
|
||||
- With **git** cli, execute this command `git clone --recursive https://github.com/airgradienthq/arduino.git AirGradient_Air_Quality_Sensor`
|
||||
- Restart Arduino IDE
|
||||
|
||||
3. On tools tab, follow settings below
|
||||
|
||||
```
|
||||
Board ➝ ESP32C3 Dev Module
|
||||
USB CDC On Boot ➝ Enabled
|
||||
CPU Frequency ➝ 160MHz (WiFi)
|
||||
Core Debug Level ➝ Info
|
||||
Erase All Flash Before Sketch Upload ➝ Enabled (or choose as needed)
|
||||
Flash Frequency ➝ 80MHz
|
||||
Flash Mode ➝ QIO
|
||||
Flash Size ➝ 4MB (32Mb)
|
||||
JTAG Adapter ➝ Disabled
|
||||
Partition Scheme ➝ Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)
|
||||
Upload Speed ➝ 921600
|
||||
```
|
||||
|
||||
4. Open sketch to compile (File ➝ Examples ➝ AirGradient Air Quality Sensor ➝ OneOpenAir). This sketch for AirGradient ONE and Open Air monitor model
|
||||
5. Compile
|
||||
|
||||

|
||||
|
||||
## Steps for ESP8266 based board (DIY model)
|
||||
|
||||
1. Add esp8266 board by adding http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field (File ➝ Preferences ➝ Additional boards manager URLs)
|
||||
|
||||

|
||||
|
||||
2. Install esp8266 board on board manager with version **3.1.2** (Tools ➝ Board ➝ Boards Manager ➝ search for `"esp8266"`)
|
||||
|
||||

|
||||
|
||||
3. Install AirGradient library on library manager using the latest version (Tools ➝ Manage Libraries... ➝ search for `"airgradient"`)
|
||||
|
||||

|
||||
|
||||
4. On tools tab, set board to `LOLIN(WEMOS) D1 R2 & mini`, and let other settings to default
|
||||
|
||||

|
||||
|
||||
5. Open sketch to compile (File ➝ Examples ➝ AirGradient Air Quality Sensor ➝ `<Model Option>`). Depends on the DIY model, either `BASIC`, `DiyProIndoorV3_3` and `DiyProIndoorV4_2`
|
||||
6. Compile
|
||||
|
||||

|
||||
|
||||
## Possible Issues
|
||||
|
||||
### Linux (Debian)
|
||||
|
||||
ModuleNotFoundError: No module named ‘serial’
|
||||
|
||||

|
||||
|
||||
Make sure python pyserial module installed globally in the environment by executing:
|
||||
|
||||
`$ sudo apt install -y python3-pyserial`
|
||||
|
||||
or
|
||||
|
||||
`$ pip install pyserial`
|
||||
|
||||
Choose based on how python installed on your machine. But most user, using `apt` is better.
|
||||
|
||||
## How to contribute
|
||||
|
||||
The instructions above are the instructions for how to build an official release of the AirGradient firmware using the Arduino IDE. If you intend to make changes which you plan to contribute back to the main project, instead of installing the AirGradient library, check out the repository at Documents/Arduino/libraries (for Windows and Mac) or ~/Arduino/libraries (for Linux). If you installed the library, you can remove it from the library manager in the Arduino IDE, or just delete the directory.
|
||||
|
||||
**NOTE:** When cloning the repository, for version >= 3.3.0 it has submodule, please use `--recursive` flag like this: `git clone --recursive https://github.com/airgradienthq/arduino.git AirGradient_Air_Quality_Sensor`
|
||||
|
||||
Please follow github [contributing to a project](https://docs.github.com/en/get-started/exploring-projects-on-github/contributing-to-a-project) tutorial to contribute to this project.
|
||||
|
||||
There are 2 environment options to compile this project, PlatformIO and ArduinoIDE.
|
||||
|
||||
- For PlatformIO, it should work out of the box
|
||||
- For arduino, files in `src` folder and also from `Examples` can be modified at `Documents/Arduino/libraries` for Windows and Mac, and `~/Arduino/Libraries` for Linux
|
||||
BIN
docs/images/additional-board.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
docs/images/ag-lib.png
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
docs/images/compiled-esp8266.png
Normal file
|
After Width: | Height: | Size: 148 KiB |
BIN
docs/images/compiled.png
Normal file
|
After Width: | Height: | Size: 131 KiB |
BIN
docs/images/esp32-board.png
Normal file
|
After Width: | Height: | Size: 62 KiB |
BIN
docs/images/esp8266-board.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
docs/images/linux-failed.png
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
docs/images/settings-esp8266.png
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
docs/images/settings.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
@@ -1,6 +1,6 @@
|
||||
## Local Server API
|
||||
|
||||
From [firmware version 3.0.10](firmwares) onwards, the AirGradient ONE and Open Air monitors have below API available.
|
||||
From [firmware version 3.0.10](firmwares) onwards, the AirGradient ONE and Open Air monitors have below API available.
|
||||
|
||||
### Discovery
|
||||
|
||||
@@ -20,7 +20,7 @@ http://airgradient_ecda3b1eaaaf.local/measures/current
|
||||
“ecda3b1eaaaf” being the serial number of your monitor.
|
||||
|
||||
You get the following response:
|
||||
```json
|
||||
```json
|
||||
{
|
||||
"wifi": -46,
|
||||
"serialno": "ecda3b1eaaaf",
|
||||
@@ -84,7 +84,7 @@ Compensated values apply correction algorithms to make the sensor values more ac
|
||||
|
||||
"/config" path returns the current configuration of the monitor.
|
||||
|
||||
```json
|
||||
```json
|
||||
{
|
||||
"country": "TH",
|
||||
"pmStandard": "ugm3",
|
||||
@@ -93,6 +93,7 @@ Compensated values apply correction algorithms to make the sensor values more ac
|
||||
"tvocLearningOffset": 12,
|
||||
"noxLearningOffset": 12,
|
||||
"mqttBrokerUrl": "",
|
||||
"httpDomain": "",
|
||||
"temperatureUnit": "c",
|
||||
"configurationControl": "local",
|
||||
"postDataToAirGradient": true,
|
||||
@@ -105,7 +106,6 @@ Compensated values apply correction algorithms to make the sensor values more ac
|
||||
"pm02": {
|
||||
"correctionAlgorithm": "epa_2021",
|
||||
"slr": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,22 +118,22 @@ Configuration parameters can be changed with a PUT request to the monitor, e.g.
|
||||
Example to force CO2 calibration
|
||||
|
||||
```bash
|
||||
curl -X PUT -H "Content-Type: application/json" -d '{"co2CalibrationRequested":true}' http://airgradient_84fce612eff4.local/config
|
||||
curl -X PUT -H "Content-Type: application/json" -d '{"co2CalibrationRequested":true}' http://airgradient_84fce612eff4.local/config
|
||||
```
|
||||
|
||||
Example to set monitor to Celsius
|
||||
|
||||
```bash
|
||||
curl -X PUT -H "Content-Type: application/json" -d '{"temperatureUnit":"c"}' http://airgradient_84fce612eff4.local/config
|
||||
curl -X PUT -H "Content-Type: application/json" -d '{"temperatureUnit":"c"}' http://airgradient_84fce612eff4.local/config
|
||||
```
|
||||
|
||||
If you use command prompt on Windows, you need to escape the quotes:
|
||||
|
||||
|
||||
``` -d "{\"param\":\"value\"}" ```
|
||||
|
||||
### Avoiding Conflicts with Configuration on AirGradient Server
|
||||
|
||||
If the monitor is set up on the AirGradient dashboard, it will also receive the configuration parameters from there. In case you do not want this, please set `configurationControl` to `local`. In case you set it to `cloud` and want to change it to `local`, you need to make a factory reset.
|
||||
If the monitor is set up on the AirGradient dashboard, it will also receive the configuration parameters from there. In case you do not want this, please set `configurationControl` to `local`. In case you set it to `cloud` and want to change it to `local`, you need to make a factory reset.
|
||||
|
||||
### Configuration Parameters (GET/PUT)
|
||||
|
||||
@@ -146,7 +146,8 @@ If the monitor is set up on the AirGradient dashboard, it will also receive the
|
||||
| `displayBrightness` | Brightness of the Display. | Number | 0-100 | `{"displayBrightness": 50}` |
|
||||
| `ledBarBrightness` | Brightness of the LEDBar. | Number | 0-100 | `{"ledBarBrightness": 40}` |
|
||||
| `abcDays` | Number of days for CO2 automatic baseline calibration. | Number | Maximum 200 days. Default 8 days. | `{"abcDays": 8}` |
|
||||
| `mqttBrokerUrl` | MQTT broker URL. | String | | `{"mqttBrokerUrl": "mqtt://192.168.0.18:1883"}` |
|
||||
| `mqttBrokerUrl` | MQTT broker URL. | String | Maximum 255 characters. Set value to empty string to disable mqtt connection. | `{"mqttBrokerUrl": "mqtt://192.168.0.18:1883"}` |
|
||||
| `httpDomain` | Domain name for http request. (version > 3.3.2) | String | Maximum 255 characters. Set value to empty string to set http domain to default airgradient | `{"httpDomain": "sub.domain.com"}` |
|
||||
| `temperatureUnit` | Temperature unit shown on the display. | String | `c` or `C`: Degree Celsius °C <br>`f` or `F`: Degree Fahrenheit °F | `{"temperatureUnit": "c"}` |
|
||||
| `configurationControl` | The configuration source of the device. | String | `both`: Accept local and cloud configuration <br>`local`: Accept only local configuration <br>`cloud`: Accept only cloud configuration | `{"configurationControl": "both"}` |
|
||||
| `postDataToAirGradient` | Send data to AirGradient cloud. | Boolean | `true`: Enabled <br>`false`: Disabled | `{"postDataToAirGradient": true}` |
|
||||
@@ -154,11 +155,14 @@ If the monitor is set up on the AirGradient dashboard, it will also receive the
|
||||
| `ledBarTestRequested` | Can be set to trigger a test. | Boolean | `true` : LEDs will run test sequence | `{"ledBarTestRequested": true}` |
|
||||
| `noxLearningOffset` | Set NOx learning gain offset. | Number | 0-720 (default 12) | `{"noxLearningOffset": 12}` |
|
||||
| `tvocLearningOffset` | Set VOC learning gain offset. | Number | 0-720 (default 12) | `{"tvocLearningOffset": 12}` |
|
||||
| `offlineMode` | Set monitor to run without WiFi. | Boolean | `false`: Disabled (default) <br> `true`: Enabled | `{"offlineMode": true}` |
|
||||
| `monitorDisplayCompensatedValues` | Set the display show the PM value with/without compensate value (only on [3.1.9]()) | Boolean | `false`: Without compensate (default) <br> `true`: with compensate | `{"monitorDisplayCompensatedValues": false }` |
|
||||
| `corrections` | Sets correction options to display and measurement values on local server response. (version >= [3.1.11]()) | Object | _see corrections section_ | _see corrections section_ |
|
||||
| `monitorDisplayCompensatedValues` | Set the display show the PM value with/without compensate value (only on 3.1.9) | Boolean | `false`: Without compensate (default) <br> `true`: with compensate | `{"monitorDisplayCompensatedValues": false }` |
|
||||
| `corrections` | Sets correction options to display and measurement values on local server response. (version >= 3.1.11) | Object | _see corrections section_ | _see corrections section_ |
|
||||
|
||||
|
||||
**Notes**
|
||||
|
||||
- `offlineMode` : the device will disable all network operation, and only show measurements on the display and ledbar; Read-Only; Change can be apply using reset button on boot.
|
||||
- `disableCloudConnection` : disable every request to AirGradient server, means features like post data to AirGradient server, configuration from AirGradient server and automatic firmware updates are disabled. This configuration overrides `configurationControl` and `postDataToAirGradient`; Read-Only; Change can be apply from wifi setup webpage.
|
||||
|
||||
### Corrections
|
||||
|
||||
@@ -200,34 +204,34 @@ Example correction configuration:
|
||||
Field Name: `pm02`
|
||||
|
||||
| Algorithm | Value | Description | SLR required |
|
||||
|------------|-------------|------|---------|
|
||||
|------------|-------------|------|---------|
|
||||
| Raw | `"none"` | No correction (default) | No |
|
||||
| EPA 2021 | `"epa_2021"` | Use EPA 2021 correction factors on top of raw value | No |
|
||||
| PMS5003_20240104 | `"slr_PMS5003_20240104"` | Correction for PMS5003 sensor batch 20240104| Yes |
|
||||
| PMS5003_20240104 | `"slr_PMS5003_20240104"` | Correction for PMS5003 sensor batch 20240104| Yes |
|
||||
| PMS5003_20231218 | `"slr_PMS5003_20231218"` | Correction for PMS5003 sensor batch 20231218| Yes |
|
||||
| PMS5003_20231030 | `"slr_PMS5003_20231030"` | Correction for PMS5003 sensor batch 20231030| Yes |
|
||||
|
||||
**NOTES**:
|
||||
**NOTES**:
|
||||
|
||||
- Set `useEpa2021` to `true` if want to apply EPA 2021 correction factors on top of SLR correction value, otherwise `false`
|
||||
- `intercept` and `scalingFactor` values can be obtained from [this article](https://www.airgradient.com/blog/low-readings-from-pms5003/)
|
||||
- If `configurationControl` is set to `local` (eg. when using Home Assistant), correction need to be set manually, see examples below
|
||||
- If `configurationControl` is set to `local` (eg. when using Home Assistant), correction need to be set manually, see examples below
|
||||
|
||||
**Examples**:
|
||||
|
||||
- PMS5003_20231030
|
||||
- PMS5003_20231030
|
||||
|
||||
```bash
|
||||
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20231030","slr":{"intercept":0,"scalingFactor":0.02838,"useEpa2021":true}}}}'
|
||||
```
|
||||
|
||||
- PMS5003_20231218
|
||||
- PMS5003_20231218
|
||||
|
||||
```bash
|
||||
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20231218","slr":{"intercept":0,"scalingFactor":0.03525,"useEpa2021":true}}}}'
|
||||
```
|
||||
|
||||
- PMS5003_20240104
|
||||
- PMS5003_20240104
|
||||
|
||||
```bash
|
||||
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20240104","slr":{"intercept":0,"scalingFactor":0.02896,"useEpa2021":true}}}}'
|
||||
@@ -240,10 +244,10 @@ Field Name:
|
||||
- Humidity: `rhum`
|
||||
|
||||
| Algorithm | Value | Description | SLR required |
|
||||
|------------|-------------|------|---------|
|
||||
|------------|-------------|------|---------|
|
||||
| Raw | `"none"` | No correction (default) | No |
|
||||
| AirGradient Standard Correction | `"ag_pms5003t_2024"` | Using standard airgradient correction (for outdoor monitor)| No |
|
||||
| Custom | `"custom"` | custom corrections constant, set `intercept` and `scalingFactor` manually | Yes |
|
||||
| Custom | `"custom"` | custom corrections constant, set `intercept` and `scalingFactor` manually | Yes |
|
||||
|
||||
*Table above apply for both Temperature and Humidity*
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## OTA Updates
|
||||
|
||||
From [firmware version 3.1.1](https://github.com/airgradienthq/arduino/tree/3.1.1) onwards, the AirGradient ONE and Open Air monitors support over the air (OTA) updates.
|
||||
From [firmware version 3.1.1](https://github.com/airgradienthq/arduino/tree/3.1.1) onwards, the AirGradient ONE and Open Air monitors support over the air (OTA) updates.
|
||||
|
||||
#### Mechanism
|
||||
|
||||
@@ -10,7 +10,7 @@ The device attempts to update to the latest version on startup and in regular in
|
||||
|
||||
http://hw.airgradient.com/sensors/{deviceId}/generic/os/firmware.bin?current_firmware={GIT_VERSION}
|
||||
|
||||
If does pass the version it is currently running on along to the server through URL parameter 'current_firmware'.
|
||||
If does pass the version it is currently running on along to the server through URL parameter 'current_firmware'.
|
||||
This allows the server to identify if the device is already running on the latest version or should update.
|
||||
|
||||
The following scenarios are possible
|
||||
|
||||
@@ -12,10 +12,8 @@ Outdoor Monitor: https://www.airgradient.com/outdoor/
|
||||
Build Instructions:
|
||||
https://www.airgradient.com/documentation/diy-v4/
|
||||
|
||||
Please make sure you have esp8266 board manager installed. Tested with
|
||||
version 3.1.2.
|
||||
|
||||
Set board to "LOLIN(WEMOS) D1 R2 & mini"
|
||||
Compile Instructions:
|
||||
https://github.com/airgradienthq/arduino/blob/master/docs/howto-compile.md
|
||||
|
||||
Configuration parameters, e.g. Celsius / Fahrenheit or PM unit (US AQI vs ug/m3)
|
||||
can be set through the AirGradient dashboard.
|
||||
@@ -150,9 +148,12 @@ void setup() {
|
||||
initMqtt();
|
||||
sendDataToAg();
|
||||
|
||||
apiClient.fetchServerConfiguration();
|
||||
if (configuration.getConfigurationControl() !=
|
||||
ConfigurationControl::ConfigurationControlLocal) {
|
||||
apiClient.fetchServerConfiguration();
|
||||
}
|
||||
configSchedule.update();
|
||||
if (apiClient.isFetchConfigureFailed()) {
|
||||
if (apiClient.isFetchConfigurationFailed()) {
|
||||
if (apiClient.isNotAvailableOnDashboard()) {
|
||||
stateMachine.displaySetAddToDashBoard();
|
||||
stateMachine.displayHandle(
|
||||
@@ -293,7 +294,7 @@ static bool sgp41Init(void) {
|
||||
configuration.hasSensorSGP = true;
|
||||
return true;
|
||||
} else {
|
||||
Serial.println("Init SGP41 failuire");
|
||||
Serial.println("Init SGP41 failure");
|
||||
configuration.hasSensorSGP = false;
|
||||
}
|
||||
return false;
|
||||
@@ -416,6 +417,14 @@ static void failedHandler(String msg) {
|
||||
}
|
||||
|
||||
static void configurationUpdateSchedule(void) {
|
||||
if (configuration.isOfflineMode() ||
|
||||
configuration.getConfigurationControl() == ConfigurationControl::ConfigurationControlLocal) {
|
||||
Serial.println("Ignore fetch server configuration. Either mode is offline "
|
||||
"or configurationControl set to local");
|
||||
apiClient.resetFetchConfigurationStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (apiClient.fetchServerConfiguration()) {
|
||||
configUpdateHandle();
|
||||
}
|
||||
@@ -473,7 +482,7 @@ static void appDispHandler(void) {
|
||||
if (configuration.isOfflineMode() == false) {
|
||||
if (wifiConnector.isConnected() == false) {
|
||||
state = AgStateMachineWiFiLost;
|
||||
} else if (apiClient.isFetchConfigureFailed()) {
|
||||
} else if (apiClient.isFetchConfigurationFailed()) {
|
||||
state = AgStateMachineSensorConfigFailed;
|
||||
if (apiClient.isNotAvailableOnDashboard()) {
|
||||
stateMachine.displaySetAddToDashBoard();
|
||||
@@ -522,17 +531,21 @@ static void sendDataToServer(void) {
|
||||
int bootCount = measurements.bootCount() + 1;
|
||||
measurements.setBootCount(bootCount);
|
||||
|
||||
/** Ignore send data to server if postToAirGradient disabled */
|
||||
if (configuration.isPostDataToAirGradient() == false ||
|
||||
configuration.isOfflineMode()) {
|
||||
if (configuration.isOfflineMode() || !configuration.isPostDataToAirGradient()) {
|
||||
Serial.println("Skipping transmission of data to AG server. Either mode is offline "
|
||||
"or post data to server disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wifiConnector.isConnected() == false) {
|
||||
Serial.println("WiFi not connected, skipping data transmission to AG server");
|
||||
return;
|
||||
}
|
||||
|
||||
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI());
|
||||
if (apiClient.postToServer(syncData)) {
|
||||
Serial.println();
|
||||
Serial.println(
|
||||
"Online mode and isPostToAirGradient = true: watchdog reset");
|
||||
Serial.println("Online mode and isPostToAirGradient = true");
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ String OpenMetrics::getPayload(void) {
|
||||
"1 if the AirGradient device was able to successfully fetch its "
|
||||
"configuration from the server",
|
||||
"gauge");
|
||||
add_metric_point("", apiClient.isFetchConfigureFailed() ? "0" : "1");
|
||||
add_metric_point("", apiClient.isFetchConfigurationFailed() ? "0" : "1");
|
||||
|
||||
add_metric(
|
||||
"post_ok",
|
||||
|
||||
@@ -12,10 +12,8 @@ Outdoor Monitor: https://www.airgradient.com/outdoor/
|
||||
Build Instructions:
|
||||
https://www.airgradient.com/documentation/diy-v4/
|
||||
|
||||
Please make sure you have esp8266 board manager installed. Tested with
|
||||
version 3.1.2.
|
||||
|
||||
Set board to "LOLIN(WEMOS) D1 R2 & mini"
|
||||
Compile Instructions:
|
||||
https://github.com/airgradienthq/arduino/blob/master/docs/howto-compile.md
|
||||
|
||||
Configuration parameters, e.g. Celsius / Fahrenheit or PM unit (US AQI vs ug/m3)
|
||||
can be set through the AirGradient dashboard.
|
||||
@@ -150,9 +148,12 @@ void setup() {
|
||||
initMqtt();
|
||||
sendDataToAg();
|
||||
|
||||
apiClient.fetchServerConfiguration();
|
||||
if (configuration.getConfigurationControl() !=
|
||||
ConfigurationControl::ConfigurationControlLocal) {
|
||||
apiClient.fetchServerConfiguration();
|
||||
}
|
||||
configSchedule.update();
|
||||
if (apiClient.isFetchConfigureFailed()) {
|
||||
if (apiClient.isFetchConfigurationFailed()) {
|
||||
if (apiClient.isNotAvailableOnDashboard()) {
|
||||
stateMachine.displaySetAddToDashBoard();
|
||||
stateMachine.displayHandle(
|
||||
@@ -350,7 +351,7 @@ static bool sgp41Init(void) {
|
||||
configuration.hasSensorSGP = true;
|
||||
return true;
|
||||
} else {
|
||||
Serial.println("Init SGP41 failuire");
|
||||
Serial.println("Init SGP41 failure");
|
||||
configuration.hasSensorSGP = false;
|
||||
}
|
||||
return false;
|
||||
@@ -468,6 +469,14 @@ static void failedHandler(String msg) {
|
||||
}
|
||||
|
||||
static void configurationUpdateSchedule(void) {
|
||||
if (configuration.isOfflineMode() ||
|
||||
configuration.getConfigurationControl() == ConfigurationControl::ConfigurationControlLocal) {
|
||||
Serial.println("Ignore fetch server configuration. Either mode is offline "
|
||||
"or configurationControl set to local");
|
||||
apiClient.resetFetchConfigurationStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (apiClient.fetchServerConfiguration()) {
|
||||
configUpdateHandle();
|
||||
}
|
||||
@@ -525,7 +534,7 @@ static void appDispHandler(void) {
|
||||
if (configuration.isOfflineMode() == false) {
|
||||
if (wifiConnector.isConnected() == false) {
|
||||
state = AgStateMachineWiFiLost;
|
||||
} else if (apiClient.isFetchConfigureFailed()) {
|
||||
} else if (apiClient.isFetchConfigurationFailed()) {
|
||||
state = AgStateMachineSensorConfigFailed;
|
||||
if (apiClient.isNotAvailableOnDashboard()) {
|
||||
stateMachine.displaySetAddToDashBoard();
|
||||
@@ -574,17 +583,21 @@ static void sendDataToServer(void) {
|
||||
int bootCount = measurements.bootCount() + 1;
|
||||
measurements.setBootCount(bootCount);
|
||||
|
||||
/** Ignore send data to server if postToAirGradient disabled */
|
||||
if (configuration.isPostDataToAirGradient() == false ||
|
||||
configuration.isOfflineMode()) {
|
||||
if (configuration.isOfflineMode() || !configuration.isPostDataToAirGradient()) {
|
||||
Serial.println("Skipping transmission of data to AG server. Either mode is offline "
|
||||
"or post data to server disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wifiConnector.isConnected() == false) {
|
||||
Serial.println("WiFi not connected, skipping data transmission to AG server");
|
||||
return;
|
||||
}
|
||||
|
||||
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI());
|
||||
if (apiClient.postToServer(syncData)) {
|
||||
Serial.println();
|
||||
Serial.println(
|
||||
"Online mode and isPostToAirGradient = true: watchdog reset");
|
||||
Serial.println("Online mode and isPostToAirGradient = true");
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ String OpenMetrics::getPayload(void) {
|
||||
"1 if the AirGradient device was able to successfully fetch its "
|
||||
"configuration from the server",
|
||||
"gauge");
|
||||
add_metric_point("", apiClient.isFetchConfigureFailed() ? "0" : "1");
|
||||
add_metric_point("", apiClient.isFetchConfigurationFailed() ? "0" : "1");
|
||||
|
||||
add_metric(
|
||||
"post_ok",
|
||||
|
||||
@@ -12,10 +12,8 @@ Outdoor Monitor: https://www.airgradient.com/outdoor/
|
||||
Build Instructions:
|
||||
https://www.airgradient.com/documentation/diy-v4/
|
||||
|
||||
Please make sure you have esp8266 board manager installed. Tested with
|
||||
version 3.1.2.
|
||||
|
||||
Set board to "LOLIN(WEMOS) D1 R2 & mini"
|
||||
Compile Instructions:
|
||||
https://github.com/airgradienthq/arduino/blob/master/docs/howto-compile.md
|
||||
|
||||
Configuration parameters, e.g. Celsius / Fahrenheit or PM unit (US AQI vs ug/m3)
|
||||
can be set through the AirGradient dashboard.
|
||||
@@ -177,9 +175,12 @@ void setup() {
|
||||
initMqtt();
|
||||
sendDataToAg();
|
||||
|
||||
apiClient.fetchServerConfiguration();
|
||||
if (configuration.getConfigurationControl() !=
|
||||
ConfigurationControl::ConfigurationControlLocal) {
|
||||
apiClient.fetchServerConfiguration();
|
||||
}
|
||||
configSchedule.update();
|
||||
if (apiClient.isFetchConfigureFailed()) {
|
||||
if (apiClient.isFetchConfigurationFailed()) {
|
||||
if (apiClient.isNotAvailableOnDashboard()) {
|
||||
stateMachine.displaySetAddToDashBoard();
|
||||
stateMachine.displayHandle(
|
||||
@@ -248,7 +249,7 @@ void loop() {
|
||||
configUpdateHandle();
|
||||
|
||||
localServer._handle();
|
||||
|
||||
|
||||
if (configuration.hasSensorSGP) {
|
||||
ag.sgp41.handle();
|
||||
}
|
||||
@@ -373,7 +374,7 @@ static bool sgp41Init(void) {
|
||||
configuration.hasSensorSGP = true;
|
||||
return true;
|
||||
} else {
|
||||
Serial.println("Init SGP41 failuire");
|
||||
Serial.println("Init SGP41 failure");
|
||||
configuration.hasSensorSGP = false;
|
||||
}
|
||||
return false;
|
||||
@@ -508,6 +509,14 @@ static void failedHandler(String msg) {
|
||||
}
|
||||
|
||||
static void configurationUpdateSchedule(void) {
|
||||
if (configuration.isOfflineMode() ||
|
||||
configuration.getConfigurationControl() == ConfigurationControl::ConfigurationControlLocal) {
|
||||
Serial.println("Ignore fetch server configuration. Either mode is offline "
|
||||
"or configurationControl set to local");
|
||||
apiClient.resetFetchConfigurationStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (apiClient.fetchServerConfiguration()) {
|
||||
configUpdateHandle();
|
||||
}
|
||||
@@ -565,7 +574,7 @@ static void appDispHandler(void) {
|
||||
if (configuration.isOfflineMode() == false) {
|
||||
if (wifiConnector.isConnected() == false) {
|
||||
state = AgStateMachineWiFiLost;
|
||||
} else if (apiClient.isFetchConfigureFailed()) {
|
||||
} else if (apiClient.isFetchConfigurationFailed()) {
|
||||
state = AgStateMachineSensorConfigFailed;
|
||||
if (apiClient.isNotAvailableOnDashboard()) {
|
||||
stateMachine.displaySetAddToDashBoard();
|
||||
@@ -615,17 +624,21 @@ static void sendDataToServer(void) {
|
||||
int bootCount = measurements.bootCount() + 1;
|
||||
measurements.setBootCount(bootCount);
|
||||
|
||||
/** Ignore send data to server if postToAirGradient disabled */
|
||||
if (configuration.isPostDataToAirGradient() == false ||
|
||||
configuration.isOfflineMode()) {
|
||||
if (configuration.isOfflineMode() || !configuration.isPostDataToAirGradient()) {
|
||||
Serial.println("Skipping transmission of data to AG server. Either mode is offline "
|
||||
"or post data to server disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wifiConnector.isConnected() == false) {
|
||||
Serial.println("WiFi not connected, skipping data transmission to AG server");
|
||||
return;
|
||||
}
|
||||
|
||||
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI());
|
||||
if (apiClient.postToServer(syncData)) {
|
||||
Serial.println();
|
||||
Serial.println(
|
||||
"Online mode and isPostToAirGradient = true: watchdog reset");
|
||||
Serial.println("Online mode and isPostToAirGradient = true");
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ String OpenMetrics::getPayload(void) {
|
||||
"1 if the AirGradient device was able to successfully fetch its "
|
||||
"configuration from the server",
|
||||
"gauge");
|
||||
add_metric_point("", apiClient.isFetchConfigureFailed() ? "0" : "1");
|
||||
add_metric_point("", apiClient.isFetchConfigurationFailed() ? "0" : "1");
|
||||
|
||||
add_metric(
|
||||
"post_ok",
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
#include "OpenMetrics.h"
|
||||
|
||||
OpenMetrics::OpenMetrics(Measurements &measure, Configuration &config,
|
||||
WifiConnector &wifiConnector, AgApiClient &apiClient)
|
||||
: measure(measure), config(config), wifiConnector(wifiConnector),
|
||||
apiClient(apiClient) {}
|
||||
WifiConnector &wifiConnector)
|
||||
: measure(measure), config(config), wifiConnector(wifiConnector) {}
|
||||
|
||||
OpenMetrics::~OpenMetrics() {}
|
||||
|
||||
void OpenMetrics::setAirGradient(AirGradient *ag) { this->ag = ag; }
|
||||
void OpenMetrics::setAirGradient(AirGradient *ag) {
|
||||
this->ag = ag;
|
||||
}
|
||||
|
||||
void OpenMetrics::setAirgradientClient(AirgradientClient *client) {
|
||||
this->agClient = client;
|
||||
}
|
||||
|
||||
const char *OpenMetrics::getApiContentType(void) {
|
||||
return "application/openmetrics-text; version=1.0.0; charset=utf-8";
|
||||
@@ -43,13 +48,13 @@ String OpenMetrics::getPayload(void) {
|
||||
"1 if the AirGradient device was able to successfully fetch its "
|
||||
"configuration from the server",
|
||||
"gauge");
|
||||
add_metric_point("", apiClient.isFetchConfigureFailed() ? "0" : "1");
|
||||
add_metric_point("", agClient->isLastFetchConfigSucceed() ? "1" : "0");
|
||||
|
||||
add_metric(
|
||||
"post_ok",
|
||||
"1 if the AirGradient device was able to successfully send to the server",
|
||||
"gauge");
|
||||
add_metric_point("", apiClient.isPostToServerFailed() ? "0" : "1");
|
||||
add_metric_point("", agClient->isLastPostMeasureSucceed() ? "1" : "0");
|
||||
|
||||
add_metric(
|
||||
"wifi_rssi",
|
||||
@@ -197,14 +202,14 @@ String OpenMetrics::getPayload(void) {
|
||||
}
|
||||
if (utils::isValidNOx(nox)) {
|
||||
add_metric("nox_index",
|
||||
"The processed Nitrous Oxide (NOx) index as measured by the "
|
||||
"The processed Nitrogen Oxide (NOx) index as measured by the "
|
||||
"AirGradient SGP sensor",
|
||||
"gauge");
|
||||
add_metric_point("", String(nox));
|
||||
}
|
||||
if (utils::isValidNOx(noxRaw)) {
|
||||
add_metric("nox_raw",
|
||||
"The raw input value to the Nitrous Oxide (NOx) index as "
|
||||
"The raw input value to the Nitrogen Oxide (NOx) index as "
|
||||
"measured by the AirGradient SGP sensor",
|
||||
"gauge");
|
||||
add_metric_point("", String(noxRaw));
|
||||
|
||||
@@ -5,21 +5,22 @@
|
||||
#include "AgValue.h"
|
||||
#include "AgWiFiConnector.h"
|
||||
#include "AirGradient.h"
|
||||
#include "AgApiClient.h"
|
||||
#include "Libraries/airgradient-client/src/airgradientClient.h"
|
||||
|
||||
class OpenMetrics {
|
||||
private:
|
||||
AirGradient *ag;
|
||||
AirgradientClient *agClient;
|
||||
Measurements &measure;
|
||||
Configuration &config;
|
||||
WifiConnector &wifiConnector;
|
||||
AgApiClient &apiClient;
|
||||
|
||||
public:
|
||||
OpenMetrics(Measurements &measure, Configuration &conig,
|
||||
WifiConnector &wifiConnector, AgApiClient& apiClient);
|
||||
OpenMetrics(Measurements &measure, Configuration &config,
|
||||
WifiConnector &wifiConnector);
|
||||
~OpenMetrics();
|
||||
void setAirGradient(AirGradient *ag);
|
||||
void setAirgradientClient(AirgradientClient *client);
|
||||
const char *getApiContentType(void);
|
||||
const char* getApi(void);
|
||||
String getPayload(void);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name=AirGradient Air Quality Sensor
|
||||
version=3.1.21
|
||||
version=3.3.9
|
||||
author=AirGradient <support@airgradient.com>
|
||||
maintainer=AirGradient <support@airgradient.com>
|
||||
sentence=ESP32-C3 / ESP8266 library for air quality monitor measuring PM, CO2, Temperature, TVOC and Humidity with OLED display.
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
platform = espressif32
|
||||
board = esp32-c3-devkitm-1
|
||||
framework = arduino
|
||||
build_flags = !echo '-D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=1 -D GIT_VERSION=\\"'$(git describe --tags --always --dirty)'\\"'
|
||||
build_flags = !echo '-D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=1 -D AG_LOG_LEVEL=AG_LOG_LEVEL_INFO -D GIT_VERSION=\\"'$(git describe --tags --always --dirty)'\\"'
|
||||
board_build.partitions = partitions.csv
|
||||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
lib_deps =
|
||||
aglib=symlink://../arduino
|
||||
EEPROM
|
||||
WebServer
|
||||
@@ -32,7 +32,7 @@ platform = espressif8266
|
||||
board = d1_mini
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
lib_deps =
|
||||
aglib=symlink://../arduino
|
||||
EEPROM
|
||||
ESP8266HTTPClient
|
||||
|
||||
@@ -34,17 +34,6 @@ void AgApiClient::begin(void) {
|
||||
* @return false Failure
|
||||
*/
|
||||
bool AgApiClient::fetchServerConfiguration(void) {
|
||||
if (config.getConfigurationControl() ==
|
||||
ConfigurationControl::ConfigurationControlLocal ||
|
||||
config.isOfflineMode()) {
|
||||
logWarning("Ignore fetch server configuration");
|
||||
|
||||
// Clear server configuration failed flag, cause it's ignore but not
|
||||
// really failed
|
||||
getConfigFailed = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
String uri = apiRoot + "/sensors/airgradient:" +
|
||||
ag->deviceId() + "/one/config";
|
||||
|
||||
@@ -58,7 +47,8 @@ bool AgApiClient::fetchServerConfiguration(void) {
|
||||
}
|
||||
#else
|
||||
HTTPClient client;
|
||||
client.setTimeout(timeoutMs);
|
||||
client.setConnectTimeout(timeoutMs); // Set timeout when establishing connection to server
|
||||
client.setTimeout(timeoutMs); // Timeout when waiting for response from AG server
|
||||
if (apiRootChanged) {
|
||||
// If apiRoot is changed, assume not using https
|
||||
if (client.begin(uri) == false) {
|
||||
@@ -114,15 +104,6 @@ bool AgApiClient::fetchServerConfiguration(void) {
|
||||
* @return false Failure
|
||||
*/
|
||||
bool AgApiClient::postToServer(String data) {
|
||||
if (config.isPostDataToAirGradient() == false) {
|
||||
logWarning("Ignore post data to server");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (WiFi.isConnected() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String uri = apiRoot + "/sensors/airgradient:" + ag->deviceId() + "/measures";
|
||||
#ifdef ESP8266
|
||||
HTTPClient client;
|
||||
@@ -133,7 +114,8 @@ bool AgApiClient::postToServer(String data) {
|
||||
}
|
||||
#else
|
||||
HTTPClient client;
|
||||
client.setTimeout(timeoutMs);
|
||||
client.setConnectTimeout(timeoutMs); // Set timeout when establishing connection to server
|
||||
client.setTimeout(timeoutMs); // Timeout when waiting for response from AG server
|
||||
if (apiRootChanged) {
|
||||
// If apiRoot is changed, assume not using https
|
||||
if (client.begin(uri) == false) {
|
||||
@@ -173,7 +155,12 @@ bool AgApiClient::postToServer(String data) {
|
||||
* @return true Success
|
||||
* @return false Failure
|
||||
*/
|
||||
bool AgApiClient::isFetchConfigureFailed(void) { return getConfigFailed; }
|
||||
bool AgApiClient::isFetchConfigurationFailed(void) { return getConfigFailed; }
|
||||
|
||||
/**
|
||||
* @brief Reset status of get configuration from AirGradient cloud
|
||||
*/
|
||||
void AgApiClient::resetFetchConfigurationStatus(void) { getConfigFailed = false; }
|
||||
|
||||
/**
|
||||
* @brief Get failed status when post data to AirGradient cloud
|
||||
@@ -198,13 +185,13 @@ void AgApiClient::setAirGradient(AirGradient *ag) { this->ag = ag; }
|
||||
|
||||
/**
|
||||
* @brief Send the package to check the connection with cloud
|
||||
*
|
||||
*
|
||||
* @param rssi WiFi RSSI
|
||||
* @param bootCount Boot count
|
||||
* @return true Success
|
||||
* @return false Failure
|
||||
*/
|
||||
bool AgApiClient::sendPing(int rssi, int bootCount) {
|
||||
bool AgApiClient::sendPing(int rssi, int bootCount) {
|
||||
JSONVar root;
|
||||
root["wifi"] = rssi;
|
||||
root["boot"] = bootCount;
|
||||
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
bool getConfigFailed;
|
||||
bool postToServerFailed;
|
||||
bool notAvailableOnDashboard = false; // Device not setup on Airgradient cloud dashboard.
|
||||
uint16_t timeoutMs = 10000; // Default set to 10s
|
||||
uint16_t timeoutMs = 15000; // Default set to 15s
|
||||
|
||||
public:
|
||||
AgApiClient(Stream &stream, Configuration &config);
|
||||
@@ -40,7 +40,8 @@ public:
|
||||
void begin(void);
|
||||
bool fetchServerConfiguration(void);
|
||||
bool postToServer(String data);
|
||||
bool isFetchConfigureFailed(void);
|
||||
bool isFetchConfigurationFailed(void);
|
||||
void resetFetchConfigurationStatus(void);
|
||||
bool isPostToServerFailed(void);
|
||||
bool isNotAvailableOnDashboard(void);
|
||||
void setAirGradient(AirGradient *ag);
|
||||
|
||||
@@ -22,15 +22,10 @@ const char *LED_BAR_MODE_NAMES[] = {
|
||||
};
|
||||
|
||||
const char *PM_CORRECTION_ALGORITHM_NAMES[] = {
|
||||
[Unknown] = "-", // This is only to pass "non-trivial designated initializers" error
|
||||
[None] = "none",
|
||||
[EPA_2021] = "epa_2021",
|
||||
[SLR_PMS5003_20220802] = "slr_PMS5003_20220802",
|
||||
[SLR_PMS5003_20220803] = "slr_PMS5003_20220803",
|
||||
[SLR_PMS5003_20220824] = "slr_PMS5003_20220824",
|
||||
[SLR_PMS5003_20231030] = "slr_PMS5003_20231030",
|
||||
[SLR_PMS5003_20231218] = "slr_PMS5003_20231218",
|
||||
[SLR_PMS5003_20240104] = "slr_PMS5003_20240104",
|
||||
[COR_ALGO_PM_UNKNOWN] = "-", // This is only to pass "non-trivial designated initializers" error
|
||||
[COR_ALGO_PM_NONE] = "none",
|
||||
[COR_ALGO_PM_EPA_2021] = "epa_2021",
|
||||
[COR_ALGO_PM_SLR_CUSTOM] = "custom",
|
||||
};
|
||||
|
||||
const char *TEMP_HUM_CORRECTION_ALGORITHM_NAMES[] = {
|
||||
@@ -51,9 +46,11 @@ JSON_PROP_DEF(abcDays);
|
||||
JSON_PROP_DEF(tvocLearningOffset);
|
||||
JSON_PROP_DEF(noxLearningOffset);
|
||||
JSON_PROP_DEF(mqttBrokerUrl);
|
||||
JSON_PROP_DEF(httpDomain);
|
||||
JSON_PROP_DEF(temperatureUnit);
|
||||
JSON_PROP_DEF(configurationControl);
|
||||
JSON_PROP_DEF(postDataToAirGradient);
|
||||
JSON_PROP_DEF(disableCloudConnection);
|
||||
JSON_PROP_DEF(ledBarBrightness);
|
||||
JSON_PROP_DEF(displayBrightness);
|
||||
JSON_PROP_DEF(co2CalibrationRequested);
|
||||
@@ -72,9 +69,11 @@ JSON_PROP_DEF(rhum);
|
||||
#define jprop_tvocLearningOffset_default 12
|
||||
#define jprop_noxLearningOffset_default 12
|
||||
#define jprop_mqttBrokerUrl_default ""
|
||||
#define jprop_httpDomain_default ""
|
||||
#define jprop_temperatureUnit_default "c"
|
||||
#define jprop_configurationControl_default String(CONFIGURATION_CONTROL_NAME[ConfigurationControl::ConfigurationControlBoth])
|
||||
#define jprop_postDataToAirGradient_default true
|
||||
#define jprop_disableCloudConnection_default false
|
||||
#define jprop_ledBarBrightness_default 100
|
||||
#define jprop_displayBrightness_default 100
|
||||
#define jprop_offlineMode_default false
|
||||
@@ -113,9 +112,9 @@ PMCorrectionAlgorithm Configuration::matchPmAlgorithm(String algorithm) {
|
||||
// If the input string matches an algorithm name, return the corresponding enum value
|
||||
// Else return Unknown
|
||||
|
||||
const size_t enumSize = SLR_PMS5003_20240104 + 1; // Get the actual size of the enum
|
||||
PMCorrectionAlgorithm result = PMCorrectionAlgorithm::Unknown;
|
||||
|
||||
const size_t enumSize = COR_ALGO_PM_SLR_CUSTOM + 1; // Get the actual size of the enum
|
||||
PMCorrectionAlgorithm result = COR_ALGO_PM_UNKNOWN;;
|
||||
|
||||
// Loop through enum values
|
||||
for (size_t enumVal = 0; enumVal < enumSize; enumVal++) {
|
||||
if (algorithm == PM_CORRECTION_ALGORITHM_NAMES[enumVal]) {
|
||||
@@ -123,6 +122,15 @@ PMCorrectionAlgorithm Configuration::matchPmAlgorithm(String algorithm) {
|
||||
}
|
||||
}
|
||||
|
||||
// If string not match from enum, check if correctionAlgorithm is one of the PM batch corrections
|
||||
if (result == COR_ALGO_PM_UNKNOWN) {
|
||||
// Check the substring "slr_PMS5003_xxxxxxxx"
|
||||
if (algorithm.substring(0, 11) == "slr_PMS5003") {
|
||||
// If it is, then its a custom correction
|
||||
result = COR_ALGO_PM_SLR_CUSTOM;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -143,36 +151,34 @@ TempHumCorrectionAlgorithm Configuration::matchTempHumAlgorithm(String algorithm
|
||||
|
||||
bool Configuration::updatePmCorrection(JSONVar &json) {
|
||||
if (!json.hasOwnProperty("corrections")) {
|
||||
Serial.println("corrections not found");
|
||||
logInfo("corrections not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
JSONVar corrections = json["corrections"];
|
||||
if (!corrections.hasOwnProperty("pm02")) {
|
||||
Serial.println("pm02 not found");
|
||||
logWarning("pm02 not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
JSONVar pm02 = corrections["pm02"];
|
||||
if (!pm02.hasOwnProperty("correctionAlgorithm")) {
|
||||
Serial.println("correctionAlgorithm not found");
|
||||
logWarning("pm02 correctionAlgorithm not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Need to have data type check, with error message response if invalid
|
||||
|
||||
// Check algorithm
|
||||
String algorithm = pm02["correctionAlgorithm"];
|
||||
PMCorrectionAlgorithm algo = matchPmAlgorithm(algorithm);
|
||||
if (algo == Unknown) {
|
||||
logInfo("Unknown algorithm");
|
||||
if (algo == COR_ALGO_PM_UNKNOWN) {
|
||||
logWarning("Unknown algorithm");
|
||||
return false;
|
||||
}
|
||||
logInfo("Correction algorithm: " + algorithm);
|
||||
|
||||
// If algo is None or EPA_2021, no need to check slr
|
||||
// But first check if pmCorrection different from algo
|
||||
if (algo == None || algo == EPA_2021) {
|
||||
if (algo == COR_ALGO_PM_NONE || algo == COR_ALGO_PM_EPA_2021) {
|
||||
if (pmCorrection.algorithm != algo) {
|
||||
// Deep copy corrections from root to jconfig, so it will be saved later
|
||||
jconfig[jprop_corrections]["pm02"]["correctionAlgorithm"] = algorithm;
|
||||
@@ -189,7 +195,7 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
|
||||
|
||||
// Check if pm02 has slr object
|
||||
if (!pm02.hasOwnProperty("slr")) {
|
||||
Serial.println("slr not found");
|
||||
logWarning("slr not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -198,7 +204,7 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
|
||||
// Validate required slr properties exist
|
||||
if (!slr.hasOwnProperty("intercept") || !slr.hasOwnProperty("scalingFactor") ||
|
||||
!slr.hasOwnProperty("useEpa2021")) {
|
||||
Serial.println("Missing required slr properties");
|
||||
logWarning("Missing required slr properties");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -236,8 +242,7 @@ bool Configuration::updateTempHumCorrection(JSONVar &json, TempHumCorrection &ta
|
||||
|
||||
JSONVar corrections = json[jprop_corrections];
|
||||
if (!corrections.hasOwnProperty(correctionName)) {
|
||||
Serial.println("pm02 not found");
|
||||
logWarning(String(correctionName) + " correction field not found on configuration");
|
||||
logInfo(String(correctionName) + " correction field not found on configuration");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -374,9 +379,11 @@ void Configuration::defaultConfig(void) {
|
||||
|
||||
jconfig[jprop_country] = jprop_country_default;
|
||||
jconfig[jprop_mqttBrokerUrl] = jprop_mqttBrokerUrl_default;
|
||||
jconfig[jprop_httpDomain] = jprop_httpDomain_default;
|
||||
jconfig[jprop_configurationControl] = jprop_configurationControl_default;
|
||||
jconfig[jprop_pmStandard] = jprop_pmStandard_default;
|
||||
jconfig[jprop_temperatureUnit] = jprop_temperatureUnit_default;
|
||||
jconfig[jprop_disableCloudConnection] = jprop_disableCloudConnection_default;
|
||||
jconfig[jprop_postDataToAirGradient] = jprop_postDataToAirGradient_default;
|
||||
if (ag->isOne()) {
|
||||
jconfig[jprop_ledBarBrightness] = jprop_ledBarBrightness_default;
|
||||
@@ -394,8 +401,8 @@ void Configuration::defaultConfig(void) {
|
||||
jconfig[jprop_offlineMode] = jprop_offlineMode_default;
|
||||
jconfig[jprop_monitorDisplayCompensatedValues] = jprop_monitorDisplayCompensatedValues_default;
|
||||
|
||||
// PM2.5 correction
|
||||
pmCorrection.algorithm = None;
|
||||
// PM2.5 default correction
|
||||
pmCorrection.algorithm = COR_ALGO_PM_NONE;
|
||||
pmCorrection.changed = false;
|
||||
pmCorrection.intercept = 0;
|
||||
pmCorrection.scalingFactor = 1;
|
||||
@@ -449,6 +456,10 @@ bool Configuration::begin(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Configuration::setConfigurationUpdatedCallback(ConfigurationUpdatedCallback_t callback) {
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse JSON configura string to local configure
|
||||
*
|
||||
@@ -731,11 +742,17 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
jconfig[jprop_mqttBrokerUrl] = broker;
|
||||
}
|
||||
} else {
|
||||
failedMessage = "\"mqttBrokerUrl\" length should <= 255";
|
||||
failedMessage = "\"mqttBrokerUrl\" length should less than 255 character";
|
||||
jsonInvalid();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else if (JSON.typeof_(root[jprop_mqttBrokerUrl]) == "null" and !isLocal) {
|
||||
// So if its not available on the json and json comes from aigradient server
|
||||
// then set its value to default (empty)
|
||||
jconfig[jprop_mqttBrokerUrl] = jprop_mqttBrokerUrl_default;
|
||||
}
|
||||
else {
|
||||
if (jsonTypeInvalid(root[jprop_mqttBrokerUrl], "string")) {
|
||||
failedMessage =
|
||||
jsonTypeInvalidMessage(String(jprop_mqttBrokerUrl), "string");
|
||||
@@ -744,6 +761,32 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
}
|
||||
|
||||
if (isLocal) {
|
||||
if (JSON.typeof_(root[jprop_httpDomain]) == "string") {
|
||||
String httpDomain = root[jprop_httpDomain];
|
||||
String oldHttpDomain = jconfig[jprop_httpDomain];
|
||||
if (httpDomain.length() <= 255) {
|
||||
if (httpDomain != oldHttpDomain) {
|
||||
changed = true;
|
||||
configLogInfo(String(jprop_httpDomain), oldHttpDomain, httpDomain);
|
||||
jconfig[jprop_httpDomain] = httpDomain;
|
||||
}
|
||||
} else {
|
||||
failedMessage = "\"httpDomain\" length should less than 255 character";
|
||||
jsonInvalid();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (jsonTypeInvalid(root[jprop_httpDomain], "string")) {
|
||||
failedMessage =
|
||||
jsonTypeInvalidMessage(String(jprop_httpDomain), "string");
|
||||
jsonInvalid();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.typeof_(root[jprop_temperatureUnit]) == "string") {
|
||||
String unit = root[jprop_temperatureUnit];
|
||||
String oldUnit = jconfig[jprop_temperatureUnit];
|
||||
@@ -912,15 +955,18 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (ledBarTestRequested || co2CalibrationRequested) {
|
||||
commandRequested = true;
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
updated = true;
|
||||
saveConfig();
|
||||
printConfig();
|
||||
} else {
|
||||
if (ledBarTestRequested || co2CalibrationRequested) {
|
||||
updated = true;
|
||||
}
|
||||
_callback();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1026,6 +1072,16 @@ String Configuration::getMqttBrokerUri(void) {
|
||||
return broker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get HTTP domain for post measures and get configuration
|
||||
*
|
||||
* @return String http domain, might be empty string
|
||||
*/
|
||||
String Configuration::getHttpDomain(void) {
|
||||
String httpDomain = jconfig[jprop_httpDomain];
|
||||
return httpDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get configuratoin post data to AirGradient cloud
|
||||
*
|
||||
@@ -1110,8 +1166,14 @@ bool Configuration::isUpdated(void) {
|
||||
return updated;
|
||||
}
|
||||
|
||||
bool Configuration::isCommandRequested(void) {
|
||||
bool oldState = this->commandRequested;
|
||||
this->commandRequested = false;
|
||||
return oldState;
|
||||
}
|
||||
|
||||
String Configuration::jsonTypeInvalidMessage(String name, String type) {
|
||||
return "'" + name + "' type invalid, it's should '" + type + "'";
|
||||
return "'" + name + "' type is invalid, expecting '" + type + "'";
|
||||
}
|
||||
|
||||
String Configuration::jsonValueInvalidMessage(String name, String value) {
|
||||
@@ -1151,20 +1213,20 @@ void Configuration::toConfig(const char *buf) {
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
bool isInvalid = false;
|
||||
bool isConfigFieldInvalid = false;
|
||||
|
||||
/** Validate country */
|
||||
if (JSON.typeof_(jconfig[jprop_country]) != "string") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
String country = jconfig[jprop_country];
|
||||
if (country.length() != 2) {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_country] = jprop_country_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: country changed");
|
||||
@@ -1172,17 +1234,17 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
/** validate: PM standard */
|
||||
if (JSON.typeof_(jconfig[jprop_pmStandard]) != "string") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
String standard = jconfig[jprop_pmStandard];
|
||||
if (standard != getPMStandardString(true) &&
|
||||
standard != getPMStandardString(false)) {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_pmStandard] = jprop_pmStandard_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: pmStandard changed");
|
||||
@@ -1190,18 +1252,18 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
/** validate led bar mode */
|
||||
if (JSON.typeof_(jconfig[jprop_ledBarMode]) != "string") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
String mode = jconfig[jprop_ledBarMode];
|
||||
if (mode != getLedBarModeName(LedBarMode::LedBarModeCO2) &&
|
||||
mode != getLedBarModeName(LedBarMode::LedBarModeOff) &&
|
||||
mode != getLedBarModeName(LedBarMode::LedBarModePm)) {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_ledBarMode] = jprop_ledBarMode_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: ledBarMode changed");
|
||||
@@ -1209,11 +1271,11 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
/** validate abcday */
|
||||
if (JSON.typeof_(jconfig[jprop_abcDays]) != "number") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_abcDays] = jprop_abcDays_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: abcDays changed");
|
||||
@@ -1221,16 +1283,16 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
/** validate tvoc learning offset */
|
||||
if (JSON.typeof_(jconfig[jprop_tvocLearningOffset]) != "number") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
int value = jconfig[jprop_tvocLearningOffset];
|
||||
if (value < 0) {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_tvocLearningOffset] = jprop_tvocLearningOffset_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: tvocLearningOffset changed");
|
||||
@@ -1238,16 +1300,16 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
/** validate nox learning offset */
|
||||
if (JSON.typeof_(jconfig[jprop_noxLearningOffset]) != "number") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
int value = jconfig[jprop_noxLearningOffset];
|
||||
if (value < 0) {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_noxLearningOffset] = jprop_noxLearningOffset_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: noxLearningOffset changed");
|
||||
@@ -1255,36 +1317,60 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
/** validate mqtt broker */
|
||||
if (JSON.typeof_(jconfig[jprop_mqttBrokerUrl]) != "string") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
changed = true;
|
||||
jconfig[jprop_mqttBrokerUrl] = jprop_mqttBrokerUrl_default;
|
||||
logInfo("toConfig: mqttBroker changed");
|
||||
}
|
||||
|
||||
/** validate http domain */
|
||||
if (JSON.typeof_(jconfig[jprop_httpDomain]) != "string") {
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
if (isConfigFieldInvalid) {
|
||||
changed = true;
|
||||
jconfig[jprop_httpDomain] = jprop_httpDomain_default;
|
||||
logInfo("toConfig: httpDomain changed");
|
||||
}
|
||||
|
||||
/** Validate temperature unit */
|
||||
if (JSON.typeof_(jconfig[jprop_temperatureUnit]) != "string") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
String unit = jconfig[jprop_temperatureUnit];
|
||||
if (unit != "c" && unit != "f") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_temperatureUnit] = jprop_temperatureUnit_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: temperatureUnit changed");
|
||||
}
|
||||
|
||||
/** validate disableCloudConnection configuration */
|
||||
if (JSON.typeof_(jconfig[jprop_disableCloudConnection]) != "boolean") {
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_disableCloudConnection] = jprop_disableCloudConnection_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: disableCloudConnection changed");
|
||||
}
|
||||
|
||||
/** validate configuration control */
|
||||
if (JSON.typeof_(jprop_configurationControl) != "string") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
String ctrl = jconfig[jprop_configurationControl];
|
||||
if (ctrl != String(CONFIGURATION_CONTROL_NAME
|
||||
@@ -1293,12 +1379,12 @@ void Configuration::toConfig(const char *buf) {
|
||||
[ConfigurationControl::ConfigurationControlLocal]) &&
|
||||
ctrl != String(CONFIGURATION_CONTROL_NAME
|
||||
[ConfigurationControl::ConfigurationControlCloud])) {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_configurationControl] =jprop_configurationControl_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: configurationControl changed");
|
||||
@@ -1306,11 +1392,11 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
/** Validate post to airgradient cloud */
|
||||
if (JSON.typeof_(jconfig[jprop_postDataToAirGradient]) != "boolean") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_postDataToAirGradient] = jprop_postDataToAirGradient_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: postToAirGradient changed");
|
||||
@@ -1318,16 +1404,16 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
/** validate led bar brightness */
|
||||
if (JSON.typeof_(jconfig[jprop_ledBarBrightness]) != "number") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
int value = jconfig[jprop_ledBarBrightness];
|
||||
if (value < 0 || value > 100) {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_ledBarBrightness] = jprop_ledBarBrightness_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: ledBarBrightness changed");
|
||||
@@ -1335,16 +1421,16 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
/** Validate display brightness */
|
||||
if (JSON.typeof_(jconfig[jprop_displayBrightness]) != "number") {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
int value = jconfig[jprop_displayBrightness];
|
||||
if (value < 0 || value > 100) {
|
||||
isInvalid = true;
|
||||
isConfigFieldInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
isConfigFieldInvalid = false;
|
||||
}
|
||||
}
|
||||
if (isInvalid) {
|
||||
if (isConfigFieldInvalid) {
|
||||
jconfig[jprop_displayBrightness] = jprop_displayBrightness_default;
|
||||
changed = true;
|
||||
logInfo("toConfig: displayBrightness changed");
|
||||
@@ -1365,7 +1451,7 @@ void Configuration::toConfig(const char *buf) {
|
||||
|
||||
// PM2.5 correction
|
||||
/// Set default first before parsing local config
|
||||
pmCorrection.algorithm = PMCorrectionAlgorithm::None;
|
||||
pmCorrection.algorithm = COR_ALGO_PM_NONE;
|
||||
pmCorrection.intercept = 0;
|
||||
pmCorrection.scalingFactor = 0;
|
||||
pmCorrection.useEPA = false;
|
||||
@@ -1465,13 +1551,24 @@ void Configuration::setOfflineModeWithoutSave(bool offline) {
|
||||
_offlineMode = offline;
|
||||
}
|
||||
|
||||
bool Configuration::isLedBarModeChanged(void) {
|
||||
bool Configuration::isCloudConnectionDisabled(void) {
|
||||
bool disabled = jconfig[jprop_disableCloudConnection];
|
||||
return disabled;
|
||||
}
|
||||
|
||||
void Configuration::setDisableCloudConnection(bool disable) {
|
||||
logInfo("Set DisableCloudConnection to " + String(disable ? "True" : "False"));
|
||||
jconfig[jprop_disableCloudConnection] = disable;
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
bool Configuration::isLedBarModeChanged(void) {
|
||||
bool changed = _ledBarModeChanged;
|
||||
_ledBarModeChanged = false;
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool Configuration::isMonitorDisplayCompensatedValues(void) {
|
||||
bool Configuration::isMonitorDisplayCompensatedValues(void) {
|
||||
return jconfig[jprop_monitorDisplayCompensatedValues];
|
||||
}
|
||||
|
||||
@@ -1494,14 +1591,14 @@ bool Configuration::isPMCorrectionChanged(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if PM correction is enabled
|
||||
*
|
||||
* @brief Check if PM correction is enabled
|
||||
*
|
||||
* @return true if PM correction algorithm is not None, otherwise false
|
||||
*/
|
||||
bool Configuration::isPMCorrectionEnabled(void) {
|
||||
PMCorrection pmCorrection = getPMCorrection();
|
||||
if (pmCorrection.algorithm == PMCorrectionAlgorithm::None ||
|
||||
pmCorrection.algorithm == PMCorrectionAlgorithm::Unknown) {
|
||||
if (pmCorrection.algorithm == COR_ALGO_PM_NONE ||
|
||||
pmCorrection.algorithm == COR_ALGO_PM_UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ private:
|
||||
bool co2CalibrationRequested;
|
||||
bool ledBarTestRequested;
|
||||
bool updated;
|
||||
bool commandRequested = false;
|
||||
String failedMessage;
|
||||
bool _noxLearnOffsetChanged;
|
||||
bool _tvocLearningOffsetChanged;
|
||||
@@ -70,6 +71,9 @@ public:
|
||||
bool hasSensorSGP = true;
|
||||
bool hasSensorSHT = true;
|
||||
|
||||
typedef void (*ConfigurationUpdatedCallback_t)();
|
||||
void setConfigurationUpdatedCallback(ConfigurationUpdatedCallback_t callback);
|
||||
|
||||
bool begin(void);
|
||||
bool parse(String data, bool isLocal);
|
||||
String toString(void);
|
||||
@@ -82,6 +86,7 @@ public:
|
||||
String getLedBarModeName(void);
|
||||
bool getDisplayMode(void);
|
||||
String getMqttBrokerUri(void);
|
||||
String getHttpDomain(void);
|
||||
bool isPostDataToAirGradient(void);
|
||||
ConfigurationControl getConfigurationControl(void);
|
||||
bool isCo2CalibrationRequested(void);
|
||||
@@ -89,6 +94,7 @@ public:
|
||||
void reset(void);
|
||||
String getModel(void);
|
||||
bool isUpdated(void);
|
||||
bool isCommandRequested(void);
|
||||
String getFailedMesage(void);
|
||||
void setPostToAirGradient(bool enable);
|
||||
bool noxLearnOffsetChanged(void);
|
||||
@@ -106,6 +112,8 @@ public:
|
||||
bool isOfflineMode(void);
|
||||
void setOfflineMode(bool offline);
|
||||
void setOfflineModeWithoutSave(bool offline);
|
||||
bool isCloudConnectionDisabled(void);
|
||||
void setDisableCloudConnection(bool disable);
|
||||
bool isLedBarModeChanged(void);
|
||||
bool isMonitorDisplayCompensatedValues(void);
|
||||
bool isPMCorrectionChanged(void);
|
||||
@@ -113,6 +121,8 @@ public:
|
||||
PMCorrection getPMCorrection(void);
|
||||
TempHumCorrection getTempCorrection(void);
|
||||
TempHumCorrection getHumCorrection(void);
|
||||
private:
|
||||
ConfigurationUpdatedCallback_t _callback;
|
||||
};
|
||||
|
||||
#endif /** _AG_CONFIG_H_ */
|
||||
|
||||
@@ -5,12 +5,31 @@
|
||||
/** Cast U8G2 */
|
||||
#define DISP() ((U8G2_SH1106_128X64_NONAME_F_HW_I2C *)(this->u8g2))
|
||||
|
||||
static const unsigned char WIFI_ISSUE_BITS[] = {
|
||||
0xd8, 0xc6, 0xde, 0xde, 0xc7, 0xf8, 0xd1, 0xe2, 0xdc, 0xce, 0xcc,
|
||||
0xcc, 0xc0, 0xc0, 0xd0, 0xc2, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0};
|
||||
|
||||
static const unsigned char CLOUD_ISSUE_BITS[] = {
|
||||
0x70, 0xc0, 0x88, 0xc0, 0x04, 0xc1, 0x04, 0xcf, 0x02, 0xd0, 0x01,
|
||||
0xe0, 0x01, 0xe0, 0x01, 0xe0, 0xa2, 0xd0, 0x4c, 0xce, 0xa0, 0xc0};
|
||||
|
||||
// Offline mode icon
|
||||
static unsigned char OFFLINE_BITS[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x62, 0x00,
|
||||
0xE6, 0x00, 0xFE, 0x1F, 0xFE, 0x1F, 0xE6, 0x00, 0x62, 0x00,
|
||||
0x30, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
// {
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x60, 0x00, 0x62, 0x00, 0xE2, 0x00,
|
||||
// 0xFE, 0x1F, 0xFE, 0x1F, 0xE2, 0x00, 0x62, 0x00, 0x60, 0x00, 0x30, 0x00,
|
||||
// 0x00, 0x00, 0x00, 0x00, };
|
||||
/**
|
||||
* @brief Show dashboard temperature and humdity
|
||||
*
|
||||
* @param hasStatus
|
||||
*/
|
||||
void OledDisplay::showTempHum(bool hasStatus, char *buf, int buf_size) {
|
||||
void OledDisplay::showTempHum(bool hasStatus) {
|
||||
char buf[10];
|
||||
/** Temperature */
|
||||
float temp = value.getCorrectedTempHum(Measurements::Temperature, 1);
|
||||
if (utils::isValidTemperature(temp)) {
|
||||
@@ -23,22 +42,22 @@ void OledDisplay::showTempHum(bool hasStatus, char *buf, int buf_size) {
|
||||
|
||||
if (config.isTemperatureUnitInF()) {
|
||||
if (hasStatus) {
|
||||
snprintf(buf, buf_size, "%0.1f", t);
|
||||
snprintf(buf, sizeof(buf), "%0.1f", t);
|
||||
} else {
|
||||
snprintf(buf, buf_size, "%0.1f°F", t);
|
||||
snprintf(buf, sizeof(buf), "%0.1f°F", t);
|
||||
}
|
||||
} else {
|
||||
if (hasStatus) {
|
||||
snprintf(buf, buf_size, "%.1f", t);
|
||||
snprintf(buf, sizeof(buf), "%.1f", t);
|
||||
} else {
|
||||
snprintf(buf, buf_size, "%.1f°C", t);
|
||||
snprintf(buf, sizeof(buf), "%.1f°C", t);
|
||||
}
|
||||
}
|
||||
} else { /** Show invalid value */
|
||||
if (config.isTemperatureUnitInF()) {
|
||||
snprintf(buf, buf_size, "-°F");
|
||||
snprintf(buf, sizeof(buf), "-°F");
|
||||
} else {
|
||||
snprintf(buf, buf_size, "-°C");
|
||||
snprintf(buf, sizeof(buf), "-°C");
|
||||
}
|
||||
}
|
||||
DISP()->drawUTF8(1, 10, buf);
|
||||
@@ -46,9 +65,9 @@ void OledDisplay::showTempHum(bool hasStatus, char *buf, int buf_size) {
|
||||
/** Show humidity */
|
||||
int rhum = round(value.getCorrectedTempHum(Measurements::Humidity, 1));
|
||||
if (utils::isValidHumidity(rhum)) {
|
||||
snprintf(buf, buf_size, "%d%%", rhum);
|
||||
snprintf(buf, sizeof(buf), "%d%%", rhum);
|
||||
} else {
|
||||
snprintf(buf, buf_size, "-%%");
|
||||
snprintf(buf, sizeof(buf), "-%%");
|
||||
}
|
||||
|
||||
if (rhum > 99.0) {
|
||||
@@ -67,6 +86,9 @@ void OledDisplay::setCentralText(int y, const char *text) {
|
||||
DISP()->drawStr(x, y, text);
|
||||
}
|
||||
|
||||
void OledDisplay::showIcon(int x, int y, xbm_icon_t *icon) {
|
||||
DISP()->drawXBM(x, y, icon->width, icon->height, icon->icon);
|
||||
}
|
||||
/**
|
||||
* @brief Construct a new Ag Oled Display:: Ag Oled Display object
|
||||
*
|
||||
@@ -252,36 +274,60 @@ void OledDisplay::setText(const char *line1, const char *line2,
|
||||
* @brief Update dashboard content
|
||||
*
|
||||
*/
|
||||
void OledDisplay::showDashboard(void) { showDashboard(NULL); }
|
||||
void OledDisplay::showDashboard(void) { showDashboard(DashBoardStatusNone); }
|
||||
|
||||
/**
|
||||
* @brief Update dashboard content and error status
|
||||
*
|
||||
*/
|
||||
void OledDisplay::showDashboard(const char *status) {
|
||||
void OledDisplay::showDashboard(DashboardStatus status) {
|
||||
if (isDisplayOff) {
|
||||
return;
|
||||
}
|
||||
|
||||
char strBuf[16];
|
||||
const int icon_pos_x = 64;
|
||||
xbm_icon_t xbm_icon = {
|
||||
.width = 0,
|
||||
.height = 0,
|
||||
.icon = nullptr,
|
||||
};
|
||||
|
||||
if (ag->isOne() || ag->isPro3_3() || ag->isPro4_2()) {
|
||||
DISP()->firstPage();
|
||||
do {
|
||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||
if ((status == NULL) || (strlen(status) == 0)) {
|
||||
showTempHum(false, strBuf, sizeof(strBuf));
|
||||
} else {
|
||||
String strStatus = "Show status: " + String(status);
|
||||
logInfo(strStatus);
|
||||
|
||||
int strWidth = DISP()->getStrWidth(status);
|
||||
DISP()->drawStr((DISP()->getWidth() - strWidth) / 2, 10, status);
|
||||
|
||||
/** Show WiFi NA*/
|
||||
if (strcmp(status, "WiFi N/A") == 0) {
|
||||
DISP()->setFont(u8g2_font_t0_12_tf);
|
||||
showTempHum(true, strBuf, sizeof(strBuf));
|
||||
}
|
||||
switch (status) {
|
||||
case DashBoardStatusNone: {
|
||||
// Maybe show signal strength?
|
||||
showTempHum(false);
|
||||
break;
|
||||
}
|
||||
case DashBoardStatusWiFiIssue: {
|
||||
DISP()->drawXBM(icon_pos_x, 0, 14, 11, WIFI_ISSUE_BITS);
|
||||
showTempHum(false);
|
||||
break;
|
||||
}
|
||||
case DashBoardStatusServerIssue: {
|
||||
DISP()->drawXBM(icon_pos_x, 0, 14, 11, CLOUD_ISSUE_BITS);
|
||||
showTempHum(false);
|
||||
break;
|
||||
}
|
||||
case DashBoardStatusAddToDashboard: {
|
||||
setCentralText(10, "Add To Dashboard");
|
||||
break;
|
||||
}
|
||||
case DashBoardStatusDeviceId: {
|
||||
setCentralText(10, ag->deviceId().c_str());
|
||||
break;
|
||||
}
|
||||
case DashBoardStatusOfflineMode: {
|
||||
DISP()->drawXBM(icon_pos_x, 0, 14, 14, OFFLINE_BITS);
|
||||
showTempHum(false); // First true
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/** Draw horizonal line */
|
||||
@@ -392,7 +438,8 @@ void OledDisplay::showDashboard(const char *status) {
|
||||
float temp = value.getCorrectedTempHum(Measurements::Temperature, 1);
|
||||
if (utils::isValidTemperature(temp)) {
|
||||
if (config.isTemperatureUnitInF()) {
|
||||
snprintf(strBuf, sizeof(strBuf), "T:%0.1f F", utils::degreeC_To_F(temp));
|
||||
snprintf(strBuf, sizeof(strBuf), "T:%0.1f F",
|
||||
utils::degreeC_To_F(temp));
|
||||
} else {
|
||||
snprintf(strBuf, sizeof(strBuf), "T:%0.1f C", temp);
|
||||
}
|
||||
@@ -442,8 +489,7 @@ void OledDisplay::setBrightness(int percent) {
|
||||
// Clear display.
|
||||
ag->display.clear();
|
||||
ag->display.show();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
isDisplayOff = false;
|
||||
ag->display.setContrast((255 * percent) / 100);
|
||||
}
|
||||
|
||||
@@ -16,17 +16,32 @@ private:
|
||||
Measurements &value;
|
||||
bool isDisplayOff = false;
|
||||
|
||||
void showTempHum(bool hasStatus, char* buf, int buf_size);
|
||||
typedef struct {
|
||||
int width;
|
||||
int height;
|
||||
unsigned char *icon;
|
||||
} xbm_icon_t;
|
||||
|
||||
void showTempHum(bool hasStatus);
|
||||
void setCentralText(int y, String text);
|
||||
void setCentralText(int y, const char *text);
|
||||
void showIcon(int x, int y, xbm_icon_t *icon);
|
||||
|
||||
public:
|
||||
OledDisplay(Configuration &config, Measurements &value,
|
||||
Stream &log);
|
||||
OledDisplay(Configuration &config, Measurements &value, Stream &log);
|
||||
~OledDisplay();
|
||||
|
||||
enum DashboardStatus {
|
||||
DashBoardStatusNone,
|
||||
DashBoardStatusWiFiIssue,
|
||||
DashBoardStatusServerIssue,
|
||||
DashBoardStatusAddToDashboard,
|
||||
DashBoardStatusDeviceId,
|
||||
DashBoardStatusOfflineMode,
|
||||
};
|
||||
|
||||
void setAirGradient(AirGradient *ag);
|
||||
bool begin(void);
|
||||
bool begin(void);
|
||||
void end(void);
|
||||
void setText(String &line1, String &line2, String &line3);
|
||||
void setText(const char *line1, const char *line2, const char *line3);
|
||||
@@ -34,7 +49,7 @@ public:
|
||||
void setText(const char *line1, const char *line2, const char *line3,
|
||||
const char *line4);
|
||||
void showDashboard(void);
|
||||
void showDashboard(const char *status);
|
||||
void showDashboard(DashboardStatus status);
|
||||
void setBrightness(int percent);
|
||||
#ifdef ESP32
|
||||
void showFirmwareUpdateVersion(String version);
|
||||
|
||||
@@ -8,8 +8,8 @@ AgSchedule::~AgSchedule() {}
|
||||
void AgSchedule::run(void) {
|
||||
uint32_t ms = (uint32_t)(millis() - count);
|
||||
if (ms >= period) {
|
||||
handler();
|
||||
count = millis();
|
||||
handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "AgStateMachine.h"
|
||||
#include "AgOledDisplay.h"
|
||||
|
||||
#define LED_TEST_BLINK_DELAY 50 /** ms */
|
||||
#define LED_TEST_BLINK_DELAY 50 /** ms */
|
||||
#define LED_FAST_BLINK_DELAY 250 /** ms */
|
||||
#define LED_SLOW_BLINK_DELAY 1000 /** ms */
|
||||
#define LED_SHORT_BLINK_DELAY 500 /** ms */
|
||||
@@ -8,10 +9,10 @@
|
||||
|
||||
#define SENSOR_CO2_CALIB_COUNTDOWN_MAX 5 /** sec */
|
||||
|
||||
#define RGB_COLOR_R 255, 0, 0 /** Red */
|
||||
#define RGB_COLOR_G 0, 255, 0 /** Green */
|
||||
#define RGB_COLOR_Y 255, 150, 0 /** Yellow */
|
||||
#define RGB_COLOR_O 255, 40, 0 /** Orange */
|
||||
#define RGB_COLOR_R 255, 0, 0 /** Red */
|
||||
#define RGB_COLOR_G 0, 255, 0 /** Green */
|
||||
#define RGB_COLOR_Y 255, 255, 0 /** Yellow */
|
||||
#define RGB_COLOR_O 255, 128, 0 /** Orange */
|
||||
#define RGB_COLOR_P 180, 0, 255 /** Purple */
|
||||
#define RGB_COLOR_CLEAR 0, 0, 0 /** No color */
|
||||
|
||||
@@ -50,7 +51,7 @@ void StateMachine::ledStatusBlinkDelay(uint32_t ms) {
|
||||
/**
|
||||
* @brief Led bar show PM or CO2 led color status
|
||||
*
|
||||
* @return true if all led bar are used, false othwerwise
|
||||
* @return true if all led bar are used, false othwerwise
|
||||
*/
|
||||
bool StateMachine::sensorhandleLeds(void) {
|
||||
int totalLedUsed = 0;
|
||||
@@ -82,7 +83,7 @@ bool StateMachine::sensorhandleLeds(void) {
|
||||
/**
|
||||
* @brief Show CO2 LED status
|
||||
*
|
||||
* @return return total number of led that are used on the monitor
|
||||
* @return return total number of led that are used on the monitor
|
||||
*/
|
||||
int StateMachine::co2handleLeds(void) {
|
||||
int totalUsed = ag->ledBar.getNumberOfLeds();
|
||||
@@ -166,8 +167,8 @@ int StateMachine::co2handleLeds(void) {
|
||||
|
||||
/**
|
||||
* @brief Show PM2.5 LED status
|
||||
*
|
||||
* @return return total number of led that are used on the monitor
|
||||
*
|
||||
* @return return total number of led that are used on the monitor
|
||||
*/
|
||||
int StateMachine::pm25handleLeds(void) {
|
||||
int totalUsed = ag->ledBar.getNumberOfLeds();
|
||||
@@ -369,18 +370,17 @@ void StateMachine::ledBarTest(void) {
|
||||
} else {
|
||||
ledBarRunTest();
|
||||
}
|
||||
}
|
||||
else if(ag->isOpenAir()) {
|
||||
} else if (ag->isOpenAir()) {
|
||||
ledBarRunTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StateMachine::ledBarPowerUpTest(void) {
|
||||
void StateMachine::ledBarPowerUpTest(void) {
|
||||
if (ag->isOne()) {
|
||||
ag->ledBar.clear();
|
||||
}
|
||||
ledBarRunTest();
|
||||
ledBarRunTest();
|
||||
}
|
||||
|
||||
void StateMachine::ledBarRunTest(void) {
|
||||
@@ -544,11 +544,11 @@ void StateMachine::displayHandle(AgStateMachineState state) {
|
||||
break;
|
||||
}
|
||||
case AgStateMachineWiFiLost: {
|
||||
disp.showDashboard("WiFi N/A");
|
||||
disp.showDashboard(OledDisplay::DashBoardStatusWiFiIssue);
|
||||
break;
|
||||
}
|
||||
case AgStateMachineServerLost: {
|
||||
disp.showDashboard("AG Server N/A");
|
||||
disp.showDashboard(OledDisplay::DashBoardStatusServerIssue);
|
||||
break;
|
||||
}
|
||||
case AgStateMachineSensorConfigFailed: {
|
||||
@@ -557,19 +557,24 @@ void StateMachine::displayHandle(AgStateMachineState state) {
|
||||
if (ms >= 5000) {
|
||||
addToDashboardTime = millis();
|
||||
if (addToDashBoardToggle) {
|
||||
disp.showDashboard("Add to AG Dashb.");
|
||||
disp.showDashboard(OledDisplay::DashBoardStatusAddToDashboard);
|
||||
} else {
|
||||
disp.showDashboard(ag->deviceId().c_str());
|
||||
disp.showDashboard(OledDisplay::DashBoardStatusDeviceId);
|
||||
}
|
||||
addToDashBoardToggle = !addToDashBoardToggle;
|
||||
}
|
||||
} else {
|
||||
disp.showDashboard("");
|
||||
disp.showDashboard();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AgStateMachineNormal: {
|
||||
disp.showDashboard();
|
||||
if (config.isOfflineMode()) {
|
||||
disp.showDashboard(
|
||||
OledDisplay::DashBoardStatusOfflineMode);
|
||||
} else {
|
||||
disp.showDashboard();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AgStateMachineCo2Calibration:
|
||||
|
||||
463
src/AgValue.cpp
@@ -2,8 +2,10 @@
|
||||
#include "AgConfigure.h"
|
||||
#include "AirGradient.h"
|
||||
#include "App/AppDef.h"
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
#define json_prop_pmFirmware "firmware"
|
||||
#define json_prop_pmFirmware "firmware"
|
||||
#define json_prop_pm01Ae "pm01"
|
||||
#define json_prop_pm25Ae "pm02"
|
||||
#define json_prop_pm10Ae "pm10"
|
||||
@@ -31,10 +33,129 @@ Measurements::Measurements(Configuration &config) : config(config) {
|
||||
#ifndef ESP8266
|
||||
_resetReason = (int)ESP_RST_UNKNOWN;
|
||||
#endif
|
||||
|
||||
/* Set invalid value for each measurements as default value when initialized*/
|
||||
_temperature[0].update.avg = utils::getInvalidTemperature();
|
||||
_temperature[1].update.avg = utils::getInvalidTemperature();
|
||||
_humidity[0].update.avg = utils::getInvalidHumidity();
|
||||
_humidity[1].update.avg = utils::getInvalidHumidity();
|
||||
_co2.update.avg = utils::getInvalidCO2();
|
||||
_tvoc.update.avg = utils::getInvalidVOC();
|
||||
_tvoc_raw.update.avg = utils::getInvalidVOC();
|
||||
_nox.update.avg = utils::getInvalidNOx();
|
||||
_nox_raw.update.avg = utils::getInvalidNOx();
|
||||
|
||||
_pm_03_pc[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_03_pc[1].update.avg = utils::getInvalidPmValue();
|
||||
_pm_05_pc[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_05_pc[1].update.avg = utils::getInvalidPmValue();
|
||||
_pm_5_pc[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_5_pc[1].update.avg = utils::getInvalidPmValue();
|
||||
|
||||
_pm_01[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_01_sp[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_01_pc[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_01[1].update.avg = utils::getInvalidPmValue();
|
||||
_pm_01_sp[1].update.avg = utils::getInvalidPmValue();
|
||||
_pm_01_pc[1].update.avg = utils::getInvalidPmValue();
|
||||
|
||||
_pm_25[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_25_sp[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_25_pc[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_25[1].update.avg = utils::getInvalidPmValue();
|
||||
_pm_25_sp[1].update.avg = utils::getInvalidPmValue();
|
||||
_pm_25_pc[1].update.avg = utils::getInvalidPmValue();
|
||||
|
||||
_pm_10[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_10_sp[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_10_pc[0].update.avg = utils::getInvalidPmValue();
|
||||
_pm_10[1].update.avg = utils::getInvalidPmValue();
|
||||
_pm_10_sp[1].update.avg = utils::getInvalidPmValue();
|
||||
_pm_10_pc[1].update.avg = utils::getInvalidPmValue();
|
||||
}
|
||||
|
||||
void Measurements::setAirGradient(AirGradient *ag) { this->ag = ag; }
|
||||
|
||||
void Measurements::printCurrentAverage() {
|
||||
Serial.println();
|
||||
if (config.hasSensorS8) {
|
||||
if (utils::isValidCO2(_co2.update.avg)) {
|
||||
Serial.printf("CO2 = %.2f ppm\n", _co2.update.avg);
|
||||
} else {
|
||||
Serial.printf("CO2 = -\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.hasSensorSHT) {
|
||||
if (utils::isValidTemperature(_temperature[0].update.avg)) {
|
||||
Serial.printf("Temperature = %.2f C\n", _temperature[0].update.avg);
|
||||
} else {
|
||||
Serial.printf("Temperature = -\n");
|
||||
}
|
||||
if (utils::isValidHumidity(_humidity[0].update.avg)) {
|
||||
Serial.printf("Relative Humidity = %.2f\n", _humidity[0].update.avg);
|
||||
} else {
|
||||
Serial.printf("Relative Humidity = -\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.hasSensorSGP) {
|
||||
if (utils::isValidVOC(_tvoc.update.avg)) {
|
||||
Serial.printf("TVOC Index = %.1f\n", _tvoc.update.avg);
|
||||
} else {
|
||||
Serial.printf("TVOC Index = -\n");
|
||||
}
|
||||
if (utils::isValidVOC(_tvoc_raw.update.avg)) {
|
||||
Serial.printf("TVOC Raw = %.1f\n", _tvoc_raw.update.avg);
|
||||
} else {
|
||||
Serial.printf("TVOC Raw = -\n");
|
||||
}
|
||||
if (utils::isValidNOx(_nox.update.avg)) {
|
||||
Serial.printf("NOx Index = %.1f\n", _nox.update.avg);
|
||||
} else {
|
||||
Serial.printf("NOx Index = -\n");
|
||||
}
|
||||
if (utils::isValidNOx(_nox_raw.update.avg)) {
|
||||
Serial.printf("NOx Raw = %.1f\n", _nox_raw.update.avg);
|
||||
} else {
|
||||
Serial.printf("NOx Raw = -\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.hasSensorPMS1) {
|
||||
printCurrentPMAverage(1);
|
||||
if (!config.hasSensorSHT) {
|
||||
if (utils::isValidTemperature(_temperature[0].update.avg)) {
|
||||
Serial.printf("[1] Temperature = %.2f C\n", _temperature[0].update.avg);
|
||||
} else {
|
||||
Serial.printf("[1] Temperature = -\n");
|
||||
}
|
||||
if (utils::isValidHumidity(_humidity[0].update.avg)) {
|
||||
Serial.printf("[1] Relative Humidity = %.2f\n", _humidity[0].update.avg);
|
||||
} else {
|
||||
Serial.printf("[1] Relative Humidity = -\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config.hasSensorPMS2) {
|
||||
printCurrentPMAverage(2);
|
||||
if (!config.hasSensorSHT) {
|
||||
if (utils::isValidTemperature(_temperature[1].update.avg)) {
|
||||
Serial.printf("[2] Temperature = %.2f C\n", _temperature[1].update.avg);
|
||||
} else {
|
||||
Serial.printf("[2] Temperature = -\n");
|
||||
}
|
||||
if (utils::isValidHumidity(_humidity[1].update.avg)) {
|
||||
Serial.printf("[2] Relative Humidity = %.2f\n", _humidity[1].update.avg);
|
||||
} else {
|
||||
Serial.printf("[2] Relative Humidity = -\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void Measurements::maxPeriod(MeasurementType type, int max) {
|
||||
switch (type) {
|
||||
case Temperature:
|
||||
@@ -447,7 +568,7 @@ float Measurements::getAverage(MeasurementType type, int ch) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return measurementAverage;
|
||||
return measurementAverage;
|
||||
}
|
||||
|
||||
String Measurements::pms5003FirmwareVersion(int fwCode) {
|
||||
@@ -529,6 +650,77 @@ String Measurements::measurementTypeStr(MeasurementType type) {
|
||||
return str;
|
||||
}
|
||||
|
||||
void Measurements::printCurrentPMAverage(int ch) {
|
||||
int idx = ch - 1;
|
||||
|
||||
if (utils::isValidPm(_pm_01[idx].update.avg)) {
|
||||
Serial.printf("[%d] Atmospheric PM 1.0 = %.2f ug/m3\n", ch, _pm_01[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Atmospheric PM 1.0 = -\n", ch);
|
||||
}
|
||||
if (utils::isValidPm(_pm_25[idx].update.avg)) {
|
||||
Serial.printf("[%d] Atmospheric PM 2.5 = %.2f ug/m3\n", ch, _pm_25[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Atmospheric PM 2.5 = -\n", ch);
|
||||
}
|
||||
if (utils::isValidPm(_pm_10[idx].update.avg)) {
|
||||
Serial.printf("[%d] Atmospheric PM 10 = %.2f ug/m3\n", ch, _pm_10[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Atmospheric PM 10 = -\n", ch);
|
||||
}
|
||||
if (utils::isValidPm(_pm_01_sp[idx].update.avg)) {
|
||||
Serial.printf("[%d] Standard Particle PM 1.0 = %.2f ug/m3\n", ch, _pm_01_sp[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Standard Particle PM 1.0 = -\n", ch);
|
||||
}
|
||||
if (utils::isValidPm(_pm_25_sp[idx].update.avg)) {
|
||||
Serial.printf("[%d] Standard Particle PM 2.5 = %.2f ug/m3\n", ch, _pm_25_sp[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Standard Particle PM 2.5 = -\n", ch);
|
||||
}
|
||||
if (utils::isValidPm(_pm_10_sp[idx].update.avg)) {
|
||||
Serial.printf("[%d] Standard Particle PM 10 = %.2f ug/m3\n", ch, _pm_10_sp[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Standard Particle PM 10 = -\n", ch);
|
||||
}
|
||||
if (utils::isValidPm03Count(_pm_03_pc[idx].update.avg)) {
|
||||
Serial.printf("[%d] Particle Count 0.3 = %.1f\n", ch, _pm_03_pc[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Particle Count 0.3 = -\n", ch);
|
||||
}
|
||||
if (utils::isValidPm03Count(_pm_05_pc[idx].update.avg)) {
|
||||
Serial.printf("[%d] Particle Count 0.5 = %.1f\n", ch, _pm_05_pc[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Particle Count 0.5 = -\n", ch);
|
||||
}
|
||||
if (utils::isValidPm03Count(_pm_01_pc[idx].update.avg)) {
|
||||
Serial.printf("[%d] Particle Count 1.0 = %.1f\n", ch, _pm_01_pc[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Particle Count 1.0 = -\n", ch);
|
||||
}
|
||||
if (utils::isValidPm03Count(_pm_25_pc[idx].update.avg)) {
|
||||
Serial.printf("[%d] Particle Count 2.5 = %.1f\n", ch, _pm_25_pc[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Particle Count 2.5 = -\n", ch);
|
||||
}
|
||||
|
||||
if (_pm_5_pc[idx].listValues.empty() == false) {
|
||||
if (utils::isValidPm03Count(_pm_5_pc[idx].update.avg)) {
|
||||
Serial.printf("[%d] Particle Count 5.0 = %.1f\n", ch, _pm_5_pc[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Particle Count 5.0 = -\n", ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (_pm_10_pc[idx].listValues.empty() == false) {
|
||||
if (utils::isValidPm03Count(_pm_10_pc[idx].update.avg)) {
|
||||
Serial.printf("[%d] Particle Count 10 = %.1f\n", ch, _pm_10_pc[idx].update.avg);
|
||||
} else {
|
||||
Serial.printf("[%d] Particle Count 10 = -\n", ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Measurements::validateChannel(int ch) {
|
||||
if (ch != 1 && ch != 2) {
|
||||
Serial.printf("ERROR! Channel %d is undefined. Only channel 1 or 2 is the optional value!", ch);
|
||||
@@ -600,7 +792,7 @@ float Measurements::getCorrectedTempHum(MeasurementType type, int ch, bool force
|
||||
return corrected;
|
||||
}
|
||||
|
||||
float Measurements::getCorrectedPM25(bool useAvg, int ch) {
|
||||
float Measurements::getCorrectedPM25(bool useAvg, int ch, bool forceCorrection) {
|
||||
float pm25;
|
||||
float corrected;
|
||||
float humidity;
|
||||
@@ -619,12 +811,18 @@ float Measurements::getCorrectedPM25(bool useAvg, int ch) {
|
||||
|
||||
Configuration::PMCorrection pmCorrection = config.getPMCorrection();
|
||||
switch (pmCorrection.algorithm) {
|
||||
case PMCorrectionAlgorithm::Unknown:
|
||||
case PMCorrectionAlgorithm::None:
|
||||
// If correction is Unknown, then default is None
|
||||
corrected = pm25;
|
||||
case PMCorrectionAlgorithm::COR_ALGO_PM_UNKNOWN:
|
||||
case PMCorrectionAlgorithm::COR_ALGO_PM_NONE: {
|
||||
// If correction is Unknown or None, then default is None
|
||||
// Unless forceCorrection enabled
|
||||
if (forceCorrection) {
|
||||
corrected = ag->pms5003.compensate(pm25, humidity);
|
||||
} else {
|
||||
corrected = pm25;
|
||||
}
|
||||
break;
|
||||
case PMCorrectionAlgorithm::EPA_2021:
|
||||
}
|
||||
case PMCorrectionAlgorithm::COR_ALGO_PM_EPA_2021:
|
||||
corrected = ag->pms5003.compensate(pm25, humidity);
|
||||
break;
|
||||
default: {
|
||||
@@ -641,6 +839,155 @@ float Measurements::getCorrectedPM25(bool useAvg, int ch) {
|
||||
return corrected;
|
||||
}
|
||||
|
||||
Measurements::Measures Measurements::getMeasures() {
|
||||
Measures mc;
|
||||
mc.bootCount = _bootCount;
|
||||
mc.freeHeap = ESP.getFreeHeap();
|
||||
// co2, tvoc, nox
|
||||
mc.co2 = _co2.update.avg;
|
||||
mc.tvoc = _tvoc.update.avg;
|
||||
mc.tvoc_raw = _tvoc_raw.update.avg;
|
||||
mc.nox = _nox.update.avg;
|
||||
mc.nox_raw = _nox_raw.update.avg;
|
||||
// Temperature & Humidity
|
||||
mc.temperature[0] = _temperature[0].update.avg;
|
||||
mc.humidity[0] = _humidity[0].update.avg;
|
||||
mc.temperature[1] = _temperature[1].update.avg;
|
||||
mc.humidity[1] = _humidity[1].update.avg;
|
||||
// PM atmospheric
|
||||
mc.pm_01[0] = _pm_01[0].update.avg;
|
||||
mc.pm_25[0] = _pm_25[0].update.avg;
|
||||
mc.pm_10[0] = _pm_10[0].update.avg;
|
||||
mc.pm_01[1] = _pm_01[1].update.avg;
|
||||
mc.pm_25[1] = _pm_25[1].update.avg;
|
||||
mc.pm_10[1] = _pm_10[1].update.avg;
|
||||
// PM standard particle
|
||||
mc.pm_01_sp[0] = _pm_01_sp[0].update.avg;
|
||||
mc.pm_25_sp[0] = _pm_25_sp[0].update.avg;
|
||||
mc.pm_10_sp[0] = _pm_10_sp[0].update.avg;
|
||||
mc.pm_01_sp[1] = _pm_01_sp[1].update.avg;
|
||||
mc.pm_25_sp[1] = _pm_25_sp[1].update.avg;
|
||||
mc.pm_10_sp[1] = _pm_10_sp[1].update.avg;
|
||||
// Particle Count
|
||||
mc.pm_03_pc[0] = _pm_03_pc[0].update.avg;
|
||||
mc.pm_05_pc[0] = _pm_05_pc[0].update.avg;
|
||||
mc.pm_01_pc[0] = _pm_01_pc[0].update.avg;
|
||||
mc.pm_25_pc[0] = _pm_25_pc[0].update.avg;
|
||||
mc.pm_5_pc[0] = _pm_5_pc[0].update.avg;
|
||||
mc.pm_10_pc[0] = _pm_10_pc[0].update.avg;
|
||||
mc.pm_03_pc[1] = _pm_03_pc[1].update.avg;
|
||||
mc.pm_05_pc[1] = _pm_05_pc[1].update.avg;
|
||||
mc.pm_01_pc[1] = _pm_01_pc[1].update.avg;
|
||||
mc.pm_25_pc[1] = _pm_25_pc[1].update.avg;
|
||||
mc.pm_5_pc[1] = _pm_5_pc[1].update.avg;
|
||||
mc.pm_10_pc[1] = _pm_10_pc[1].update.avg;
|
||||
|
||||
return mc;
|
||||
}
|
||||
|
||||
std::string Measurements::buildMeasuresPayload(Measures &mc) {
|
||||
std::ostringstream oss;
|
||||
|
||||
// CO2
|
||||
if (utils::isValidCO2(mc.co2)) {
|
||||
oss << std::round(mc.co2);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
// Temperature
|
||||
if (utils::isValidTemperature(mc.temperature[0]) && utils::isValidTemperature(mc.temperature[1])) {
|
||||
float temp = (mc.temperature[0] + mc.temperature[1]) / 2.0f;
|
||||
oss << std::round(temp * 10);
|
||||
} else if (utils::isValidTemperature(mc.temperature[0])) {
|
||||
oss << std::round(mc.temperature[0] * 10);
|
||||
} else if (utils::isValidTemperature(mc.temperature[1])) {
|
||||
oss << std::round(mc.temperature[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
// Humidity
|
||||
if (utils::isValidHumidity(mc.humidity[0]) && utils::isValidHumidity(mc.humidity[1])) {
|
||||
float hum = (mc.humidity[0] + mc.humidity[1]) / 2.0f;
|
||||
oss << std::round(hum * 10);
|
||||
} else if (utils::isValidHumidity(mc.humidity[0])) {
|
||||
oss << std::round(mc.humidity[0] * 10);
|
||||
} else if (utils::isValidHumidity(mc.humidity[1])) {
|
||||
oss << std::round(mc.humidity[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
/// PM1.0 atmospheric environment
|
||||
if (utils::isValidPm(mc.pm_01[0]) && utils::isValidPm(mc.pm_01[1])) {
|
||||
float pm01 = (mc.pm_01[0] + mc.pm_01[1]) / 2.0f;
|
||||
oss << std::round(pm01 * 10);
|
||||
} else if (utils::isValidPm(mc.pm_01[0])) {
|
||||
oss << std::round(mc.pm_01[0] * 10);
|
||||
} else if (utils::isValidPm(mc.pm_01[1])) {
|
||||
oss << std::round(mc.pm_01[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
/// PM2.5 atmospheric environment
|
||||
if (utils::isValidPm(mc.pm_25[0]) && utils::isValidPm(mc.pm_25[1])) {
|
||||
float pm25 = (mc.pm_25[0] + mc.pm_25[1]) / 2.0f;
|
||||
oss << std::round(pm25 * 10);
|
||||
} else if (utils::isValidPm(mc.pm_25[0])) {
|
||||
oss << std::round(mc.pm_25[0] * 10);
|
||||
} else if (utils::isValidPm(mc.pm_25[1])) {
|
||||
oss << std::round(mc.pm_25[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
/// PM10 atmospheric environment
|
||||
if (utils::isValidPm(mc.pm_10[0]) && utils::isValidPm(mc.pm_10[1])) {
|
||||
float pm10 = (mc.pm_10[0] + mc.pm_10[1]) / 2.0f;
|
||||
oss << std::round(pm10 * 10);
|
||||
} else if (utils::isValidPm(mc.pm_10[0])) {
|
||||
oss << std::round(mc.pm_10[0] * 10);
|
||||
} else if (utils::isValidPm(mc.pm_10[1])) {
|
||||
oss << std::round(mc.pm_10[1] * 10);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
// TVOC
|
||||
if (utils::isValidVOC(mc.tvoc)) {
|
||||
oss << std::round(mc.tvoc);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
// NOx
|
||||
if (utils::isValidNOx(mc.nox)) {
|
||||
oss << std::round(mc.nox);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
/// PM 0.3 particle count
|
||||
if (utils::isValidPm03Count(mc.pm_03_pc[0]) && utils::isValidPm03Count(mc.pm_03_pc[1])) {
|
||||
oss << std::round((mc.pm_03_pc[0] + mc.pm_03_pc[1]) / 2.0f);
|
||||
} else if (utils::isValidPm03Count(mc.pm_03_pc[0])) {
|
||||
oss << std::round(mc.pm_03_pc[0]);
|
||||
} else if (utils::isValidPm03Count(mc.pm_03_pc[1])) {
|
||||
oss << std::round(mc.pm_03_pc[1]);
|
||||
}
|
||||
|
||||
oss << ",";
|
||||
|
||||
if (mc.signal < 0) {
|
||||
oss << mc.signal;
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi) {
|
||||
JSONVar root;
|
||||
|
||||
@@ -741,8 +1088,8 @@ JSONVar Measurements::buildIndoor(bool localServer) {
|
||||
// buildPMS params:
|
||||
/// PMS channel 1 (indoor only have 1 PMS; hence allCh false)
|
||||
/// Not include temperature and humidity from PMS sensor
|
||||
/// Not include compensated calculation
|
||||
indoor = buildPMS(1, false, false, false);
|
||||
/// Include compensated calculation
|
||||
indoor = buildPMS(1, false, false, true);
|
||||
if (!localServer) {
|
||||
// Indoor is using PMS5003
|
||||
indoor[json_prop_pmFirmware] = this->pms5003FirmwareVersion(ag->pms5003.getFirmwareVersion());
|
||||
@@ -766,15 +1113,6 @@ JSONVar Measurements::buildIndoor(bool localServer) {
|
||||
}
|
||||
}
|
||||
|
||||
// Add pm25 compensated value only if PM2.5 and humidity value is valid
|
||||
if (config.hasSensorPMS1 && utils::isValidPm(_pm_25[0].update.avg)) {
|
||||
if (config.hasSensorSHT && utils::isValidHumidity(_humidity[0].update.avg)) {
|
||||
// Correction using moving average value
|
||||
float tmp = getCorrectedPM25(true);
|
||||
indoor[json_prop_pm25Compensated] = ag->round2(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
return indoor;
|
||||
}
|
||||
|
||||
@@ -787,58 +1125,58 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
||||
validateChannel(ch);
|
||||
|
||||
// Follow array indexing just for get address of the value type
|
||||
ch = ch - 1;
|
||||
int chIndex = ch - 1;
|
||||
|
||||
if (utils::isValidPm(_pm_01[ch].update.avg)) {
|
||||
pms[json_prop_pm01Ae] = ag->round2(_pm_01[ch].update.avg);
|
||||
if (utils::isValidPm(_pm_01[chIndex].update.avg)) {
|
||||
pms[json_prop_pm01Ae] = ag->round2(_pm_01[chIndex].update.avg);
|
||||
}
|
||||
if (utils::isValidPm(_pm_25[ch].update.avg)) {
|
||||
pms[json_prop_pm25Ae] = ag->round2(_pm_25[ch].update.avg);
|
||||
if (utils::isValidPm(_pm_25[chIndex].update.avg)) {
|
||||
pms[json_prop_pm25Ae] = ag->round2(_pm_25[chIndex].update.avg);
|
||||
}
|
||||
if (utils::isValidPm(_pm_10[ch].update.avg)) {
|
||||
pms[json_prop_pm10Ae] = ag->round2(_pm_10[ch].update.avg);
|
||||
if (utils::isValidPm(_pm_10[chIndex].update.avg)) {
|
||||
pms[json_prop_pm10Ae] = ag->round2(_pm_10[chIndex].update.avg);
|
||||
}
|
||||
if (utils::isValidPm(_pm_01_sp[ch].update.avg)) {
|
||||
pms[json_prop_pm01Sp] = ag->round2(_pm_01_sp[ch].update.avg);
|
||||
if (utils::isValidPm(_pm_01_sp[chIndex].update.avg)) {
|
||||
pms[json_prop_pm01Sp] = ag->round2(_pm_01_sp[chIndex].update.avg);
|
||||
}
|
||||
if (utils::isValidPm(_pm_25_sp[ch].update.avg)) {
|
||||
pms[json_prop_pm25Sp] = ag->round2(_pm_25_sp[ch].update.avg);
|
||||
if (utils::isValidPm(_pm_25_sp[chIndex].update.avg)) {
|
||||
pms[json_prop_pm25Sp] = ag->round2(_pm_25_sp[chIndex].update.avg);
|
||||
}
|
||||
if (utils::isValidPm(_pm_10_sp[ch].update.avg)) {
|
||||
pms[json_prop_pm10Sp] = ag->round2(_pm_10_sp[ch].update.avg);
|
||||
if (utils::isValidPm(_pm_10_sp[chIndex].update.avg)) {
|
||||
pms[json_prop_pm10Sp] = ag->round2(_pm_10_sp[chIndex].update.avg);
|
||||
}
|
||||
if (utils::isValidPm03Count(_pm_03_pc[ch].update.avg)) {
|
||||
pms[json_prop_pm03Count] = ag->round2(_pm_03_pc[ch].update.avg);
|
||||
if (utils::isValidPm03Count(_pm_03_pc[chIndex].update.avg)) {
|
||||
pms[json_prop_pm03Count] = ag->round2(_pm_03_pc[chIndex].update.avg);
|
||||
}
|
||||
if (utils::isValidPm03Count(_pm_05_pc[ch].update.avg)) {
|
||||
pms[json_prop_pm05Count] = ag->round2(_pm_05_pc[ch].update.avg);
|
||||
if (utils::isValidPm03Count(_pm_05_pc[chIndex].update.avg)) {
|
||||
pms[json_prop_pm05Count] = ag->round2(_pm_05_pc[chIndex].update.avg);
|
||||
}
|
||||
if (utils::isValidPm03Count(_pm_01_pc[ch].update.avg)) {
|
||||
pms[json_prop_pm1Count] = ag->round2(_pm_01_pc[ch].update.avg);
|
||||
if (utils::isValidPm03Count(_pm_01_pc[chIndex].update.avg)) {
|
||||
pms[json_prop_pm1Count] = ag->round2(_pm_01_pc[chIndex].update.avg);
|
||||
}
|
||||
if (utils::isValidPm03Count(_pm_25_pc[ch].update.avg)) {
|
||||
pms[json_prop_pm25Count] = ag->round2(_pm_25_pc[ch].update.avg);
|
||||
if (utils::isValidPm03Count(_pm_25_pc[chIndex].update.avg)) {
|
||||
pms[json_prop_pm25Count] = ag->round2(_pm_25_pc[chIndex].update.avg);
|
||||
}
|
||||
if (_pm_5_pc[ch].listValues.empty() == false) {
|
||||
if (_pm_5_pc[chIndex].listValues.empty() == false) {
|
||||
// Only include pm5.0 count when values available on its list
|
||||
// If not, means no pm5_pc available from the sensor
|
||||
if (utils::isValidPm03Count(_pm_5_pc[ch].update.avg)) {
|
||||
pms[json_prop_pm5Count] = ag->round2(_pm_5_pc[ch].update.avg);
|
||||
if (utils::isValidPm03Count(_pm_5_pc[chIndex].update.avg)) {
|
||||
pms[json_prop_pm5Count] = ag->round2(_pm_5_pc[chIndex].update.avg);
|
||||
}
|
||||
}
|
||||
if (_pm_10_pc[ch].listValues.empty() == false) {
|
||||
if (_pm_10_pc[chIndex].listValues.empty() == false) {
|
||||
// Only include pm10 count when values available on its list
|
||||
// If not, means no pm10_pc available from the sensor
|
||||
if (utils::isValidPm03Count(_pm_10_pc[ch].update.avg)) {
|
||||
pms[json_prop_pm10Count] = ag->round2(_pm_10_pc[ch].update.avg);
|
||||
if (utils::isValidPm03Count(_pm_10_pc[chIndex].update.avg)) {
|
||||
pms[json_prop_pm10Count] = ag->round2(_pm_10_pc[chIndex].update.avg);
|
||||
}
|
||||
}
|
||||
|
||||
if (withTempHum) {
|
||||
float _vc;
|
||||
// Set temperature if valid
|
||||
if (utils::isValidTemperature(_temperature[ch].update.avg)) {
|
||||
pms[json_prop_temp] = ag->round2(_temperature[ch].update.avg);
|
||||
if (utils::isValidTemperature(_temperature[chIndex].update.avg)) {
|
||||
pms[json_prop_temp] = ag->round2(_temperature[chIndex].update.avg);
|
||||
// Compensate temperature when flag is set
|
||||
if (compensate) {
|
||||
_vc = getCorrectedTempHum(Temperature, ch, true);
|
||||
@@ -848,8 +1186,8 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
||||
}
|
||||
}
|
||||
// Set humidity if valid
|
||||
if (utils::isValidHumidity(_humidity[ch].update.avg)) {
|
||||
pms[json_prop_rhum] = ag->round2(_humidity[ch].update.avg);
|
||||
if (utils::isValidHumidity(_humidity[chIndex].update.avg)) {
|
||||
pms[json_prop_rhum] = ag->round2(_humidity[chIndex].update.avg);
|
||||
// Compensate relative humidity when flag is set
|
||||
if (compensate) {
|
||||
_vc = getCorrectedTempHum(Humidity, ch, true);
|
||||
@@ -859,17 +1197,14 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
||||
}
|
||||
}
|
||||
|
||||
// Add pm25 compensated value only if PM2.5 and humidity value is valid
|
||||
if (compensate) {
|
||||
if (utils::isValidPm(_pm_25[ch].update.avg) &&
|
||||
utils::isValidHumidity(_humidity[ch].update.avg)) {
|
||||
// Note: the pms5003t object is not matter either for channel 1 or 2, compensate points to
|
||||
// the same base function
|
||||
float pm25 = ag->pms5003t_1.compensate(_pm_25[ch].update.avg, _humidity[ch].update.avg);
|
||||
if (utils::isValidPm(pm25)) {
|
||||
pms[json_prop_pm25Compensated] = ag->round2(pm25);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add pm25 compensated value only if PM2.5 and humidity value is valid
|
||||
if (compensate) {
|
||||
if (utils::isValidPm(_pm_25[chIndex].update.avg) &&
|
||||
utils::isValidHumidity(_humidity[chIndex].update.avg)) {
|
||||
float pm25 = getCorrectedPM25(true, ch, true);
|
||||
pms[json_prop_pm25Compensated] = ag->round2(pm25);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1117,12 +1452,12 @@ JSONVar Measurements::buildPMS(int ch, bool allCh, bool withTempHum, bool compen
|
||||
float pm25_comp2 = utils::getInvalidPmValue();
|
||||
if (utils::isValidPm(_pm_25[0].update.avg) &&
|
||||
utils::isValidHumidity(_humidity[0].update.avg)) {
|
||||
pm25_comp1 = ag->pms5003t_1.compensate(_pm_25[0].update.avg, _humidity[0].update.avg);
|
||||
pm25_comp1 = getCorrectedPM25(true, 1, true);
|
||||
pms["channels"]["1"][json_prop_pm25Compensated] = ag->round2(pm25_comp1);
|
||||
}
|
||||
if (utils::isValidPm(_pm_25[1].update.avg) &&
|
||||
utils::isValidHumidity(_humidity[1].update.avg)) {
|
||||
pm25_comp2 = ag->pms5003t_2.compensate(_pm_25[1].update.avg, _humidity[1].update.avg);
|
||||
pm25_comp2 = getCorrectedPM25(true, 2, true);
|
||||
pms["channels"]["2"][json_prop_pm25Compensated] = ag->round2(pm25_comp2);
|
||||
}
|
||||
|
||||
@@ -1186,4 +1521,4 @@ void Measurements::setResetReason(esp_reset_reason_t reason) {
|
||||
|
||||
_resetReason = (int)reason;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Libraries/Arduino_JSON/src/Arduino_JSON.h"
|
||||
#include "Main/utils.h"
|
||||
#include <Arduino.h>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
class Measurements {
|
||||
@@ -37,6 +38,31 @@ public:
|
||||
Measurements(Configuration &config);
|
||||
~Measurements() {}
|
||||
|
||||
struct Measures {
|
||||
float temperature[2];
|
||||
float humidity[2];
|
||||
float co2;
|
||||
float tvoc; // Index value
|
||||
float tvoc_raw;
|
||||
float nox; // Index value
|
||||
float nox_raw;
|
||||
float pm_01[2]; // pm 1.0 atmospheric environment
|
||||
float pm_25[2]; // pm 2.5 atmospheric environment
|
||||
float pm_10[2]; // pm 10 atmospheric environment
|
||||
float pm_01_sp[2]; // pm 1.0 standard particle
|
||||
float pm_25_sp[2]; // pm 2.5 standard particle
|
||||
float pm_10_sp[2]; // pm 10 standard particle
|
||||
float pm_03_pc[2]; // particle count 0.3
|
||||
float pm_05_pc[2]; // particle count 0.5
|
||||
float pm_01_pc[2]; // particle count 1.0
|
||||
float pm_25_pc[2]; // particle count 2.5
|
||||
float pm_5_pc[2]; // particle count 5.0
|
||||
float pm_10_pc[2]; // particle count 10
|
||||
int bootCount;
|
||||
int signal;
|
||||
uint32_t freeHeap;
|
||||
};
|
||||
|
||||
void setAirGradient(AirGradient *ag);
|
||||
|
||||
// Enumeration for every AG measurements
|
||||
@@ -62,6 +88,8 @@ public:
|
||||
PM10_PC, // Particle 10 count
|
||||
};
|
||||
|
||||
void printCurrentAverage();
|
||||
|
||||
/**
|
||||
* @brief Set each MeasurementType maximum period length for moving average
|
||||
*
|
||||
@@ -121,7 +149,7 @@ public:
|
||||
*
|
||||
* @param type measurement type that will be retrieve
|
||||
* @param ch target type value channel
|
||||
* @return moving average value of target measurements type
|
||||
* @return moving average value of target measurements type
|
||||
*/
|
||||
float getAverage(MeasurementType type, int ch = 1);
|
||||
|
||||
@@ -144,15 +172,20 @@ public:
|
||||
*
|
||||
* @param useAvg Use moving average value if true, otherwise use latest value
|
||||
* @param ch MeasurementType channel
|
||||
* @param forceCorrection force using correction even though config correction is not applied, default to EPA
|
||||
* @return float Corrected PM2.5 value
|
||||
*/
|
||||
float getCorrectedPM25(bool useAvg = false, int ch = 1);
|
||||
float getCorrectedPM25(bool useAvg = false, int ch = 1, bool forceCorrection = false);
|
||||
|
||||
/**
|
||||
* build json payload for every measurements
|
||||
*/
|
||||
String toString(bool localServer, AgFirmwareMode fwMode, int rssi);
|
||||
|
||||
Measures getMeasures();
|
||||
|
||||
std::string buildMeasuresPayload(Measures &measures);
|
||||
|
||||
/**
|
||||
* Set to true if want to debug every update value
|
||||
*/
|
||||
@@ -227,6 +260,8 @@ private:
|
||||
*/
|
||||
void validateChannel(int ch);
|
||||
|
||||
void printCurrentPMAverage(int ch);
|
||||
|
||||
JSONVar buildOutdoor(bool localServer, AgFirmwareMode fwMode);
|
||||
JSONVar buildIndoor(bool localServer);
|
||||
JSONVar buildPMS(int ch, bool allCh, bool withTempHum, bool compensate);
|
||||
|
||||
@@ -81,16 +81,15 @@ bool WifiConnector::connect(void) {
|
||||
// ssid = "AG-" + String(ESP.getChipId(), HEX);
|
||||
WIFI()->setConfigPortalTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
|
||||
|
||||
WiFiManagerParameter postToAg("chbPostToAg",
|
||||
"Prevent Connection to AirGradient Server", "T",
|
||||
2, "type=\"checkbox\" ", WFM_LABEL_AFTER);
|
||||
WIFI()->addParameter(&postToAg);
|
||||
WiFiManagerParameter postToAgInfo(
|
||||
WiFiManagerParameter disableCloud("chbPostToAg", "Prevent Connection to AirGradient Server", "T",
|
||||
2, "type=\"checkbox\" ", WFM_LABEL_AFTER);
|
||||
WIFI()->addParameter(&disableCloud);
|
||||
WiFiManagerParameter disableCloudInfo(
|
||||
"<p>Prevent connection to the AirGradient Server. Important: Only enable "
|
||||
"it if you are sure you don't want to use any AirGradient cloud "
|
||||
"features. As a result you will not receive automatic firmware updates "
|
||||
"and your data will not reach the AirGradient dashboard.</p>");
|
||||
WIFI()->addParameter(&postToAgInfo);
|
||||
"features. As a result you will not receive automatic firmware updates, "
|
||||
"configuration settings from cloud and the measure data will not reach the AirGradient dashboard.</p>");
|
||||
WIFI()->addParameter(&disableCloudInfo);
|
||||
|
||||
WIFI()->autoConnect(ssid.c_str(), WIFI_HOTSPOT_PASSWORD_DEFAULT);
|
||||
|
||||
@@ -174,12 +173,11 @@ bool WifiConnector::connect(void) {
|
||||
logInfo("WiFi Connected: " + WiFi.SSID() + " IP: " + localIpStr());
|
||||
|
||||
if (hasPortalConfig) {
|
||||
String result = String(postToAg.getValue());
|
||||
logInfo("Setting postToAirGradient set from " +
|
||||
String(config.isPostDataToAirGradient() ? "True" : "False") +
|
||||
String(" to ") + String(result != "T" ? "True" : "False") +
|
||||
String(" successful"));
|
||||
config.setPostToAirGradient(result != "T");
|
||||
String result = String(disableCloud.getValue());
|
||||
logInfo("Setting disableCloudConnection set from " +
|
||||
String(config.isCloudConnectionDisabled() ? "True" : "False") + String(" to ") +
|
||||
String(result == "T" ? "True" : "False") + String(" successful"));
|
||||
config.setDisableCloudConnection(result == "T");
|
||||
}
|
||||
hasPortalConfig = false;
|
||||
}
|
||||
@@ -360,7 +358,7 @@ bool WifiConnector::isConnected(void) { return WiFi.isConnected(); }
|
||||
* this method
|
||||
*
|
||||
*/
|
||||
void WifiConnector::reset(void) {
|
||||
void WifiConnector::reset(void) {
|
||||
if(this->wifi == NULL) {
|
||||
this->wifi = new WiFiManager();
|
||||
if(this->wifi == NULL){
|
||||
@@ -368,7 +366,7 @@ void WifiConnector::reset(void) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
WIFI()->resetSettings();
|
||||
WIFI()->resetSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -408,7 +406,7 @@ bool WifiConnector::isConfigurePorttalTimeout(void) { return connectorTimeout; }
|
||||
|
||||
/**
|
||||
* @brief Set wifi connect to default WiFi
|
||||
*
|
||||
*
|
||||
*/
|
||||
void WifiConnector::setDefault(void) {
|
||||
WiFi.begin("airgradient", "cleanair");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "AirGradient.h"
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#else
|
||||
#else
|
||||
#include "WiFi.h"
|
||||
#endif
|
||||
|
||||
@@ -57,7 +57,7 @@ String AirGradient::getBoardName(void) {
|
||||
|
||||
/**
|
||||
* @brief Board Type is ONE_INDOOR
|
||||
*
|
||||
*
|
||||
* @return true ONE_INDOOR
|
||||
* @return false Other
|
||||
*/
|
||||
@@ -65,15 +65,15 @@ bool AirGradient::isOne(void) {
|
||||
return boardType == BoardType::ONE_INDOOR;
|
||||
}
|
||||
|
||||
bool AirGradient::isOpenAir(void) {
|
||||
return boardType == BoardType::OPEN_AIR_OUTDOOR;
|
||||
bool AirGradient::isOpenAir(void) {
|
||||
return boardType == BoardType::OPEN_AIR_OUTDOOR;
|
||||
}
|
||||
|
||||
bool AirGradient::isPro4_2(void) {
|
||||
return boardType == BoardType::DIY_PRO_INDOOR_V4_2;
|
||||
}
|
||||
|
||||
bool AirGradient::isPro3_3(void) {
|
||||
bool AirGradient::isPro3_3(void) {
|
||||
return boardType == BoardType::DIY_PRO_INDOOR_V3_3;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
#include "Main/utils.h"
|
||||
|
||||
#ifndef GIT_VERSION
|
||||
#define GIT_VERSION "3.1.21-snap"
|
||||
#define GIT_VERSION "3.3.9-snap"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef ESP8266
|
||||
// Airgradient server root ca certificate
|
||||
const char *const AG_SERVER_ROOT_CA =
|
||||
@@ -176,9 +177,9 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Check that Airgradient object is OPEN_AIR
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool isOpenAir(void);
|
||||
|
||||
|
||||
@@ -95,15 +95,10 @@ enum ConfigurationControl {
|
||||
};
|
||||
|
||||
enum PMCorrectionAlgorithm {
|
||||
Unknown, // Unknown algorithm
|
||||
None, // No PM correction
|
||||
EPA_2021,
|
||||
SLR_PMS5003_20220802,
|
||||
SLR_PMS5003_20220803,
|
||||
SLR_PMS5003_20220824,
|
||||
SLR_PMS5003_20231030,
|
||||
SLR_PMS5003_20231218,
|
||||
SLR_PMS5003_20240104,
|
||||
COR_ALGO_PM_UNKNOWN, // Unknown algorithm
|
||||
COR_ALGO_PM_NONE, // No PM correction
|
||||
COR_ALGO_PM_EPA_2021,
|
||||
COR_ALGO_PM_SLR_CUSTOM,
|
||||
};
|
||||
|
||||
// Don't change the order of the enum
|
||||
|
||||
1
src/Libraries/airgradient-client
Submodule
1
src/Libraries/airgradient-ota
Submodule
@@ -27,7 +27,7 @@ enum BoardType {
|
||||
|
||||
/**
|
||||
* @brief Board definitions
|
||||
*
|
||||
*
|
||||
*/
|
||||
struct BoardDef {
|
||||
/** Board Support CO2 SenseS8 */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
/**
|
||||
* @brief The class define how to handle the LED
|
||||
*
|
||||
*
|
||||
*/
|
||||
class StatusLed {
|
||||
public:
|
||||
|
||||
@@ -260,13 +260,14 @@ bool MqttClient::connect(String id) {
|
||||
connected = false;
|
||||
if (user.isEmpty()) {
|
||||
logInfo("Connect without auth");
|
||||
if(CLIENT()->connect(id.c_str())) {
|
||||
connected = true;
|
||||
}
|
||||
return connected;
|
||||
connected = CLIENT()->connect(id.c_str());
|
||||
} else {
|
||||
logInfo("Connect with auth");
|
||||
connected = CLIENT()->connect(id.c_str(), user.c_str(), password.c_str());
|
||||
}
|
||||
return CLIENT()->connect(id.c_str(), user.c_str(), password.c_str());
|
||||
return connected;
|
||||
}
|
||||
|
||||
void MqttClient::handle(void) {
|
||||
if (isBegin == false) {
|
||||
return;
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
#include "OtaHandler.h"
|
||||
|
||||
#ifndef ESP8266 // Only for esp32 based mcu
|
||||
|
||||
#include "AirGradient.h"
|
||||
|
||||
void OtaHandler::setHandlerCallback(OtaHandlerCallback_t callback) { _callback = callback; }
|
||||
|
||||
void OtaHandler::updateFirmwareIfOutdated(String deviceId) {
|
||||
String url =
|
||||
"https://hw.airgradient.com/sensors/airgradient:" + deviceId + "/generic/os/firmware.bin";
|
||||
url += "?current_firmware=";
|
||||
url += GIT_VERSION;
|
||||
char urlAsChar[URL_BUF_SIZE];
|
||||
url.toCharArray(urlAsChar, URL_BUF_SIZE);
|
||||
Serial.printf("checking for new OTA update @ %s\n", urlAsChar);
|
||||
|
||||
esp_http_client_config_t config = {};
|
||||
config.url = urlAsChar;
|
||||
config.cert_pem = AG_SERVER_ROOT_CA;
|
||||
OtaUpdateOutcome ret = attemptToPerformOta(&config);
|
||||
Serial.println(ret);
|
||||
if (_callback) {
|
||||
switch (ret) {
|
||||
case OtaUpdateOutcome::UPDATE_PERFORMED:
|
||||
_callback(OtaState::OTA_STATE_SUCCESS, "");
|
||||
break;
|
||||
case OtaUpdateOutcome::UPDATE_SKIPPED:
|
||||
_callback(OtaState::OTA_STATE_SKIP, "");
|
||||
break;
|
||||
case OtaUpdateOutcome::ALREADY_UP_TO_DATE:
|
||||
_callback(OtaState::OTA_STATE_UP_TO_DATE, "");
|
||||
break;
|
||||
case OtaUpdateOutcome::UPDATE_FAILED:
|
||||
_callback(OtaState::OTA_STATE_FAIL, "");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OtaHandler::OtaUpdateOutcome
|
||||
OtaHandler::attemptToPerformOta(const esp_http_client_config_t *config) {
|
||||
esp_http_client_handle_t client = esp_http_client_init(config);
|
||||
if (client == NULL) {
|
||||
Serial.println("Failed to initialize HTTP connection");
|
||||
return OtaUpdateOutcome::UPDATE_FAILED;
|
||||
}
|
||||
|
||||
esp_err_t err = esp_http_client_open(client, 0);
|
||||
if (err != ESP_OK) {
|
||||
esp_http_client_cleanup(client);
|
||||
Serial.printf("Failed to open HTTP connection: %s\n", esp_err_to_name(err));
|
||||
return OtaUpdateOutcome::UPDATE_FAILED;
|
||||
}
|
||||
esp_http_client_fetch_headers(client);
|
||||
|
||||
int httpStatusCode = esp_http_client_get_status_code(client);
|
||||
if (httpStatusCode == 304) {
|
||||
Serial.println("Firmware is already up to date");
|
||||
cleanupHttp(client);
|
||||
return OtaUpdateOutcome::ALREADY_UP_TO_DATE;
|
||||
} else if (httpStatusCode != 200) {
|
||||
Serial.printf("Firmware update skipped, the server returned %d\n", httpStatusCode);
|
||||
cleanupHttp(client);
|
||||
return OtaUpdateOutcome::UPDATE_SKIPPED;
|
||||
}
|
||||
|
||||
esp_ota_handle_t update_handle = 0;
|
||||
const esp_partition_t *update_partition = NULL;
|
||||
Serial.println("Starting OTA update ...");
|
||||
update_partition = esp_ota_get_next_update_partition(NULL);
|
||||
if (update_partition == NULL) {
|
||||
Serial.println("Passive OTA partition not found");
|
||||
cleanupHttp(client);
|
||||
return OtaUpdateOutcome::UPDATE_FAILED;
|
||||
}
|
||||
Serial.printf("Writing to partition subtype %d at offset 0x%x\n", update_partition->subtype,
|
||||
update_partition->address);
|
||||
|
||||
err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
|
||||
if (err != ESP_OK) {
|
||||
Serial.printf("esp_ota_begin failed, error=%d\n", err);
|
||||
cleanupHttp(client);
|
||||
return OtaUpdateOutcome::UPDATE_FAILED;
|
||||
}
|
||||
|
||||
esp_err_t ota_write_err = ESP_OK;
|
||||
char *upgrade_data_buf = (char *)malloc(OTA_BUF_SIZE);
|
||||
if (!upgrade_data_buf) {
|
||||
Serial.println("Couldn't allocate memory for data buffer");
|
||||
return OtaUpdateOutcome::UPDATE_FAILED;
|
||||
}
|
||||
|
||||
int binary_file_len = 0;
|
||||
int totalSize = esp_http_client_get_content_length(client);
|
||||
Serial.println("File size: " + String(totalSize) + String(" bytes"));
|
||||
|
||||
// Show display start update new firmware.
|
||||
if (_callback) {
|
||||
_callback(OtaState::OTA_STATE_BEGIN, "");
|
||||
}
|
||||
|
||||
// Download file and write new firmware to OTA partition
|
||||
uint32_t lastUpdate = millis();
|
||||
while (1) {
|
||||
int data_read = esp_http_client_read(client, upgrade_data_buf, OTA_BUF_SIZE);
|
||||
if (data_read == 0) {
|
||||
if (_callback) {
|
||||
_callback(OtaState::OTA_STATE_PROCESSING, String(100));
|
||||
}
|
||||
Serial.println("Connection closed, all data received");
|
||||
break;
|
||||
}
|
||||
if (data_read < 0) {
|
||||
Serial.println("Data read error");
|
||||
if (_callback) {
|
||||
_callback(OtaState::OTA_STATE_FAIL, "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (data_read > 0) {
|
||||
ota_write_err = esp_ota_write(update_handle, (const void *)upgrade_data_buf, data_read);
|
||||
if (ota_write_err != ESP_OK) {
|
||||
if (_callback) {
|
||||
_callback(OtaState::OTA_STATE_FAIL, "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
binary_file_len += data_read;
|
||||
|
||||
int percent = (binary_file_len * 100) / totalSize;
|
||||
uint32_t ms = (uint32_t)(millis() - lastUpdate);
|
||||
if (ms >= 250) {
|
||||
// sm.executeOTA(StateMachine::OtaState::OTA_STATE_PROCESSING, "",
|
||||
// percent);
|
||||
if (_callback) {
|
||||
_callback(OtaState::OTA_STATE_PROCESSING, String(percent));
|
||||
}
|
||||
lastUpdate = millis();
|
||||
}
|
||||
}
|
||||
}
|
||||
free(upgrade_data_buf);
|
||||
cleanupHttp(client);
|
||||
Serial.printf("# of bytes written: %d\n", binary_file_len);
|
||||
|
||||
esp_err_t ota_end_err = esp_ota_end(update_handle);
|
||||
if (ota_write_err != ESP_OK) {
|
||||
Serial.printf("Error: esp_ota_write failed! err=0x%d\n", err);
|
||||
return OtaUpdateOutcome::UPDATE_FAILED;
|
||||
} else if (ota_end_err != ESP_OK) {
|
||||
Serial.printf("Error: esp_ota_end failed! err=0x%d. Image is invalid", ota_end_err);
|
||||
return OtaUpdateOutcome::UPDATE_FAILED;
|
||||
}
|
||||
|
||||
err = esp_ota_set_boot_partition(update_partition);
|
||||
if (err != ESP_OK) {
|
||||
Serial.printf("esp_ota_set_boot_partition failed! err=0x%d\n", err);
|
||||
return OtaUpdateOutcome::UPDATE_FAILED;
|
||||
}
|
||||
return OtaUpdateOutcome::UPDATE_PERFORMED;
|
||||
}
|
||||
|
||||
void OtaHandler::cleanupHttp(esp_http_client_handle_t client) {
|
||||
esp_http_client_close(client);
|
||||
esp_http_client_cleanup(client);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef OTA_HANDLER_H
|
||||
#define OTA_HANDLER_H
|
||||
#ifndef ESP8266 // Only for esp32 based mcu
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_http_client.h>
|
||||
#include <esp_ota_ops.h>
|
||||
|
||||
#define OTA_BUF_SIZE 1024
|
||||
#define URL_BUF_SIZE 256
|
||||
|
||||
class OtaHandler {
|
||||
public:
|
||||
enum OtaState {
|
||||
OTA_STATE_BEGIN,
|
||||
OTA_STATE_FAIL,
|
||||
OTA_STATE_SKIP,
|
||||
OTA_STATE_UP_TO_DATE,
|
||||
OTA_STATE_PROCESSING,
|
||||
OTA_STATE_SUCCESS
|
||||
};
|
||||
|
||||
typedef void (*OtaHandlerCallback_t)(OtaState state, String message);
|
||||
void setHandlerCallback(OtaHandlerCallback_t callback);
|
||||
void updateFirmwareIfOutdated(String deviceId);
|
||||
|
||||
private:
|
||||
OtaHandlerCallback_t _callback;
|
||||
|
||||
enum OtaUpdateOutcome {
|
||||
UPDATE_PERFORMED = 0,
|
||||
ALREADY_UP_TO_DATE,
|
||||
UPDATE_FAILED,
|
||||
UPDATE_SKIPPED
|
||||
}; // Internal use
|
||||
|
||||
OtaUpdateOutcome attemptToPerformOta(const esp_http_client_config_t *config);
|
||||
void cleanupHttp(esp_http_client_handle_t client);
|
||||
};
|
||||
|
||||
#endif // ESP8266
|
||||
#endif // OTA_HANDLER_H
|
||||
@@ -21,10 +21,15 @@ bool PMSBase::begin(Stream *stream) {
|
||||
}
|
||||
Serial.printf("cleared %d byte(s)\n", bytesCleared);
|
||||
|
||||
|
||||
uint8_t command[] = {0x42, 0x4D, 0xE4, 0x00, 0x01, 0x01, 0x74};
|
||||
size_t bytesWritten = stream->write(command, sizeof(command));
|
||||
Serial.printf("%d byte(s) written\n", bytesWritten);
|
||||
|
||||
// explicitly put the sensor into active mode, this seems to be be needed for the Cubic PM2009X
|
||||
Serial.printf("setting active mode\n");
|
||||
uint8_t activeModeCommand[] = { 0x42, 0x4D, 0xE1, 0x00, 0x01, 0x01, 0x71 };
|
||||
size_t bytesWritten = stream->write(activeModeCommand, sizeof(activeModeCommand));
|
||||
uint8_t activeModeCommand[] = {0x42, 0x4D, 0xE1, 0x00, 0x01, 0x01, 0x71};
|
||||
bytesWritten = stream->write(activeModeCommand, sizeof(activeModeCommand));
|
||||
Serial.printf("%d byte(s) written\n", bytesWritten);
|
||||
|
||||
// Run and check sensor data for 4sec
|
||||
@@ -314,12 +319,11 @@ int PMSBase::pm25ToAQI(int pm02) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief SLR correction for PM2.5
|
||||
*
|
||||
* @brief SLR correction for PM2.5
|
||||
*
|
||||
* Reference: https://www.airgradient.com/blog/low-readings-from-pms5003/
|
||||
*
|
||||
*
|
||||
* @param pm25 PM2.5 raw value
|
||||
* @param pm003Count PM0.3 count
|
||||
* @param scalingFactor Scaling factor
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
/** For PMS5003T*/
|
||||
int16_t getTemp(void);
|
||||
uint16_t getHum(void);
|
||||
uint8_t getFirmwareVersion(void);
|
||||
uint8_t getFirmwareVersion(void);
|
||||
uint8_t getErrorCode(void);
|
||||
|
||||
int pm25ToAQI(int pm02);
|
||||
@@ -48,7 +48,7 @@ private:
|
||||
/** In normal package interval is 200-800ms, In case small changed on sensor
|
||||
* it's will interval reach to 2.3sec
|
||||
*/
|
||||
const uint16_t READ_PACKGE_TIMEOUT = 3000; /** ms */
|
||||
const uint16_t READ_PACKGE_TIMEOUT = 3000; /** ms */
|
||||
const int failCountMax = 10;
|
||||
int failCount = 0;
|
||||
|
||||
@@ -76,15 +76,15 @@ private:
|
||||
uint16_t pms_count2_5;
|
||||
uint16_t pms_count5_0;
|
||||
uint16_t pms_count10;
|
||||
int16_t pms_temp;
|
||||
int16_t pms_temp;
|
||||
uint16_t pms_hum;
|
||||
uint8_t pms_errorCode;
|
||||
uint8_t pms_firmwareVersion;
|
||||
uint8_t pms_errorCode;
|
||||
uint8_t pms_firmwareVersion;
|
||||
|
||||
int16_t toI16(const uint8_t *buf);
|
||||
uint16_t toU16(const uint8_t *buf);
|
||||
bool validate(const uint8_t *buf);
|
||||
void parse(const uint8_t* buf);
|
||||
void parse(const uint8_t *buf);
|
||||
};
|
||||
|
||||
#endif /** _PMS5003_BASE_H_ */
|
||||
|
||||
@@ -189,21 +189,21 @@ float PMS5003::compensate(float pm25, float humidity) { return pms.compensate(pm
|
||||
|
||||
/**
|
||||
* @brief Get sensor firmware version
|
||||
*
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMS5003::getFirmwareVersion(void) { return _ver; }
|
||||
|
||||
/**
|
||||
* @brief Get sensor error code
|
||||
*
|
||||
* @return uint8_t
|
||||
*
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t PMS5003::getErrorCode(void) { return pms.getErrorCode(); }
|
||||
|
||||
/**
|
||||
* @brief Is sensor connect with device
|
||||
*
|
||||
*
|
||||
* @return true Connected
|
||||
* @return false Removed
|
||||
*/
|
||||
@@ -255,14 +255,55 @@ void PMS5003::resetFailCount(void) {
|
||||
|
||||
/**
|
||||
* @brief Get number of fail count
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMS5003::getFailCount(void) { return pms.getFailCount(); }
|
||||
|
||||
/**
|
||||
* @brief Get number of fail count max
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMS5003::getFailCountMax(void) { return pms.getFailCountMax(); }
|
||||
|
||||
// Standby mode. For low power consumption and prolong the life of the sensor.
|
||||
void PMS5003::sleep() {
|
||||
uint8_t command[] = {0x42, 0x4D, 0xE4, 0x00, 0x00, 0x01, 0x73};
|
||||
size_t bytesWritten = this->_serial->write(command, sizeof(command));
|
||||
Serial.printf("%d byte(s) written\n", bytesWritten);
|
||||
}
|
||||
|
||||
// Operating mode. Stable data should be got at least 30 seconds after the sensor wakeup from the sleep mode because of the fan's performance.
|
||||
void PMS5003::wakeUp() {
|
||||
uint8_t command[] = {0x42, 0x4D, 0xE4, 0x00, 0x01, 0x01, 0x74};
|
||||
size_t bytesWritten = this->_serial->write(command, sizeof(command));
|
||||
Serial.printf("%d byte(s) written\n", bytesWritten);
|
||||
}
|
||||
|
||||
// Active mode. Default mode after power up. In this mode sensor would send serial data to the host automatically.
|
||||
void PMS5003::activeMode() {
|
||||
uint8_t command[] = {0x42, 0x4D, 0xE1, 0x00, 0x01, 0x01, 0x71};
|
||||
size_t bytesWritten = this->_serial->write(command, sizeof(command));
|
||||
Serial.printf("%d byte(s) written\n", bytesWritten);
|
||||
// _mode = MODE_ACTIVE;
|
||||
}
|
||||
|
||||
// Passive mode. In this mode sensor would send serial data to the host only for request.
|
||||
void PMS5003::passiveMode() {
|
||||
uint8_t command[] = {0x42, 0x4D, 0xE1, 0x00, 0x00, 0x01, 0x70};
|
||||
size_t bytesWritten = this->_serial->write(command, sizeof(command));
|
||||
Serial.printf("%d byte(s) written\n", bytesWritten);
|
||||
// _mode = MODE_PASSIVE;
|
||||
}
|
||||
|
||||
// Request read in Passive Mode.
|
||||
void PMS5003::requestRead() {
|
||||
// if (_mode == MODE_PASSIVE)
|
||||
// {
|
||||
uint8_t command[] = {0x42, 0x4D, 0xE2, 0x00, 0x00, 0x01, 0x71};
|
||||
size_t bytesWritten = this->_serial->write(command, sizeof(command));
|
||||
Serial.printf("%d byte(s) written\n", bytesWritten);
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -19,6 +19,14 @@ public:
|
||||
#else
|
||||
bool begin(HardwareSerial &serial);
|
||||
#endif
|
||||
|
||||
// Modes
|
||||
void sleep();
|
||||
void wakeUp();
|
||||
void activeMode();
|
||||
void passiveMode();
|
||||
void requestRead();
|
||||
|
||||
void end(void);
|
||||
void handle(void);
|
||||
void updateFailCount(void);
|
||||
|
||||
@@ -218,21 +218,21 @@ float PMS5003T::compensate(float pm25, float humidity) { return pms.compensate(p
|
||||
|
||||
/**
|
||||
* @brief Get module(s) firmware version
|
||||
*
|
||||
*
|
||||
* @return int Version code
|
||||
*/
|
||||
int PMS5003T::getFirmwareVersion(void) { return _ver; }
|
||||
|
||||
/**
|
||||
* @brief Get sensor error code
|
||||
*
|
||||
* @return uint8_t
|
||||
*
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t PMS5003T::getErrorCode(void) { return pms.getErrorCode(); }
|
||||
|
||||
/**
|
||||
* @brief Is sensor connect to device
|
||||
*
|
||||
*
|
||||
* @return true Connected
|
||||
* @return false Removed
|
||||
*/
|
||||
@@ -281,14 +281,14 @@ void PMS5003T::resetFailCount(void) {
|
||||
|
||||
/**
|
||||
* @brief Get fail count
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMS5003T::getFailCount(void) { return pms.getFailCount(); }
|
||||
|
||||
/**
|
||||
* @brief Get fail count max
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMS5003T::getFailCountMax(void) { return pms.getFailCountMax(); }
|
||||
|
||||
@@ -6,11 +6,11 @@ PMS5003TBase::~PMS5003TBase() {}
|
||||
|
||||
/**
|
||||
* @brief Compensate the temperature
|
||||
*
|
||||
*
|
||||
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
|
||||
*
|
||||
* @param temp
|
||||
* @return * float
|
||||
*
|
||||
* @param temp
|
||||
* @return * float
|
||||
*/
|
||||
float PMS5003TBase::compensateTemp(float temp) {
|
||||
if (temp < 10.0f) {
|
||||
@@ -21,11 +21,11 @@ float PMS5003TBase::compensateTemp(float temp) {
|
||||
|
||||
/**
|
||||
* @brief Compensate the humidity
|
||||
*
|
||||
*
|
||||
* Reference formula: https://www.airgradient.com/documentation/correction-algorithms/
|
||||
*
|
||||
* @param temp
|
||||
* @return * float
|
||||
*
|
||||
* @param temp
|
||||
* @return * float
|
||||
*/
|
||||
float PMS5003TBase::compensateHum(float hum) {
|
||||
hum = hum * 1.259f + 7.34f;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
class PMS5003TBase
|
||||
{
|
||||
private:
|
||||
|
||||
|
||||
public:
|
||||
PMS5003TBase();
|
||||
~PMS5003TBase();
|
||||
|
||||
@@ -835,3 +835,13 @@ bool S8::setAbcPeriod(int hours) {
|
||||
* @return int Hour
|
||||
*/
|
||||
int S8::getAbcPeriod(void) { return getCalibPeriodABC(); }
|
||||
|
||||
|
||||
void S8::printInformation(void) {
|
||||
Serial.print("S8 type ID: 0x");
|
||||
Serial.println(getSensorTypeId(), HEX);
|
||||
Serial.print("S8 serial number: 0x");
|
||||
Serial.println(getSensorId(), HEX);
|
||||
Serial.print("S8 memory map version: 0x");
|
||||
Serial.println(getMemoryMapVersion(), HEX);
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public:
|
||||
bool isBaseLineCalibrationDone(void);
|
||||
bool setAbcPeriod(int hours);
|
||||
int getAbcPeriod(void);
|
||||
void printInformation(void);
|
||||
|
||||
private:
|
||||
/** Variables */
|
||||
|
||||
@@ -131,6 +131,22 @@ void Sgp41::handle(void) {
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void Sgp41::pause() {
|
||||
onPause = true;
|
||||
Serial.println("Pausing SGP41 handler task");
|
||||
// Set latest value to invalid
|
||||
tvocRaw = utils::getInvalidVOC();
|
||||
tvoc = utils::getInvalidVOC();
|
||||
noxRaw = utils::getInvalidNOx();
|
||||
nox = utils::getInvalidNOx();
|
||||
}
|
||||
|
||||
void Sgp41::resume() {
|
||||
onPause = false;
|
||||
Serial.println("Resuming SGP41 handler task");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle the sensor conditioning and run time udpate value, This method
|
||||
* must not call, it's called on private task
|
||||
@@ -152,6 +168,11 @@ void Sgp41::_handle(void) {
|
||||
uint16_t srawVoc, srawNox;
|
||||
for (;;) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
if (onPause) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (getRawSignal(srawVoc, srawNox)) {
|
||||
tvocRaw = srawVoc;
|
||||
noxRaw = srawNox;
|
||||
|
||||
@@ -18,6 +18,10 @@ public:
|
||||
bool begin(TwoWire &wire, Stream &stream);
|
||||
void handle(void);
|
||||
#else
|
||||
/* pause _handle task to read sensor */
|
||||
void pause();
|
||||
/* resume _handle task to read sensor */
|
||||
void resume();
|
||||
void _handle(void);
|
||||
#endif
|
||||
void end(void);
|
||||
@@ -32,6 +36,7 @@ public:
|
||||
int getTvocLearningOffset(void);
|
||||
|
||||
private:
|
||||
bool onPause = false;
|
||||
bool onConditioning = true;
|
||||
bool ready = false;
|
||||
bool _isBegin = false;
|
||||
|
||||