mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-06-27 00:31:32 +02:00
Compare commits
16 Commits
fix/resizi
...
develop
Author | SHA1 | Date | |
---|---|---|---|
831c844c24 | |||
060a7f6815 | |||
d8eb6b3c1a | |||
969858b5cb | |||
09b5805686 | |||
b09b753339 | |||
ddb3dba131 | |||
e780b0ace6 | |||
e82da5401e | |||
50a98acde4 | |||
7049d21a41 | |||
d5cdeaa9f3 | |||
09207c6923 | |||
5b38ca222b | |||
9ee35341a5 | |||
cec0514444 |
@ -143,6 +143,7 @@ static void updatePm(void);
|
||||
static void sendDataToServer(void);
|
||||
static void tempHumUpdate(void);
|
||||
static void co2Update(void);
|
||||
static void printMeasurements();
|
||||
static void mdnsInit(void);
|
||||
static void createMqttTask(void);
|
||||
static void initMqtt(void);
|
||||
@ -172,6 +173,7 @@ AgSchedule tvocSchedule(SENSOR_TVOC_UPDATE_INTERVAL, updateTvoc);
|
||||
AgSchedule watchdogFeedSchedule(60000, wdgFeedUpdate);
|
||||
AgSchedule checkForUpdateSchedule(FIRMWARE_CHECK_FOR_UPDATE_MS, checkForFirmwareUpdate);
|
||||
AgSchedule networkSignalCheckSchedule(10000, networkSignalCheck);
|
||||
AgSchedule printMeasurementsSchedule(6000, printMeasurements);
|
||||
|
||||
void setup() {
|
||||
/** Serial for print debug message */
|
||||
@ -191,6 +193,7 @@ void setup() {
|
||||
|
||||
/** Initialize local configure */
|
||||
configuration.begin();
|
||||
configuration.setConfigurationUpdatedCallback(configUpdateHandle);
|
||||
|
||||
/** Init I2C */
|
||||
Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
|
||||
@ -218,9 +221,6 @@ void setup() {
|
||||
boardInit();
|
||||
setMeasurementMaxPeriod();
|
||||
|
||||
// Comment below line to disable debug measurement readings
|
||||
measurements.setDebug(true);
|
||||
|
||||
bool connectToNetwork = true;
|
||||
if (ag->isOne()) { // Offline mode only available for indoor monitor
|
||||
/** Show message confirm offline mode, should me perform if LED bar button
|
||||
@ -365,11 +365,17 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
/* Run measurement schedule */
|
||||
printMeasurementsSchedule.run();
|
||||
|
||||
/** factory reset handle */
|
||||
factoryConfigReset();
|
||||
|
||||
/** check that local configuration changed then do some action */
|
||||
configUpdateHandle();
|
||||
if (configuration.isCommandRequested()) {
|
||||
// Each state machine already has an independent request command check
|
||||
stateMachine.executeCo2Calibration();
|
||||
stateMachine.executeLedBarTest();
|
||||
}
|
||||
}
|
||||
|
||||
static void co2Update(void) {
|
||||
@ -386,6 +392,10 @@ static void co2Update(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void printMeasurements() {
|
||||
measurements.printCurrentAverage();
|
||||
}
|
||||
|
||||
static void mdnsInit(void) {
|
||||
if (!MDNS.begin(localServer.getHostname().c_str())) {
|
||||
Serial.println("Init mDNS failed");
|
||||
@ -565,7 +575,7 @@ void checkForFirmwareUpdate(void) {
|
||||
if (networkOption == UseWifi) {
|
||||
agOta = new AirgradientOTAWifi;
|
||||
} else {
|
||||
agOta = new AirgradientOTACellular(cellularCard);
|
||||
agOta = new AirgradientOTACellular(cellularCard, agClient->getICCID());
|
||||
}
|
||||
|
||||
// Indicate main task that firmware update is in progress
|
||||
@ -1033,10 +1043,17 @@ void initializeNetwork() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send data for the first time to AG server at boot
|
||||
// Send data for the first time to AG server at boot only if postDataToAirgradient is enabled
|
||||
if (configuration.isPostDataToAirGradient()) {
|
||||
sendDataToAg();
|
||||
}
|
||||
}
|
||||
|
||||
// Skip fetch configuration if configuration control is set to "local" only
|
||||
if (configuration.getConfigurationControl() == ConfigurationControl::ConfigurationControlLocal) {
|
||||
ledBarEnabledUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
std::string config = agClient->httpFetchConfig();
|
||||
configSchedule.update();
|
||||
@ -1068,8 +1085,8 @@ static void configurationUpdateSchedule(void) {
|
||||
}
|
||||
|
||||
std::string config = agClient->httpFetchConfig();
|
||||
if (agClient->isLastFetchConfigSucceed() && configuration.parse(config.c_str(), false)) {
|
||||
configUpdateHandle();
|
||||
if (agClient->isLastFetchConfigSucceed()) {
|
||||
configuration.parse(config.c_str(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1078,8 +1095,6 @@ static void configUpdateHandle() {
|
||||
return;
|
||||
}
|
||||
|
||||
stateMachine.executeCo2Calibration();
|
||||
|
||||
String mqttUri = configuration.getMqttBrokerUri();
|
||||
if (mqttClient.isCurrentUri(mqttUri) == false) {
|
||||
mqttClient.end();
|
||||
@ -1151,11 +1166,6 @@ static void configUpdateHandle() {
|
||||
if (configuration.isDisplayBrightnessChanged()) {
|
||||
oledDisplay.setBrightness(configuration.getDisplayBrightness());
|
||||
}
|
||||
|
||||
stateMachine.executeLedBarTest();
|
||||
}
|
||||
else if(ag->isOpenAir()) {
|
||||
stateMachine.executeLedBarTest();
|
||||
}
|
||||
|
||||
// Update display and led bar notification based on updated configuration
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AirGradient Air Quality Sensor
|
||||
version=3.3.6
|
||||
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.
|
||||
|
@ -456,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
|
||||
*
|
||||
@ -951,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;
|
||||
}
|
||||
|
||||
@ -1159,6 +1166,12 @@ 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 is invalid, expecting '" + type + "'";
|
||||
}
|
||||
|
@ -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);
|
||||
@ -90,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);
|
||||
@ -116,6 +121,8 @@ public:
|
||||
PMCorrection getPMCorrection(void);
|
||||
TempHumCorrection getTempCorrection(void);
|
||||
TempHumCorrection getHumCorrection(void);
|
||||
private:
|
||||
ConfigurationUpdatedCallback_t _callback;
|
||||
};
|
||||
|
||||
#endif /** _AG_CONFIG_H_ */
|
||||
|
151
src/AgValue.cpp
151
src/AgValue.cpp
@ -76,6 +76,86 @@ Measurements::Measurements(Configuration &config) : config(config) {
|
||||
|
||||
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:
|
||||
@ -570,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);
|
||||
|
@ -88,6 +88,8 @@ public:
|
||||
PM10_PC, // Particle 10 count
|
||||
};
|
||||
|
||||
void printCurrentAverage();
|
||||
|
||||
/**
|
||||
* @brief Set each MeasurementType maximum period length for moving average
|
||||
*
|
||||
@ -258,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);
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "Main/utils.h"
|
||||
|
||||
#ifndef GIT_VERSION
|
||||
#define GIT_VERSION "3.3.6-snap"
|
||||
#define GIT_VERSION "3.3.9-snap"
|
||||
#endif
|
||||
|
||||
|
||||
|
Submodule src/Libraries/airgradient-client updated: a4ac14936e...e32a6a4cde
Submodule src/Libraries/airgradient-ota updated: c772392427...7b103e9073
Reference in New Issue
Block a user