Compare commits

...

71 Commits
3.0.3 ... 3.0.6

Author SHA1 Message Date
d78205aa20 Changed measurement and update interval for Open Air. Added fw version to logs. 2024-03-02 15:04:30 +07:00
c1228bbd06 Changed measurement and update intervalls 2024-03-02 14:05:00 +07:00
1eb43f684b Fix SHT read error. 2024-03-02 13:41:08 +07:00
4798e44cb7 MDNS replace board with model 2024-03-01 21:56:21 +07:00
a867e9af38 revert SENSOR_TEMP_HUM_UPDATE_INTERVAL value 2024-03-01 19:51:58 +07:00
a59d5a1bb8 Update check.yml
Adjusted new name for example files
2024-02-29 20:05:16 +07:00
b4d6006678 Changed PM polling frequency for Open Air to 2s 2024-02-29 18:30:52 +07:00
236c5bab84 Added offline mode after LED test. 2024-02-29 18:15:22 +07:00
852fdc4360 Renamed example file. 2024-02-29 17:58:58 +07:00
f7e85a92e8 Uped version Nr. Renamed examples. 2024-02-29 17:58:14 +07:00
e99fc2ecdc Merge pull request #69 from airgradienthq/develop
Update API naming
2024-02-29 15:26:53 +07:00
67785ed99b Update API naming 2024-02-29 15:20:19 +07:00
45ac4f116b Merge pull request #68 from airgradienthq/develop
Develop
2024-02-29 15:12:28 +07:00
173e3caf2f Update API naming 2024-02-29 15:07:23 +07:00
351af57591 move pm25ToAQI into PMSUtils 2024-02-29 14:45:44 +07:00
0bda7a1c4b Change pmPoll interval from 5s to 2s 2024-02-29 14:00:19 +07:00
9a31c107fa add get BoardName from AirGradient library 2024-02-29 13:58:48 +07:00
5449fa15ea Merge branch 'master' into develop 2024-02-29 13:50:46 +07:00
3e4e2affa8 Merge pull request #59 from dechamps/prometheus
Add support for Prometheus/OpenMetrics to One V9
2024-02-29 13:47:49 +07:00
d3a242a0b7 Merge branch 'master' into develop 2024-02-29 13:45:45 +07:00
e5e2887c4d Merge pull request #58 from dechamps/githubactions
Add compile check GitHub Actions workflow
2024-02-29 13:41:50 +07:00
4eda2e4cb5 Merge pull request #67 from airgradienthq/develop
Develop
2024-02-29 10:57:10 +07:00
fcee721d58 Merge pull request #66 from airgradienthq/feature/add-mdns-attributes
Add mDNS attribute
2024-02-29 10:56:48 +07:00
7d12e63e34 Merge pull request #65 from airgradienthq/feature/relative-humidity-pms5003t-formula
Feature/relative humidity pms5003t formula
2024-02-29 10:50:21 +07:00
8ff8b7929e Update correction relative humdity formula 2024-02-29 10:49:38 +07:00
66c53daed6 Implement relative humidity correction 2024-02-29 10:39:17 +07:00
5de3a34dd0 Add mDNS attribute 2024-02-29 10:22:05 +07:00
b94112e22a Merge pull request #64 from airgradienthq/feature/led-bar-color-for-pms-and-co2
Feature/led bar color for pms and co2
2024-02-29 09:38:13 +07:00
99e925e7bd Merge pull request #63 from airgradienthq/hotfix/build-fail-if-set-core-debug-level-to-verbose
fix: build fail if set `Core Debug Level` to `Verbose`, #57
2024-02-29 09:34:26 +07:00
d8cba0d346 fix: build fail if set Core Debug Level to Verbose, #57 2024-02-29 09:33:33 +07:00
39de897621 Merge pull request #56 from dechamps/includecap
Fix path capitalization
2024-02-29 09:05:30 +07:00
9f1a793848 Merge pull request #62 from airgradienthq/hotfix/compile-fail-cause-value-type
fix: BoardDef pin number invalid type, #51
2024-02-29 08:49:03 +07:00
be9ba88d52 fix: BoardDef pin number invalid type, #51 2024-02-29 08:45:38 +07:00
0084b6fb91 fix: update cloud sync json noxIndex by nox_index 2024-02-29 08:39:05 +07:00
75b579bafa Merge pull request #61 from airgradienthq/feature/factory-config-reset
add Factory RESET
2024-02-26 17:51:17 +07:00
cf5ff99d8a add Factory RESET 2024-02-26 17:48:22 +07:00
ea204d90b1 Merge pull request #60 from airgradienthq/bugfix/mqtt-sending-interval
fix: Mqtt sending interval
2024-02-26 15:56:30 +07:00
13f6c2c747 fix: Mqtt sending interval 2024-02-26 15:55:33 +07:00
760f827d0d Add support for Prometheus/OpenMetrics to One V9
This commit adds a new feature to the One V9 (ONE_I-9PSL) firmware:
support for exposing metrics to Prometheus (or any other ingestor
compatible with the OpenMetrics format).

With this change, the AirGradient device will make metrics available
on the standard HTTP /metrics endpoint, out-of-the-box, with no need to
do anything else. All the user has to do is add their device address as
a target to their scrape config on their Prometheus server.

For more information on Prometheus and OpenMetrics, see:

- https://prometheus.io/docs/instrumenting/exposition_formats/
- https://openmetrics.io/
- https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md

This obsoletes projects such as:

- ebfa8d0ac6/AirGradient-DIY
- https://forum.airgradient.com/t/prometheus-integration/1504
2024-02-25 17:51:58 +00:00
8c8e0d4dea Add compile check GitHub Actions workflow
This commit adds a GitHub Actions workflow that, on every push/pull
request, will check that every single example successfully compiles on
every board it supports. That is, it it will check compilation on:

- ESP8266 for BASIC_v4, TestCO2, TestPM and TestSht
- ESP32 for ONE_I-9PSL, Open_Air, TestCO2, TestPM and TestSht

This provides the first building block towards a Continuous Integration
(CI) pipeline and prevents build breakages from making it to master.

Ideally this should also run tests on the examples (i.e. verifying that
the example boots successfully and sends metrics), but for now this will
at least ensure the build is not obviously broken.
2024-02-25 12:12:16 +00:00
b749495bf4 Fix path capitalization
This fixes build breakage on case-sensitive filesystems (e.g. Linux)
with errors like:

  src/Display/Display.h:4:10: fatal error: ../main/BoardDef.h: No such file or directory
