mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-29 08:27:17 +02:00
Merge branch 'develop' into ota
This commit is contained in:
@ -37,6 +37,7 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
|
||||
*/
|
||||
|
||||
#include <HardwareSerial.h>
|
||||
#include "AirGradient.h"
|
||||
#include "OtaHandler.h"
|
||||
#include "AgApiClient.h"
|
||||
#include "AgConfigure.h"
|
||||
@ -49,7 +50,6 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
|
||||
#include "MqttClient.h"
|
||||
#include "OpenMetrics.h"
|
||||
#include "WebServer.h"
|
||||
#include <AirGradient.h>
|
||||
#include <WebServer.h>
|
||||
|
||||
#define LED_BAR_ANIMATION_PERIOD 100 /** ms */
|
||||
@ -78,7 +78,8 @@ static AirGradient *ag;
|
||||
static OledDisplay oledDisplay(configuration, measurements, Serial);
|
||||
static StateMachine stateMachine(oledDisplay, Serial, measurements,
|
||||
configuration);
|
||||
static WifiConnector wifiConnector(oledDisplay, Serial, stateMachine, configuration);
|
||||
static WifiConnector wifiConnector(oledDisplay, Serial, stateMachine,
|
||||
configuration);
|
||||
static OpenMetrics openMetrics(measurements, configuration, wifiConnector,
|
||||
apiClient);
|
||||
static OtaHandler otaHandler;
|
||||
@ -110,6 +111,7 @@ static void initMqtt(void);
|
||||
static void factoryConfigReset(void);
|
||||
static void wdgFeedUpdate(void);
|
||||
static void ledBarEnabledUpdate(void);
|
||||
static bool sgp41Init(void);
|
||||
|
||||
AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, oledDisplayLedBarSchedule);
|
||||
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
|
||||
@ -308,7 +310,7 @@ static void createMqttTask(void) {
|
||||
/** Send data */
|
||||
if (mqttClient.isConnected()) {
|
||||
String payload = measurements.toString(
|
||||
false, fwMode, wifiConnector.RSSI(), ag, &configuration);
|
||||
true, fwMode, wifiConnector.RSSI(), ag, &configuration);
|
||||
String topic = "airgradient/readings/" + ag->deviceId();
|
||||
|
||||
if (mqttClient.publish(topic.c_str(), payload.c_str(),
|
||||
@ -416,6 +418,20 @@ static void ledBarEnabledUpdate(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool sgp41Init(void) {
|
||||
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||
if (ag->sgp41.begin(Wire)) {
|
||||
Serial.println("Init SGP41 success");
|
||||
configuration.hasSensorSGP = true;
|
||||
return true;
|
||||
} else {
|
||||
Serial.println("Init SGP41 failuire");
|
||||
configuration.hasSensorSGP = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void sendDataToAg() {
|
||||
/** Change oledDisplay and led state */
|
||||
if (ag->isOne()) {
|
||||
@ -484,11 +500,7 @@ static void oneIndoorInit(void) {
|
||||
ag->watchdog.begin();
|
||||
|
||||
/** Init sensor SGP41 */
|
||||
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||
if (ag->sgp41.begin(Wire) == false) {
|
||||
Serial.println("SGP41 sensor not found");
|
||||
configuration.hasSensorSGP = false;
|
||||
if (sgp41Init() == false) {
|
||||
dispSensorNotFound("SGP41");
|
||||
}
|
||||
|
||||
@ -570,10 +582,7 @@ static void openAirInit(void) {
|
||||
serial1Available = false;
|
||||
}
|
||||
|
||||
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||
if (ag->sgp41.begin(Wire) == false) {
|
||||
configuration.hasSensorSGP = false;
|
||||
if (sgp41Init() == false) {
|
||||
Serial.println("SGP sensor not found");
|
||||
|
||||
if (configuration.hasSensorS8 == false) {
|
||||
@ -648,6 +657,16 @@ static void boardInit(void) {
|
||||
} else {
|
||||
openAirInit();
|
||||
}
|
||||
|
||||
/** Set S8 CO2 abc days period */
|
||||
if (configuration.hasSensorS8) {
|
||||
if (ag->s8.setAbcPeriod(configuration.getCO2CalibrationAbcDays() * 24)) {
|
||||
Serial.println("Set S8 AbcDays successful");
|
||||
} else {
|
||||
Serial.println("Set S8 AbcDays failure");
|
||||
}
|
||||
}
|
||||
|
||||
localServer.setFwMode(fwMode);
|
||||
}
|
||||
|
||||
@ -682,17 +701,23 @@ static void configUpdateHandle() {
|
||||
if (configuration.noxLearnOffsetChanged() ||
|
||||
configuration.tvocLearnOffsetChanged()) {
|
||||
ag->sgp41.end();
|
||||
Serial.println("nox/tvoc learning offset changed");
|
||||
Serial.println("noxLearningOffset: " + String(configuration.getNoxLearningOffset()));
|
||||
Serial.println("tvocLearningOffset: " + String(configuration.getTvocLearningOffset()));
|
||||
ag->sgp41.setNoxLearningOffset(configuration.getNoxLearningOffset());
|
||||
ag->sgp41.setTvocLearningOffset(configuration.getTvocLearningOffset());
|
||||
if (ag->sgp41.begin(Wire)) {
|
||||
Serial.println("Init SGP41 success");
|
||||
configuration.hasSensorSGP = true;
|
||||
} else {
|
||||
Serial.println("Init SGP41 failuire");
|
||||
configuration.hasSensorSGP = false;
|
||||
|
||||
int oldTvocOffset = ag->sgp41.getTvocLearningOffset();
|
||||
int oldNoxOffset = ag->sgp41.getNoxLearningOffset();
|
||||
bool result = sgp41Init();
|
||||
const char *resultStr = "successful";
|
||||
if (!result) {
|
||||
resultStr = "failure";
|
||||
}
|
||||
if (oldTvocOffset != configuration.getTvocLearningOffset()) {
|
||||
Serial.printf("Setting tvocLearningOffset from %d to %d hours %s\r\n",
|
||||
oldTvocOffset, configuration.getTvocLearningOffset(),
|
||||
resultStr);
|
||||
}
|
||||
if (oldNoxOffset != configuration.getNoxLearningOffset()) {
|
||||
Serial.printf("Setting noxLearningOffset from %d to %d hours %s\r\n",
|
||||
oldNoxOffset, configuration.getNoxLearningOffset(),
|
||||
resultStr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -795,6 +820,10 @@ static void updatePm(void) {
|
||||
Serial.printf("[1] PM3.0 Count: %d\r\n", measurements.pm03PCount_1);
|
||||
Serial.printf("[1] Temperature in C: %0.2f\r\n", measurements.temp_1);
|
||||
Serial.printf("[1] Relative Humidity: %d\r\n", measurements.hum_1);
|
||||
Serial.printf("[1] Temperature compensated in C: %0.2f\r\n",
|
||||
ag->pms5003t_1.temperatureCompensated(measurements.temp_1));
|
||||
Serial.printf("[1] Relative Humidity compensated: %d\r\n",
|
||||
ag->pms5003t_1.humidityCompensated(measurements.hum_1));
|
||||
} else {
|
||||
measurements.pm01_1 = -1;
|
||||
measurements.pm25_1 = -1;
|
||||
@ -821,6 +850,10 @@ static void updatePm(void) {
|
||||
Serial.printf("[2] PM3.0 Count: %d\r\n", measurements.pm03PCount_2);
|
||||
Serial.printf("[2] Temperature in C: %0.2f\r\n", measurements.temp_2);
|
||||
Serial.printf("[2] Relative Humidity: %d\r\n", measurements.hum_2);
|
||||
Serial.printf("[2] Temperature compensated in C: %0.2f\r\n",
|
||||
ag->pms5003t_1.temperatureCompensated(measurements.temp_2));
|
||||
Serial.printf("[2] Relative Humidity compensated: %d\r\n",
|
||||
ag->pms5003t_1.humidityCompensated(measurements.hum_2));
|
||||
} else {
|
||||
measurements.pm01_2 = -1;
|
||||
measurements.pm25_2 = -1;
|
||||
@ -947,6 +980,10 @@ static void tempHumUpdate(void) {
|
||||
|
||||
Serial.printf("Temperature in C: %0.2f\r\n", measurements.Temperature);
|
||||
Serial.printf("Relative Humidity: %d\r\n", measurements.Humidity);
|
||||
Serial.printf("Temperature compensated in C: %0.2f\r\n",
|
||||
measurements.Temperature);
|
||||
Serial.printf("Relative Humidity compensated: %d\r\n",
|
||||
measurements.Humidity);
|
||||
|
||||
// Update compensation temperature and humidity for SGP41
|
||||
if (configuration.hasSensorSGP) {
|
||||
|
@ -179,7 +179,7 @@ String OpenMetrics::getPayload(void) {
|
||||
|
||||
if (_temp > -1001) {
|
||||
add_metric("temperature",
|
||||
"The ambient temperature as measured by the AirGradient SHT "
|
||||
"The ambient temperature as measured by the AirGradient SHT / PMS "
|
||||
"sensor, in degrees Celsius",
|
||||
"gauge", "celsius");
|
||||
add_metric_point("", String(_temp));
|
||||
@ -187,21 +187,22 @@ String OpenMetrics::getPayload(void) {
|
||||
if (atmpCompensated > -1001) {
|
||||
add_metric(
|
||||
"temperature_compensated",
|
||||
"The ambient temperature as measured by the AirGradient SHT / PMS",
|
||||
"The compensated ambient temperature as measured by the AirGradient SHT / PMS "
|
||||
"sensor, in degrees Celsius",
|
||||
"gauge", "celsius");
|
||||
add_metric_point("", String(atmpCompensated));
|
||||
}
|
||||
if (_hum >= 0) {
|
||||
add_metric(
|
||||
"humidity",
|
||||
"The relative humidity as measured by the AirGradient SHT sensor",
|
||||
"The relative humidity as measured by the AirGradient SHT sensor"
|
||||
"gauge", "percent");
|
||||
add_metric_point("", String(_hum));
|
||||
}
|
||||
if (ahumCompensated >= 0) {
|
||||
add_metric(
|
||||
"humidity_compensated",
|
||||
"The relative humidity as measured by the AirGradient SHT / PMS sensor",
|
||||
"The compensated relative humidity as measured by the AirGradient SHT / PMS sensor",
|
||||
"gauge", "percent");
|
||||
add_metric_point("", String(ahumCompensated));
|
||||
}
|
||||
|
Reference in New Issue
Block a user