2024-02-24 21:43:03 +00:00
7e3eabf09f Remove old color set process for PM 2024-02-21 21:18:44 +07:00
e636876c9b Update .gitignore 2024-02-21 21:16:12 +07:00
68953d7390 Update LED for PM and CO2 2024-02-21 21:16:01 +07:00
1a52c2d9f8 Merge pull request #54 from airgradienthq/feature/bugfix-and-example-update
Feature/bugfix and example update
2024-02-21 20:19:54 +07:00
6afcf6d4c3 Udpate version: 3.0.4 2024-02-20 21:06:09 +07:00
af139331b1 Show message when sensor module not found on display 2024-02-20 21:05:13 +07:00
e79a798b88 Update show invalid value into display 2024-02-20 21:05:04 +07:00
14fb790e2a PMS5003 add failed count to 3 before show invalid value to display 2024-02-20 20:36:06 +07:00
2aab02940d add local webserver mDNS airgradient_<devId>.local 2024-02-18 15:20:31 +07:00
da07067661 Save configuration on device persistently 2024-02-18 15:01:30 +07:00
b2091114b3 add serialno to local server data GET response 2024-02-18 12:50:46 +07:00
e09128572c fix: FW stops if some sensor not found 2024-02-18 12:43:37 +07:00
e16966d092 Add webserver to get measure data on example Open_Air 2024-02-18 11:06:06 +07:00
26a8b065bc fix: wifi not connect if LED test with button request 2024-02-18 10:59:01 +07:00
589b98d97e Better server configure for abcDays debug message 2024-02-18 10:49:06 +07:00
cb4d9372f8 Add device webserver to get measure data at <IPAddress>/measures/current 2024-02-18 10:35:20 +07:00
6cb7fa8a1b Fix: capitalize folder and file 2024-02-17 17:34:01 +07:00
6cdbb8a0a3 Fix capitalize folder and file name ignored 2024-02-17 17:28:51 +07:00
781fb51c6f Add mqtt client 2024-02-17 17:19:29 +07:00
17646f3067 Update typo, #49 2024-02-17 14:05:17 +07:00
7a4b665bb5 [Update] optimize display not show on power up or after flash firmware 2024-02-17 13:56:07 +07:00
571b36d05f Optimize Serial nr show and display do not show content after power up or flash firmware 2024-02-17 13:50:22 +07:00
23513cf88c Add parameter tvoc_raw for SGP41 2024-02-17 13:36:32 +07:00
b475c5c1ec capitalize folder names and file names Same like class file names 2024-02-17 13:17:45 +07:00
ee9f26ee04 Update multiple typos, #50 2024-02-17 13:02:24 +07:00
8c94cea764 round real value with 2 decimal on server sync data json 2024-02-17 12:47:51 +07:00
7c63af5ba9 Add Serial Nr into log 2024-02-17 12:11:44 +07:00
7c1eae83e4 Add logging for abcDays 2024-02-17 12:04:11 +07:00
e48ff0e41c Fix model PST send data to cloud with channel 2024-02-17 10:45:56 +07:00
c9e3a2a9b4 Rename example Open_Air_O to Open_Air 2024-02-17 10:38:10 +07:00
251 changed files with 2839 additions and 1273 deletions

51
.github/workflows/check.yml vendored Normal file
View File

@ -0,0 +1,51 @@
on: [push, pull_request]
jobs:
compile:
strategy:
fail-fast: false
matrix:
example:
- "BASIC"
- "ONE"
- "Open_Air"
- "TestCO2"
- "TestPM"
- "TestSht"
fqbn:
- "esp8266:esp8266:d1_mini"
- "esp32:esp32:esp32c3"
include:
- fqbn: "esp8266:esp8266:d1_mini"
core: "esp8266:esp8266@3.1.2"
core_url: "https://arduino.esp8266.com/stable/package_esp8266com_index.json"
- fqbn: "esp32:esp32:esp32c3"
board_options: "JTAGAdapter=default,CDCOnBoot=cdc,PartitionScheme=default,CPUFreq=160,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=verbose,EraseFlash=none"
core: "esp32:esp32@2.0.11"
exclude:
- example: "BASIC_v4"
fqbn: "esp32:esp32:esp32c3"
- example: "ONE_I-9PSL"
fqbn: "esp8266:esp8266:d1_mini"
- example: "Open_Air"
fqbn: "esp8266:esp8266:d1_mini"
runs-on: ubuntu-latest
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
- 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 }}'
# 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
# "hardware lab" runner that is directly connected to a relevant device.

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
.vscode
*.DS_Store
build
.vscode

View File

@ -50,7 +50,7 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#define SENSOR_TVOC_UPDATE_INTERVAL 1000 /** ms */
#define SENSOR_CO2_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_PM_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_TEMP_HUM_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_TEMP_HUM_UPDATE_INTERVAL 2000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 2000 /** ms */
#define WIFI_HOTSPOT_PASSWORD_DEFAULT \
"cleanair" /** default WiFi AP password \
@ -79,8 +79,8 @@ public:
/** Call handler */
handler();
Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n",
(unsigned int)handler, period);
// Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n",
// (unsigned int)handler, period);
/** Update period time */
count = millis();
@ -115,7 +115,7 @@ public:
* @return true Success
* @return false Failure
*/
bool pollServerConfig(String id) {
bool fetchServerConfiguration(String id) {
String uri =
"http://hw.airgradient.com/sensors/airgradient:" + id + "/one/config";
@ -271,7 +271,7 @@ public:
bool isPMSinUSAQI(void) { return inUSAQI; }
/**
* @brief Get status of get server coniguration is failed
* @brief Get status of get server configuration is failed
*
* @return true Failed
* @return false Success
@ -305,7 +305,7 @@ public:
*
* @return int days, -1 if invalid.
*/
int getCo2Abccalib(void) { return co2AbcCalib; }
int getCo2AbcDaysConfig(void) { return co2AbcCalib; }
/**
* @brief Get device configuration model name
@ -359,7 +359,7 @@ AirGradient ag = AirGradient(DIY_BASIC);
static int co2Ppm = -1;
static int pm25 = -1;
static float temp = -1;
static float temp = -1001;
static int hum = -1;
static long val;
static String wifiSSID = "";
@ -368,24 +368,30 @@ static bool wifiHasConfig = false; /** */
static void boardInit(void);
static void failedHandler(String msg);
static void co2Calibration(void);
static void serverConfigPoll(void);
static void co2Poll(void);
static void pmPoll(void);
static void tempHumPoll(void);
static void updateServerConfiguration(void);
static void co2Update(void);
static void pmUpdate(void);
static void tempHumUpdate(void);
static void sendDataToServer(void);
static void dispHandler(void);
static String getDevId(void);
static void updateWiFiConnect(void);
static void showNr(void);
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, serverConfigPoll);
bool hasSensorS8 = true;
bool hasSensorPMS = true;
bool hasSensorSHT = true;
int pmFailCount = 0;
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, updateServerConfiguration);
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
AgSchedule dispSchedule(DISP_UPDATE_INTERVAL, dispHandler);
AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Poll);
AgSchedule pmsSchedule(SENSOR_PM_UPDATE_INTERVAL, pmPoll);
AgSchedule tempHumSchedule(SENSOR_TEMP_HUM_UPDATE_INTERVAL, tempHumPoll);
AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update);
AgSchedule pmsSchedule(SENSOR_PM_UPDATE_INTERVAL, pmUpdate);
AgSchedule tempHumSchedule(SENSOR_TEMP_HUM_UPDATE_INTERVAL, tempHumUpdate);
void setup() {
Serial.begin(115200);
showNr();
/** Init I2C */
Wire.begin(ag.getI2cSdaPin(), ag.getI2cSclPin());
@ -407,7 +413,7 @@ void setup() {
wifiHasConfig = true;
sendPing();
agServer.pollServerConfig(getDevId());
agServer.fetchServerConfiguration(getDevId());
if (agServer.isCo2Calib()) {
co2Calibration();
}
@ -436,9 +442,15 @@ void loop() {
configSchedule.run();
serverSchedule.run();
dispSchedule.run();
if (hasSensorS8) {
co2Schedule.run();
}
if (hasSensorPMS) {
pmsSchedule.run();
}
if (hasSensorSHT) {
tempHumSchedule.run();
}
updateWiFiConnect();
}
@ -469,6 +481,7 @@ void displayShowText(String ln1, String ln2, String ln3) {
ag.display.setText(ln3);
ag.display.show();
delay(100);
}
// Wifi Manager
@ -507,22 +520,28 @@ void connectToWifi() {
static void boardInit(void) {
/** Init SHT sensor */
if (ag.sht.begin(Wire) == false) {
failedHandler("SHT init failed");
hasSensorSHT = false;
Serial.println("SHT sensor not found");
}
/** CO2 init */
if (ag.s8.begin(&Serial) == false) {
failedHandler("SenseAirS8 init failed");
Serial.println("CO2 S8 snsor not found");
hasSensorS8 = false;
}
/** PMS init */
if (ag.pms5003.begin(&Serial) == false) {
failedHandler("PMS5003 init failed");
Serial.println("PMS sensor not found");
hasSensorPMS = false;
}
/** Display init */
ag.display.begin(Wire);
ag.display.setTextColor(1);
ag.display.clear();
ag.display.show();
delay(100);
}
static void failedHandler(String msg) {
@ -557,34 +576,59 @@ static void co2Calibration(void) {
}
}
static void serverConfigPoll(void) {
if (agServer.pollServerConfig(getDevId())) {
static void updateServerConfiguration(void) {
if (agServer.fetchServerConfiguration(getDevId())) {
if (agServer.isCo2Calib()) {
if (hasSensorS8) {
co2Calibration();
} else {
Serial.println("CO2 S8 not available, calib ignored");
}
if (agServer.getCo2Abccalib() > 0) {
if (ag.s8.setAutoCalib(agServer.getCo2Abccalib() * 24) == false) {
Serial.println("Set S8 auto calib failed");
}
if (agServer.getCo2AbcDaysConfig() > 0) {
if (hasSensorS8) {
int newHour = agServer.getCo2AbcDaysConfig() * 24;
Serial.printf("abcDays config: %d days(%d hours)\r\n",
agServer.getCo2AbcDaysConfig(), newHour);
int curHour = ag.s8.getAbcPeriod();
Serial.printf("Current config: %d (hours)\r\n", ag.s8.getAbcPeriod());
if (curHour == newHour) {
Serial.println("set 'abcDays' ignored");
} else {
if (ag.s8.setAbcPeriod(agServer.getCo2AbcDaysConfig() * 24) ==
false) {
Serial.println("Set S8 abcDays period calib failed");
} else {
Serial.println("Set S8 abcDays period calib success");
}
}
} else {
Serial.println("CO2 S8 not available, set 'abcDays' ignored");
}
}
}
}
static void co2Poll() {
static void co2Update() {
co2Ppm = ag.s8.getCo2();
Serial.printf("CO2 index: %d\r\n", co2Ppm);
}
void pmPoll() {
void pmUpdate() {
if (ag.pms5003.readData()) {
pm25 = ag.pms5003.getPm25Ae();
Serial.printf("PMS2.5: %d\r\n", pm25);
pmFailCount = 0;
} else {
Serial.printf("PM read failed, %d", pmFailCount);
pmFailCount++;
if (pmFailCount >= 3) {
pm25 = -1;
}
}
}
static void tempHumPoll() {
static void tempHumUpdate() {
if (ag.sht.measure()) {
temp = ag.sht.getTemperature();
hum = ag.sht.getRelativeHumidity();
@ -604,8 +648,8 @@ static void sendDataToServer() {
if (pm25 >= 0) {
root["pm02"] = pm25;
}
if (temp >= 0) {
root["atmp"] = temp;
if (temp > -1001) {
root["atmp"] = ag.round2(temp);
}
if (hum >= 0) {
root["rhum"] = hum;
@ -622,16 +666,42 @@ static void dispHandler() {
String ln3 = "";
if (agServer.isPMSinUSAQI()) {
if (pm25 < 0) {
ln1 = "AQI: -";
} else {
ln1 = "AQI:" + String(ag.pms5003.convertPm25ToUsAqi(pm25));
}
} else {
if (pm25 < 0) {
ln1 = "PM :- ug";
} else {
ln1 = "PM :" + String(pm25) + " ug";
}
}
if (co2Ppm > -1001) {
ln2 = "CO2:" + String(co2Ppm);
} else {
ln2 = "CO2: -";
}
String _hum = "-";
if (hum > 0) {
_hum = String(hum);
}
String _temp = "-";
if (agServer.isTemperatureUnitF()) {
ln3 = String((temp * 9 / 5) + 32).substring(0, 4) + " " + String(hum) + "%";
if (temp > -1001) {
_temp = String((temp * 9 / 5) + 32).substring(0, 4);
}
ln3 = _temp + " " + _hum + "%";
} else {
ln3 = String(temp).substring(0, 4) + " " + String(hum) + "%";
if (temp > -1001) {
_temp = String(temp).substring(0, 4);
}
ln3 = _temp + " " + _hum + "%";
}
displayShowText(ln1, ln2, ln3);
}
@ -659,6 +729,11 @@ static void updateWiFiConnect(void) {
}
}
static void showNr(void) {
Serial.println();
Serial.println("Serial nr: " + getDevId());
}
String getNormalizedMac() {
String mac = WiFi.macAddress();
mac.replace(":", "");

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,974 +0,0 @@
/*
This is the code for the AirGradient Open Air open-source hardware outdoor Air
Quality Monitor with an ESP32-C3 Microcontroller.
It is an air quality monitor for PM2.5, CO2, TVOCs, NOx, Temperature and
Humidity and can send data over Wifi.
Open source air quality monitors and kits are available:
Indoor Monitor: https://www.airgradient.com/indoor/
Outdoor Monitor: https://www.airgradient.com/outdoor/
Build Instructions:
https://www.airgradient.com/documentation/open-air-pst-kit-1-3/
The codes needs the following libraries installed:
“WifiManager by tzapu, tablatronix” tested with version 2.0.16-rc.2
"Arduino_JSON" by Arduino Version 0.2.0
Please make sure you have esp32 board manager installed. Tested with
version 2.0.11.
Important flashing settings:
- Set board to "ESP32C3 Dev Module"
- Enable "USB CDC On Boot"
- Flash frequency "80Mhz"
- Flash mode "QIO"
- Flash size "4MB"
- Partition scheme "Default 4MB with spiffs (1.2MB APP/1,5MB SPIFFS)"
- JTAG adapter "Disabled"
If you have any questions please visit our forum at
https://forum.airgradient.com/
CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
*/
#include <AirGradient.h>
#include <Arduino_JSON.h>
#include <HTTPClient.h>
#include <HardwareSerial.h>
#include <WiFiManager.h>
#include <Wire.h>
/**
*
* @brief Application state machine state
*
*/
enum {
APP_SM_WIFI_MANAGER_MODE, /** In WiFi Manger Mode */
APP_SM_WIFI_MAMAGER_PORTAL_ACTIVE, /** WiFi Manager has connected to mobile
phone */
APP_SM_WIFI_MANAGER_STA_CONNECTING, /** After SSID and PW entered and OK
clicked, connection to WiFI network is
attempted*/
APP_SM_WIFI_MANAGER_STA_CONNECTED, /** Connecting to WiFi worked */
APP_SM_WIFI_OK_SERVER_CONNECTING, /** Once connected to WiFi an attempt to
reach the server is performed */
APP_SM_WIFI_OK_SERVER_CONNNECTED, /** Server is reachable, all fine */
/** Exceptions during WIFi Setup */
APP_SM_WIFI_MANAGER_CONNECT_FAILED, /** Cannot connect to WiFi (e.g. wrong
password, WPA Enterprise etc.) */
APP_SM_WIFI_OK_SERVER_CONNECT_FAILED, /** Connected to WiFi but server not
reachable, e.g. firewall block/
whitelisting needed etc. */
APP_SM_WIFI_OK_SERVER_OK_SENSOR_CONFIG_FAILED, /** Server reachable but sensor
not configured correctly*/
/** During Normal Operation */
APP_SM_WIFI_LOST, /** Connection to WiFi network failed credentials incorrect
encryption not supported etc. */
APP_SM_SERVER_LOST, /** Connected to WiFi network but the server cannot be
reached through the internet, e.g. blocked by firewall
*/
APP_SM_SENSOR_CONFIG_FAILED, /** Server is reachable but there is some
configuration issue to be fixed on the server
side */
APP_SM_NORMAL,
};
#define LED_FAST_BLINK_DELAY 250 /** ms */
#define LED_SLOW_BLINK_DELAY 1000 /** ms */
#define WIFI_CONNECT_COUNTDOWN_MAX 180 /** sec */
#define WIFI_CONNECT_RETRY_MS 10000 /** ms */
#define LED_BAR_COUNT_INIT_VALUE (-1) /** */
#define LED_BAR_ANIMATION_PERIOD 100 /** ms */
#define DISP_UPDATE_INTERVAL 5000 /** ms */
#define SERVER_CONFIG_UPDATE_INTERVAL 30000 /** ms */
#define SERVER_SYNC_INTERVAL 60000 /** ms */
#define SENSOR_CO2_CALIB_COUNTDOWN_MAX 5 /** sec */
#define SENSOR_TVOC_UPDATE_INTERVAL 1000 /** ms */
#define SENSOR_CO2_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_PM_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_TEMP_HUM_UPDATE_INTERVAL 5000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 2000 /** ms */
#define WIFI_HOTSPOT_PASSWORD_DEFAULT \
"cleanair" /** default WiFi AP password \
*/
/**
* @brief Use use LED bar state
*/
typedef enum {
UseLedBarOff, /** Don't use LED bar */
UseLedBarPM, /** Use LED bar for PMS */
UseLedBarCO2, /** Use LED bar for CO2 */
} UseLedBar;
/**
* @brief Schedule handle with timing period
*
*/
class AgSchedule {
public:
AgSchedule(int period, void (*handler)(void))
: period(period), handler(handler) {}
void run(void) {
uint32_t ms = (uint32_t)(millis() - count);
if (ms >= period) {
/** Call handler */
handler();
Serial.printf("[AgSchedule] handle 0x%08x, period: %d(ms)\r\n",
(unsigned int)handler, period);
/** Update period time */
count = millis();
}
}
void setPeriod(int period) { this->period = period; }
private:
void (*handler)(void);
int period;
int count;
};
/**
* @brief AirGradient server configuration and sync data
*
*/
class AgServer {
public:
void begin(void) {
inF = false;
inUSAQI = false;
configFailed = false;
serverFailed = false;
memset(models, 0, sizeof(models));
memset(mqttBroker, 0, sizeof(mqttBroker));
}
/**
* @brief Get server configuration
*
* @param id Device ID
* @return true Success
* @return false Failure
*/
bool pollServerConfig(String id) {
String uri =
"http://hw.airgradient.com/sensors/airgradient:" + id + "/one/config";
/** Init http client */
HTTPClient client;
if (client.begin(uri) == false) {
configFailed = true;
return false;
}
/** Get */
int retCode = client.GET();
if (retCode != 200) {
client.end();
configFailed = true;
return false;
}
/** clear failed */
configFailed = false;
/** Get response string */
String respContent = client.getString();
client.end();
Serial.println("Get server config: " + respContent);
/** Parse JSON */
JSONVar root = JSON.parse(respContent);
if (JSON.typeof(root) == "undefined") {
/** JSON invalid */
return false;
}
/** Get "country" */
if (JSON.typeof_(root["country"]) == "string") {
String country = root["country"];
if (country == "US") {
inF = true;
} else {
inF = false;
}
}
/** Get "pmStandard" */
if (JSON.typeof_(root["pmStandard"]) == "string") {
String standard = root["pmStandard"];
if (standard == "ugm3") {
inUSAQI = false;
} else {
inUSAQI = true;
}
}
/** Get "co2CalibrationRequested" */
if (JSON.typeof_(root["co2CalibrationRequested"]) == "boolean") {
co2Calib = root["co2CalibrationRequested"];
}
/** Get "ledBarMode" */
if (JSON.typeof_(root["ledBarMode"]) == "string") {
String mode = root["ledBarMode"];
if (mode == "co2") {
ledBarMode = UseLedBarCO2;
} else if (mode == "pm") {
ledBarMode = UseLedBarPM;
} else if (mode == "off") {
ledBarMode = UseLedBarOff;
} else {
ledBarMode = UseLedBarOff;
}
}
/** Get model */
if (JSON.typeof_(root["model"]) == "string") {
String model = root["model"];
if (model.length()) {
int len =
model.length() < sizeof(models) ? model.length() : sizeof(models);
memset(models, 0, sizeof(models));
memcpy(models, model.c_str(), len);
}
}
/** Get "mqttBrokerUrl" */
if (JSON.typeof_(root["mqttBrokerUrl"]) == "string") {
String mqtt = root["mqttBrokerUrl"];
if (mqtt.length()) {
int len = mqtt.length() < sizeof(mqttBroker) ? mqtt.length()
: sizeof(mqttBroker);
memset(mqttBroker, 0, sizeof(mqttBroker));
memcpy(mqttBroker, mqtt.c_str(), len);
}
}
/** Get 'abcDays' */
if (JSON.typeof_(root["abcDays"]) == "number") {
co2AbcCalib = root["abcDays"];
} else {
co2AbcCalib = -1;
}
/** Show configuration */
showServerConfig();
return true;
}
bool postToServer(String id, String payload) {
/**
* @brief Only post data if WiFi is connected
*/
if (WiFi.isConnected() == false) {
return false;
}
Serial.printf("Post payload: %s\r\n", payload.c_str());
String uri =
"http://hw.airgradient.com/sensors/airgradient:" + id + "/measures";
WiFiClient wifiClient;
HTTPClient client;
if (client.begin(wifiClient, uri.c_str()) == false) {
return false;
}
client.addHeader("content-type", "application/json");
int retCode = client.POST(payload);
client.end();
if ((retCode == 200) || (retCode == 429)) {
serverFailed = false;
return true;
}
serverFailed = true;
return false;
}
/**
* @brief Get temperature configuration unit
*
* @return true F unit
* @return false C Unit
*/
bool isTemperatureUnitF(void) { return inF; }
/**
* @brief Get PMS standard unit
*
* @return true USAQI
* @return false ugm3
*/
bool isPMSinUSAQI(void) { return inUSAQI; }
/**
* @brief Get status of get server coniguration is failed
*
* @return true Failed
* @return false Success
*/
bool isConfigFailed(void) { return configFailed; }
/**
* @brief Get status of post server configuration is failed
*
* @return true Failed
* @return false Success
*/
bool isServerFailed(void) { return serverFailed; }
/**
* @brief Get request calibration CO2
*
* @return true Requested. If result = true, it's clear after function call
* @return false Not-requested
*/
bool isCo2Calib(void) {
bool ret = co2Calib;
if (ret) {
co2Calib = false;
}
return ret;
}
/**
* @brief Get the Co2 auto calib period
*
* @return int days, -1 if invalid.
*/
int getCo2Abccalib(void) { return co2AbcCalib; }
/**
* @brief Get device configuration model name
*
* @return String Model name, empty string if server failed
*/
String getModelName(void) { return String(models); }
/**
* @brief Get mqttBroker url
*
* @return String Broker url, empty if server failed
*/
String getMqttBroker(void) { return String(mqttBroker); }
/**
* @brief Show server configuration parameter
*/
void showServerConfig(void) {
Serial.println("Server configuration: ");
Serial.printf(" inF: %s\r\n", inF ? "true" : "false");
Serial.printf(" inUSAQI: %s\r\n", inUSAQI ? "true" : "false");
Serial.printf(" useRGBLedBar: %d\r\n", (int)ledBarMode);
Serial.printf(" Model: %s\r\n", models);
Serial.printf(" Mqtt Broker: %s\r\n", mqttBroker);
Serial.printf(" S8 calib period: %d\r\n", co2AbcCalib);
}
/**
* @brief Get server config led bar mode
*
* @return UseLedBar
*/
UseLedBar getLedBarMode(void) { return ledBarMode; }
private:
bool inF; /** Temperature unit, true: F, false: C */
bool inUSAQI; /** PMS unit, true: USAQI, false: ugm3 */
bool configFailed; /** Flag indicate get server configuration failed */
bool serverFailed; /** Flag indicate post data to server failed */
bool co2Calib; /** Is co2Ppmcalibration requset */
int co2AbcCalib = -1; /** update auto calibration number of day */
UseLedBar ledBarMode = UseLedBarCO2; /** */
char models[20]; /** */
char mqttBroker[256]; /** */
};
AgServer agServer;
/** Create airgradient instance for 'OPEN_AIR_OUTDOOR' board */
AirGradient ag(OPEN_AIR_OUTDOOR);
static int ledSmState = APP_SM_NORMAL;
int loopCount = 0;
WiFiManager wifiManager; /** wifi manager instance */
static bool wifiHasConfig = false;
static String wifiSSID = "";
int tvocIndex = -1;
int noxIndex = -1;
int co2Ppm = 0;
int pm25_1 = -1;
int pm01_1 = -1;
int pm10_1 = -1;
int pm03PCount_1 = -1;
float temp_1;
int hum_1;
int pm25_2 = -1;
int pm01_2 = -1;
int pm10_2 = -1;
int pm03PCount_2 = -1;
float temp_2;
int hum_2;
int pm1Value01;
int pm1Value25;
int pm1Value10;
int pm1PCount;
int pm1temp;
int pm1hum;
int pm2Value01;
int pm2Value25;
int pm2Value10;
int pm2PCount;
int pm2temp;
int pm2hum;
int countPosition;
const int targetCount = 20;
enum {
FW_MODE_PST, /** PMS5003T, S8 and SGP41 */
FW_MODE_PPT, /** PMS5003T_1, PMS5003T_2, SGP41 */
FW_MODE_PP /** PMS5003T_1, PMS5003T_2 */
};
int fw_mode = FW_MODE_PST;
void boardInit(void);
void failedHandler(String msg);
void co2Calibration(void);
static String getDevId(void);
static void updateWiFiConnect(void);
static void tvocPoll(void);
static void pmPoll(void);
static void sendDataToServer(void);
static void co2Poll(void);
static void serverConfigPoll(void);
static const char *getFwMode(int mode);
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, serverConfigPoll);
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Poll);
AgSchedule pmsSchedule(SENSOR_PM_UPDATE_INTERVAL, pmPoll);
AgSchedule tvocSchedule(SENSOR_TVOC_UPDATE_INTERVAL, tvocPoll);
void setup() {
Serial.begin(115200);
/** Board init */
boardInit();
/** Server init */
agServer.begin();
/** WiFi connect */
connectToWifi();
if (WiFi.isConnected()) {
wifiHasConfig = true;
sendPing();
agServer.pollServerConfig(getDevId());
if (agServer.isConfigFailed()) {
ledSmHandler(APP_SM_WIFI_OK_SERVER_OK_SENSOR_CONFIG_FAILED);
delay(DISPLAY_DELAY_SHOW_CONTENT_MS);
}
}
ledSmHandler(APP_SM_NORMAL);
}
void loop() {
configSchedule.run();
serverSchedule.run();
if (fw_mode == FW_MODE_PST) {
co2Schedule.run();
}
pmsSchedule.run();
if (fw_mode == FW_MODE_PST || fw_mode == FW_MODE_PPT) {
tvocSchedule.run();
}
updateWiFiConnect();
}
void sendPing() {
JSONVar root;
root["wifi"] = WiFi.RSSI();
root["boot"] = loopCount;
if (agServer.postToServer(getDevId(), JSON.stringify(root))) {
ledSmHandler(APP_SM_WIFI_OK_SERVER_CONNNECTED);
} else {
ledSmHandler(APP_SM_WIFI_OK_SERVER_CONNECT_FAILED);
}
delay(DISPLAY_DELAY_SHOW_CONTENT_MS);
}
static void sendDataToServer(void) {
JSONVar root;
root["wifi"] = WiFi.RSSI();
root["boot"] = loopCount;
if (fw_mode == FW_MODE_PST) {
if (co2Ppm >= 0) {
root["rco2"] = co2Ppm;
}
if (pm01_1 >= 0) {
root["pm01"] = pm01_1;
}
if (pm25_1 >= 0) {
root["pm02"] = pm25_1;
}
if (pm10_1 >= 0) {
root["pm10"] = pm10_1;
}
if (pm03PCount_1 >= 0) {
root["pm003_count"] = pm03PCount_1;
}
if (tvocIndex >= 0) {
root["tvoc_index"] = tvocIndex;
}
if (noxIndex >= 0) {
root["noxIndex"] = noxIndex;
}
if (temp_1 >= 0) {
root["atmp"] = temp_1;
}
if (hum_1 >= 0) {
root["rhum"] = hum_1;
}
} else if (fw_mode == FW_MODE_PPT) {
if (tvocIndex > 0) {
root["tvoc_index"] = loopCount;
}
if (noxIndex > 0) {
root["nox_index"] = loopCount;
}
}
if (fw_mode == FW_MODE_PP || FW_MODE_PPT) {
root["pm01"] = (int)((pm01_1 + pm01_2) / 2);
root["pm02"] = (int)((pm25_1 + pm25_2) / 2);
root["pm003_count"] = (int)((pm03PCount_1 + pm03PCount_2) / 2);
root["atmp"] = (int)((temp_1 + temp_2) / 2);
root["rhum"] = (int)((hum_1 + hum_2) / 2);
root["channels"]["1"]["pm01"] = pm01_1;
root["channels"]["1"]["pm02"] = pm25_1;
root["channels"]["1"]["pm10"] = pm10_1;
root["channels"]["1"]["pm003_count"] = pm03PCount_1;
root["channels"]["1"]["atmp"] = temp_1;
root["channels"]["1"]["rhum"] = hum_1;
root["channels"]["2"]["pm01"] = pm01_2;
root["channels"]["2"]["pm02"] = pm25_2;
root["channels"]["2"]["pm10"] = pm10_2;
root["channels"]["2"]["pm003_count"] = pm03PCount_2;
root["channels"]["2"]["atmp"] = temp_2;
root["channels"]["2"]["rhum"] = hum_2;
}
/** Send data to sensor */
if (agServer.postToServer(getDevId(), JSON.stringify(root))) {
resetWatchdog();
}
loopCount++;
}
void resetWatchdog() {
Serial.println("Watchdog reset");
ag.watchdog.reset();
}
bool wifiMangerClientConnected(void) {
return WiFi.softAPgetStationNum() ? true : false;
}
// Wifi Manager
void connectToWifi() {
wifiSSID = "airgradient-" + String(getNormalizedMac());
wifiManager.setConfigPortalBlocking(false);
wifiManager.setTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
wifiManager.setAPCallback([](WiFiManager *obj) {
/** This callback if wifi connnected failed and try to start configuration
* portal */
ledSmState = APP_SM_WIFI_MANAGER_MODE;
});
wifiManager.setSaveConfigCallback([]() {
/** Wifi connected save the configuration */
ledSmHandler(APP_SM_WIFI_MANAGER_STA_CONNECTED);
});
wifiManager.setSaveParamsCallback([]() {
/** Wifi set connect: ssid, password */
ledSmHandler(APP_SM_WIFI_MANAGER_STA_CONNECTING);
});
wifiManager.autoConnect(wifiSSID.c_str(), WIFI_HOTSPOT_PASSWORD_DEFAULT);
xTaskCreate(
[](void *obj) {
while (wifiManager.getConfigPortalActive()) {
wifiManager.process();
}
vTaskDelete(NULL);
},
"wifi_cfg", 4096, NULL, 10, NULL);
uint32_t stimer = millis();
bool clientConnectChanged = false;
while (wifiManager.getConfigPortalActive()) {
if (WiFi.isConnected() == false) {
if (ledSmState == APP_SM_WIFI_MANAGER_MODE) {
uint32_t ms = (uint32_t)(millis() - stimer);
if (ms >= 100) {
stimer = millis();
ledSmHandler(ledSmState);
}
}
/** Check for client connect to change led color */
bool clientConnected = wifiMangerClientConnected();
if (clientConnected != clientConnectChanged) {
clientConnectChanged = clientConnected;
if (clientConnectChanged) {
ledSmHandler(APP_SM_WIFI_MAMAGER_PORTAL_ACTIVE);
} else {
ledSmHandler(APP_SM_WIFI_MANAGER_MODE);
}
}
}
}
/** Show display wifi connect result failed */
ag.statusLed.setOff();
delay(2000);
if (WiFi.isConnected() == false) {
ledSmHandler(APP_SM_WIFI_MANAGER_CONNECT_FAILED);
}
}
String getNormalizedMac() {
String mac = WiFi.macAddress();
mac.replace(":", "");
mac.toLowerCase();
return mac;
}
void boardInit(void) {
if (Wire.begin(ag.getI2cSdaPin(), ag.getI2cSclPin()) == false) {
failedHandler("Init I2C failed");
}
ag.watchdog.begin();
ag.button.begin();
ag.statusLed.begin();
/** detect sensor: PMS5003, PMS5003T, SGP41 and S8 */
if (ag.s8.begin(Serial1) == false) {
Serial.println("S8 not detect run mode 'PPT'");
fw_mode = FW_MODE_PPT;
/** De-initialize Serial1 */
Serial1.end();
}
if (ag.sgp41.begin(Wire) == false) {
if (fw_mode == FW_MODE_PST) {
failedHandler("Init SGP41 failed");
} else {
Serial.println("SGP41 not detect run mode 'PP'");
fw_mode = FW_MODE_PP;
}
}
if (ag.pms5003t_1.begin(Serial0) == false) {
failedHandler("Init PMS5003T_1 failed");
}
if (fw_mode != FW_MODE_PST) {
if (ag.pms5003t_2.begin(Serial1) == false) {
failedHandler("Init PMS5003T_2 failed");
}
}
if (fw_mode != FW_MODE_PST) {
pmsSchedule.setPeriod(2000);
}
Serial.printf("Firmware node: %s\r\n", getFwMode(fw_mode));
}
void failedHandler(String msg) {
while (true) {
Serial.println(msg);
vTaskDelay(1000);
}
}
void co2Calibration(void) {
/** Count down for co2CalibCountdown secs */
for (int i = 0; i < SENSOR_CO2_CALIB_COUNTDOWN_MAX; i++) {
Serial.printf("Start CO2 calib after %d sec\r\n",
SENSOR_CO2_CALIB_COUNTDOWN_MAX - i);
delay(1000);
}
if (ag.s8.setBaselineCalibration()) {
Serial.println("Calibration success");
delay(1000);
Serial.println("Wait for calib finish...");
int count = 0;
while (ag.s8.isBaseLineCalibrationDone() == false) {
delay(1000);
count++;
}
Serial.printf("Calib finish after %d sec\r\n", count);
delay(2000);
} else {
Serial.println("Calibration failure!!!");
delay(2000);
}
}
/**
* @brief WiFi reconnect handler
*/
static void updateWiFiConnect(void) {
static uint32_t lastRetry;
if (wifiHasConfig == false) {
return;
}
if (WiFi.isConnected()) {
lastRetry = millis();
return;
}
uint32_t ms = (uint32_t)(millis() - lastRetry);
if (ms >= WIFI_CONNECT_RETRY_MS) {
lastRetry = millis();
WiFi.reconnect();
Serial.printf("Re-Connect WiFi\r\n");
}
}
/**
* @brief Update tvocIndexindex
*
*/
static void tvocPoll(void) {
tvocIndex = ag.sgp41.getTvocIndex();
noxIndex = ag.sgp41.getNoxIndex();
Serial.printf("tvocIndexindex: %d\r\n", tvocIndex);
Serial.printf(" NOx index: %d\r\n", noxIndex);
}
/**
* @brief Update PMS data
*
*/
static void pmPoll(void) {
if (fw_mode == FW_MODE_PST) {
if (ag.pms5003t_1.readData()) {
pm01_1 = ag.pms5003t_1.getPm01Ae();
pm25_1 = ag.pms5003t_1.getPm25Ae();
pm25_1 = ag.pms5003t_1.getPm10Ae();
pm03PCount_1 = ag.pms5003t_1.getPm03ParticleCount();
temp_1 = ag.pms5003t_1.getTemperature();
hum_1 = ag.pms5003t_1.getRelativeHumidity();
}
} else {
if (ag.pms5003t_1.readData() && ag.pms5003t_2.readData()) {
pm1Value01 = pm1Value01 + ag.pms5003t_1.getPm01Ae();
pm1Value25 = pm1Value25 + ag.pms5003t_1.getPm25Ae();
pm1Value10 = pm1Value10 + ag.pms5003t_1.getPm10Ae();
pm1PCount = pm1PCount + ag.pms5003t_1.getPm03ParticleCount();
pm1temp = pm1temp + ag.pms5003t_1.getTemperature();
pm1hum = pm1hum + ag.pms5003t_1.getRelativeHumidity();
pm2Value01 = pm2Value01 + ag.pms5003t_2.getPm01Ae();
pm2Value25 = pm2Value25 + ag.pms5003t_2.getPm25Ae();
pm2Value10 = pm2Value10 + ag.pms5003t_2.getPm10Ae();
pm2PCount = pm2PCount + ag.pms5003t_2.getPm03ParticleCount();
pm2temp = pm2temp + ag.pms5003t_2.getTemperature();
pm2hum = pm2hum + ag.pms5003t_2.getRelativeHumidity();
countPosition++;
if (countPosition == targetCount) {
pm01_1 = pm1Value01 / targetCount;
pm25_1 = pm1Value25 / targetCount;
pm10_1 = pm1Value10 / targetCount;
pm03PCount_1 = pm1PCount / targetCount;
temp_1 = pm1temp / targetCount;
hum_1 = pm1hum / targetCount;
pm01_2 = pm2Value01 / targetCount;
pm25_2 = pm2Value25 / targetCount;
pm10_2 = pm2Value10 / targetCount;
pm03PCount_2 = pm2PCount / targetCount;
temp_2 = pm2temp / targetCount;
hum_2 = pm2hum / targetCount;
countPosition = 0;
pm1Value01 = 0;
pm1Value25 = 0;
pm1Value10 = 0;
pm1PCount = 0;
pm1temp = 0;
pm1hum = 0;
pm2Value01 = 0;
pm2Value25 = 0;
pm2Value10 = 0;
pm2PCount = 0;
pm2temp = 0;
pm2hum = 0;
}
}
}
}
static void co2Poll(void) {
co2Ppm = ag.s8.getCo2();
Serial.printf("CO2 index: %d\r\n", co2Ppm);
}
static void serverConfigPoll(void) {
if (agServer.pollServerConfig(getDevId())) {
/** Only support CO2 S8 sensor on FW_MODE_PST */
if (fw_mode == FW_MODE_PST) {
if (agServer.isCo2Calib()) {
co2Calibration();
}
if (agServer.getCo2Abccalib() > 0) {
if (ag.s8.setAutoCalib(agServer.getCo2Abccalib() * 24) == false) {
Serial.println("Set S8 auto calib failed");
}
}
}
}
}
static String getDevId(void) { return getNormalizedMac(); }
void ledBlinkDelay(uint32_t tdelay) {
ag.statusLed.setOn();
delay(tdelay);
ag.statusLed.setOff();
delay(tdelay);
}
void ledSmHandler(int sm) {
if (sm > APP_SM_NORMAL) {
return;
}
ledSmState = sm;
switch (sm) {
case APP_SM_WIFI_MANAGER_MODE: {
ag.statusLed.setToggle();
break;
}
case APP_SM_WIFI_MAMAGER_PORTAL_ACTIVE: {
ag.statusLed.setOn();
break;
}
case APP_SM_WIFI_MANAGER_STA_CONNECTING: {
ag.statusLed.setOff();
break;
}
case APP_SM_WIFI_MANAGER_STA_CONNECTED: {
ag.statusLed.setOff();
break;
}
case APP_SM_WIFI_OK_SERVER_CONNECTING: {
ag.statusLed.setOff();
break;
}
case APP_SM_WIFI_OK_SERVER_CONNNECTED: {
ag.statusLed.setOff();
/** two time slow blink, then off */
for (int i = 0; i < 2; i++) {
ledBlinkDelay(LED_SLOW_BLINK_DELAY);
}
ag.statusLed.setOff();
break;
}
case APP_SM_WIFI_MANAGER_CONNECT_FAILED: {
/** Three time fast blink then 2 sec pause. Repeat 3 times */
ag.statusLed.setOff();
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 3; i++) {
ledBlinkDelay(LED_FAST_BLINK_DELAY);
}
delay(2000);
}
ag.statusLed.setOff();
break;
}
case APP_SM_WIFI_OK_SERVER_CONNECT_FAILED: {
ag.statusLed.setOff();
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 4; i++) {
ledBlinkDelay(LED_FAST_BLINK_DELAY);
}
delay(2000);
}
ag.statusLed.setOff();
break;
}
case APP_SM_WIFI_OK_SERVER_OK_SENSOR_CONFIG_FAILED: {
ag.statusLed.setOff();
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 5; i++) {
ledBlinkDelay(LED_FAST_BLINK_DELAY);
}
delay(2000);
}
ag.statusLed.setOff();
break;
}
case APP_SM_WIFI_LOST: {
ag.statusLed.setOff();
break;
}
case APP_SM_SERVER_LOST: {
ag.statusLed.setOff();
break;
}
case APP_SM_SENSOR_CONFIG_FAILED: {
ag.statusLed.setOff();
break;
}
case APP_SM_NORMAL: {
ag.statusLed.setOff();
break;
}
default:
break;
}
}
static const char *getFwMode(int mode) {
switch (mode) {
case FW_MODE_PST:
return "FW_MODE_PST";
case FW_MODE_PPT:
return "FW_MODE_PPT";
case FW_MODE_PP:
return "FW_MODE_PP";
default:
break;
}
return "FW_MODE_UNKNOW";
}

View File

@ -1,5 +1,5 @@
name=AirGradient Air Quality Sensor
version=3.0.3
version=3.0.6
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.

View File

@ -1,6 +1,6 @@
#include "AirGradient.h"
#define AG_LIB_VER "3.0.3"
#define AG_LIB_VER "3.0.6"
AirGradient::AirGradient(BoardType type)
: pms5003(type), pms5003t_1(type), pms5003t_2(type), s8(type), sgp41(type),
@ -36,3 +36,11 @@ int AirGradient::getI2cSclPin(void) {
String AirGradient::getVersion(void) { return AG_LIB_VER; }
BoardType AirGradient::getBoardType(void) { return boardType; }
double AirGradient::round2(double value) {
return (int)(value * 100 + 0.5) / 100.0;
}
String AirGradient::getBoardName(void) {
return String(getBoardDefName(boardType));
}

View File

@ -1,17 +1,17 @@
#ifndef _AIR_GRADIENT_H_
#define _AIR_GRADIENT_H_
#include "display/oled.h"
#include "main/BoardDef.h"
#include "main/HardwareWatchdog.h"
#include "main/LedBar.h"
#include "main/PushButton.h"
#include "main/StatusLed.h"
#include "pms/pms5003.h"
#include "pms/pms5003t.h"
#include "s8/s8.h"
#include "sgp41/sgp41.h"
#include "sht/sht.h"
#include "Display/Display.h"
#include "Main/BoardDef.h"
#include "Main/HardwareWatchdog.h"
#include "Main/LedBar.h"
#include "Main/PushButton.h"
#include "Main/StatusLed.h"
#include "PMS/PMS5003.h"
#include "PMS/PMS5003T.h"
#include "S8/S8.h"
#include "Sgp41/Sgp41.h"
#include "Sht/Sht.h"
/**
* @brief Class with define all the sensor has supported by Airgradient. Each
@ -107,6 +107,21 @@ public:
*/
String getVersion(void);
/**
* @brief Get the Board Name object
*
* @return String
*/
String getBoardName(void);
/**
* @brief Round double value with for 2 decimal
*
* @param valuem Round value
* @return double
*/
double round2(double value);
private:
BoardType boardType;
};

View File

@ -1,6 +1,6 @@
#include "oled.h"
#include "../library/Adafruit_SH110x/Adafruit_SH110X.h"
#include "../library/Adafruit_SSD1306_Wemos_OLED/Adafruit_SSD1306.h"
#include "Display.h"
#include "../Libraries/Adafruit_SH110x/Adafruit_SH110X.h"
#include "../Libraries/Adafruit_SSD1306_Wemos_OLED/Adafruit_SSD1306.h"
#define disp(func) \
if (this->_boardType == DIY_BASIC) { \

View File

@ -1,7 +1,7 @@
#ifndef _AIR_GRADIENT_OLED_H_
#define _AIR_GRADIENT_OLED_H_
#include "../main/BoardDef.h"
#include "../Main/BoardDef.h"
#include <Arduino.h>
#include <Wire.h>

Some files were not shown because too many files have changed in this diff Show More