Compare commits

..

42 Commits

Author SHA1 Message Date
0a64424196 add show content delay for display brightness 2025-05-14 12:39:42 +07:00
626a2240fa Fix resizing queue after success post
This fix should be make it more consistent
2025-05-09 15:45:53 +07:00
174ec6568f Merge pull request #313 from airgradienthq/fix/mode-cloud-disable
Fix bootloop when cloud connection is disabled
2025-05-08 01:28:07 +07:00
6b55719399 Fix cloud connection mode
Use continue instead of return to ignore the rest of transmission code
2025-05-05 17:37:28 +07:00
e2084f0738 Fix OTA request on boot when cloud Connection disabled 2025-05-05 17:36:14 +07:00
5e07923690 Merge pull request #311 from ccoley/fix/submodule-url
Fix failing to clone submodules recursively
2025-05-04 14:13:47 +07:00
04049439b1 Merge pull request #310 from airgradienthq/fix/openmetrics
Fix calling airgradient client before initialization on open metrics
2025-05-04 13:29:24 +07:00
c148d256d7 Use a relative path for submodule URL
We keep the username in the path so that forks don't need to also fork
the submodules
2025-04-30 23:25:30 -07:00
02849a1938 Fix pass agclient to openmetrics
previously, agclient initialized after setAirgradient
2025-05-01 13:38:42 +08:00
074337a96d Merge pull request #304 from airgradienthq/fix/api-root
FIX: HTTP domain configuration changes applied for OTA too
2025-04-21 13:42:26 +07:00
4daa817a0b Change airgradient-ota commit to main branch 2025-04-21 13:41:15 +07:00
81a4502952 Fix: http domain applied for OTA 2025-04-21 13:27:05 +07:00
764e2eae38 Prepare release 3.3.6 2025-04-16 12:34:17 +07:00
79bf9811be Merge pull request #303 from airgradienthq/fix/ce-tvoc
Fix incorrect TVOC / NOx values when when network option is cellular
2025-04-15 12:25:39 +07:00
9475724d0c Remove comment 2025-04-15 12:20:26 +07:00
e7603a7659 Update feedback
Change airgradient-ota submodule to latest main instead of branch
2025-04-14 15:24:53 +07:00
9bba89722e Fix sgp unreliable value by only pause task when performing ota 2025-04-12 02:25:04 +07:00
81945a358e SGP41 add method to pause and resume task handle 2025-04-12 02:22:55 +07:00
3d26a54d69 Prepare release 3.3.5 2025-04-11 15:56:05 +07:00
b70ee75d50 Merge pull request #302 from airgradienthq/improve-ce-reconnection
Improve cellular client reconnection
2025-04-11 15:49:25 +07:00
c6846c818a Rename MICROS_TO_MINUTES() to follow convention 2025-04-11 15:46:21 +07:00
0b1c901a76 Rename cellularModule object name to cellularCard
Rename checkCellularClientNotReady to restartIfCeClientIssueOverTwoHours
2025-04-11 13:41:07 +07:00
83504c8628 Bump libs to latest 2025-04-10 19:05:28 +07:00
4487992748 Remove unnecessary code 2025-04-10 14:58:51 +07:00
3c8a65a329 Use esp_timer_get_time for timer of ce client not ready 2025-04-10 14:58:11 +07:00
673d564ddb Fix based on feedback 2025-04-10 12:45:18 +07:00
423eb4808f Change airgradient-client to latest main 2025-04-10 02:14:34 +07:00
18a710ffc2 Make sure transmit cycle not too long to wait divisible by 3 2025-04-10 02:06:11 +07:00
040cb79a4d Transmit measures only if queue size is 1 or divisible by 3 2025-04-10 00:27:44 +07:00
52d3dc03f1 Redundant check if cellular client not ready for 2 hours
Check calls happen in both task
2025-04-09 23:46:03 +07:00
1c6bc3ec55 Bump airgradient-client fix esp8266 compile 2025-04-09 22:48:21 +07:00
34d7c93e14 Improve reconnection of CE network option
Restart system if it already too long
2025-04-09 15:51:54 +07:00
fee1dc25d6 Improve reconnection of CE network option
Restart system if it already too long
Bump airgradient-client: Improve ensureClientConnection
2025-04-09 15:49:34 +07:00
9fb01d42f4 Prepare release 3.3.4 2025-04-07 16:56:54 +07:00
7bb013939c Merge pull request #301 from airgradienthq/feat/signal
Include cellular signal in RSSI (dbm) when post measures
2025-04-07 16:55:42 +07:00
0da21155e7 bump submodule to post measures with new endpoint
that include signal in rssi
2025-04-07 16:29:54 +07:00
7a153cc0ea add cellular signal quality to post measures payload
If value invalid 0, then do include it to payload
2025-04-07 16:29:15 +07:00
b079c35e6b Include cellular signal in rssi to measurement cycle 2025-04-07 16:28:37 +07:00
6051e183b8 Merge pull request #300 from airgradienthq/fix/pms-error
Remove CORE_DEBUG_LEVEL that affected PM sensor reading
2025-04-07 15:33:37 +07:00
c95379b957 Update submodule to the latest main branch 2025-04-07 15:30:52 +07:00
0cae8bc185 Change ag log level to info 2025-04-05 23:56:14 +07:00
5902a4c8e4 Remove arduino-esp32 core debug level from build_flags
And change it to airgradient log level that take effect to airgradient submodules
Temporary bump submodule to WIP branch
2025-04-05 23:45:46 +07:00
12 changed files with 224 additions and 71 deletions

4
.gitmodules vendored
View File

@ -1,6 +1,6 @@
[submodule "src/Libraries/airgradient-client"]
path = src/Libraries/airgradient-client
url = git@github.com:airgradienthq/airgradient-client.git
url = ../../airgradienthq/airgradient-client.git
[submodule "src/Libraries/airgradient-ota"]
path = src/Libraries/airgradient-ota
url = git@github.com:airgradienthq/airgradient-ota.git
url = ../../airgradienthq/airgradient-ota.git

View File

@ -26,7 +26,6 @@ https://forum.airgradient.com/
CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
*/
#include "AgConfigure.h"
#include "AgSchedule.h"
#include "AgStateMachine.h"
@ -37,6 +36,7 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#include "Arduino.h"
#include "EEPROM.h"
#include "ESPmDNS.h"
#include "Libraries/airgradient-client/src/common.h"
#include "LocalServer.h"
#include "MqttClient.h"
#include "OpenMetrics.h"
@ -45,6 +45,7 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#include <HardwareSerial.h>
#include <WebServer.h>
#include <WiFi.h>
#include <cstdint>
#include <string>
#include "Libraries/airgradient-client/src/agSerial.h"
@ -65,7 +66,7 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#define WIFI_TRANSMISSION_INTERVAL 1 * 60000 /** ms */
#define CELLULAR_SERVER_CONFIG_SYNC_INTERVAL 30 * 60000 /** ms */
#define CELLULAR_MEASUREMENT_INTERVAL 3 * 60000 /** ms */
#define CELLULAR_TRANSMISSION_INTERVAL 9 * 60000 /** ms */
#define CELLULAR_TRANSMISSION_INTERVAL 3 * 60000 /** ms */
#define MQTT_SYNC_INTERVAL 60000 /** ms */
#define SENSOR_CO2_CALIB_COUNTDOWN_MAX 5 /** sec */
#define SENSOR_TVOC_UPDATE_INTERVAL 1000 /** ms */
@ -74,7 +75,10 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#define SENSOR_TEMP_HUM_UPDATE_INTERVAL 6000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 2000 /** ms */
#define FIRMWARE_CHECK_FOR_UPDATE_MS (60 * 60 * 1000) /** ms */
#define TIME_TO_START_POWER_CYCLE_CELLULAR_MODULE (1 * 60) /** minutes */
#define TIMEOUT_WAIT_FOR_CELLULAR_MODULE_READY (2 * 60) /** minutes */
#define MEASUREMENT_TRANSMIT_CYCLE 3
#define MAXIMUM_MEASUREMENT_CYCLE_QUEUE 80
#define RESERVED_MEASUREMENT_CYCLE_CAPACITY 10
@ -88,6 +92,8 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#define GPIO_EXPANSION_CARD_POWER 4
#define GPIO_IIC_RESET 3
#define MINUTES() ((uint32_t)(esp_timer_get_time() / 1000 / 1000 / 60))
static MqttClient mqttClient(Serial);
static TaskHandle_t mqttTask = NULL;
static Configuration configuration(Serial);
@ -102,7 +108,7 @@ static OpenMetrics openMetrics(measurements, configuration, wifiConnector);
static LocalServer localServer(Serial, openMetrics, measurements, configuration,
wifiConnector);
static AgSerial *agSerial;
static CellularModule *cell;
static CellularModule *cellularCard;
static AirgradientClient *agClient;
enum NetworkOption {
@ -111,12 +117,17 @@ enum NetworkOption {
};
NetworkOption networkOption;
TaskHandle_t handleNetworkTask = NULL;
static bool otaInProgress = false;
static bool firmwareUpdateInProgress = false;
static uint32_t factoryBtnPressTime = 0;
static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
static bool ledBarButtonTest = false;
static String fwNewVersion;
static int lastCellSignalQuality = 99; // CSQ
// Default value is 0, indicate its not started yet
// In minutes
uint32_t agCeClientProblemDetectedTime = 0;
SemaphoreHandle_t mutexMeasurementCycleQueue;
static std::vector<Measurements::Measures> measurementCycleQueue;
@ -145,6 +156,7 @@ static void displayExecuteOta(AirgradientOTA::OtaResult result, String msg, int
static int calculateMaxPeriod(int updateInterval);
static void setMeasurementMaxPeriod();
static void newMeasurementCycle();
static void restartIfCeClientIssueOverTwoHours();
static void networkSignalCheck();
static void networkingTask(void *args);
@ -198,7 +210,7 @@ void setup() {
oledDisplay.setAirGradient(ag);
stateMachine.setAirGradient(ag);
wifiConnector.setAirGradient(ag);
openMetrics.setAirGradient(ag, agClient);
openMetrics.setAirGradient(ag);
localServer.setAirGraident(ag);
measurements.setAirGradient(ag);
@ -259,6 +271,7 @@ void setup() {
Serial.println("Display brightness: " + String(configuration.getDisplayBrightness()));
oledDisplay.setBrightness(configuration.getDisplayBrightness());
delay(DISPLAY_DELAY_SHOW_CONTENT_MS);
}
@ -297,11 +310,17 @@ void setup() {
}
void loop() {
if (networkOption == UseCellular) {
// Check if cellular client not ready until certain time
// Redundant check in both task to make sure its executed
restartIfCeClientIssueOverTwoHours();
}
// Schedule to feed external watchdog
watchdogFeedSchedule.run();
if (otaInProgress) {
// OTA currently in progress, temporarily disable running sensor schedules
if (firmwareUpdateInProgress) {
// Firmare update currently in progress, temporarily disable running sensor schedules
delay(10000);
return;
}
@ -334,7 +353,7 @@ void loop() {
static bool pmsConnected = false;
if (pmsConnected != ag->pms5003.connected()) {
pmsConnected = ag->pms5003.connected();
Serial.printf("PMS sensor %s ", pmsConnected?"connected":"removed");
Serial.printf("PMS sensor %s \n", pmsConnected?"connected":"removed");
}
}
} else {
@ -537,35 +556,37 @@ static bool sgp41Init(void) {
}
void checkForFirmwareUpdate(void) {
if (configuration.isCloudConnectionDisabled()) {
Serial.println("Cloud connection is disabled, skip firmware update");
return;
}
AirgradientOTA *agOta;
if (networkOption == UseWifi) {
agOta = new AirgradientOTAWifi;
} else {
agOta = new AirgradientOTACellular(cell);
agOta = new AirgradientOTACellular(cellularCard);
}
// Indicate main task that ota is performing
Serial.println("Check for firmware update, disabling main task");
otaInProgress = true;
if (configuration.hasSensorSGP && networkOption == UseCellular) {
// Only for cellular because it can disturb i2c line
Serial.println("Disable SGP41 task for cellular OTA");
ag->sgp41.end();
}
// Indicate main task that firmware update is in progress
firmwareUpdateInProgress = true;
agOta->setHandlerCallback(otaHandlerCallback);
agOta->updateIfAvailable(ag->deviceId().c_str(), GIT_VERSION);
// Only goes to this line if OTA is not success
String httpDomain = configuration.getHttpDomain();
if (httpDomain != "") {
Serial.printf("httpDomain configuration available, start OTA with custom domain\n",
httpDomain.c_str());
agOta->updateIfAvailable(ag->deviceId().c_str(), GIT_VERSION, httpDomain.c_str());
} else {
agOta->updateIfAvailable(ag->deviceId().c_str(), GIT_VERSION);
}
// Only goes to this line if firmware update is not success
// Handled by otaHandlerCallback
otaInProgress = false;
if (configuration.hasSensorSGP && networkOption == UseCellular) {
// Re-start SGP41 task
if (!sgp41Init()) {
Serial.println("Failed re-start SGP41 task");
}
}
// Indicate main task that firmware update finish
firmwareUpdateInProgress = false;
delete agOta;
Serial.println();
@ -573,14 +594,25 @@ void checkForFirmwareUpdate(void) {
void otaHandlerCallback(AirgradientOTA::OtaResult result, const char *msg) {
switch (result) {
case AirgradientOTA::Starting:
case AirgradientOTA::Starting: {
Serial.println("Firmware update starting...");
if (configuration.hasSensorSGP && networkOption == UseCellular) {
// Temporary pause SGP41 task while cellular firmware update is in progress
ag->sgp41.pause();
}
displayExecuteOta(result, fwNewVersion, 0);
break;
}
case AirgradientOTA::InProgress:
Serial.printf("OTA progress: %s\n", msg);
displayExecuteOta(result, "", std::stoi(msg));
break;
case AirgradientOTA::Failed:
displayExecuteOta(result, "", 0);
if (configuration.hasSensorSGP && networkOption == UseCellular) {
ag->sgp41.resume();
}
break;
case AirgradientOTA::Skipped:
case AirgradientOTA::AlreadyUpToDate:
displayExecuteOta(result, "", 0);
@ -647,7 +679,11 @@ static void displayExecuteOta(AirgradientOTA::OtaResult result, String msg, int
}
delay(1000);
}
oledDisplay.setAirGradient(0);
if (ag->isOne()) {
oledDisplay.setAirGradient(0);
oledDisplay.setBrightness(0);
}
break;
}
default:
@ -925,8 +961,8 @@ void initializeNetwork() {
if (agSerial->open()) {
Serial.println("Cellular module found");
// Initialize cellular module and use cellular as agClient
cell = new CellularModuleA7672XX(agSerial, GPIO_POWER_MODULE_PIN);
agClient = new AirgradientCellularClient(cell);
cellularCard = new CellularModuleA7672XX(agSerial, GPIO_POWER_MODULE_PIN);
agClient = new AirgradientCellularClient(cellularCard);
networkOption = UseCellular;
} else {
Serial.println("Cellular module not available, using wifi");
@ -959,6 +995,9 @@ void initializeNetwork() {
ESP.restart();
}
// Provide openmetrics to have access to last transmission result
openMetrics.setAirgradientClient(agClient);
if (networkOption == UseCellular) {
// Disabling it again
agSerial->setDebug(false);
@ -1340,7 +1379,10 @@ void postUsingWifi() {
Serial.printf("Free heap: %u\n", ESP.getFreeHeap());
}
void postUsingCellular() {
/**
* forcePost to force post without checking transmit cycle
*/
void postUsingCellular(bool forcePost) {
// Aquire queue mutex to get queue size
xSemaphoreTake(mutexMeasurementCycleQueue, portMAX_DELAY);
@ -1352,6 +1394,14 @@ void postUsingCellular() {
return;
}
// Check queue size if its ready to transmit
// It is ready if size is divisible by 3
if (!forcePost && (queueSize % MEASUREMENT_TRANSMIT_CYCLE) > 0) {
Serial.printf("Not ready to transmit, queue size are %d\n", queueSize);
xSemaphoreGive(mutexMeasurementCycleQueue);
return;
}
// Build payload include all measurements from queue
std::string payload;
payload += std::to_string(CELLULAR_MEASUREMENT_INTERVAL / 1000); // Convert to seconds
@ -1373,13 +1423,17 @@ void postUsingCellular() {
// Post success, remove the data that previously sent from queue
xSemaphoreTake(mutexMeasurementCycleQueue, portMAX_DELAY);
measurementCycleQueue.erase(measurementCycleQueue.begin(),
measurementCycleQueue.begin() + queueSize);
if (measurementCycleQueue.capacity() > RESERVED_MEASUREMENT_CYCLE_CAPACITY) {
Serial.println("measurementCycleQueue capacity more than reserved space, resizing..");
measurementCycleQueue.resize(RESERVED_MEASUREMENT_CYCLE_CAPACITY);
std::vector<Measurements::Measures> tmp;
tmp.reserve(RESERVED_MEASUREMENT_CYCLE_CAPACITY);
measurementCycleQueue.swap(tmp);
} else {
// If not more than the capacity, then just clear all the values
measurementCycleQueue.clear();
}
xSemaphoreGive(mutexMeasurementCycleQueue);
}
@ -1393,7 +1447,7 @@ void sendDataToServer(void) {
if (networkOption == UseWifi) {
postUsingWifi();
} else if (networkOption == UseCellular) {
postUsingCellular();
postUsingCellular(false);
}
}
@ -1472,44 +1526,75 @@ void networkSignalCheck() {
if (networkOption == UseWifi) {
Serial.printf("WiFi RSSI %d\n", wifiConnector.RSSI());
} else if (networkOption == UseCellular) {
auto result = cell->retrieveSignal();
auto result = cellularCard->retrieveSignal();
if (result.status != CellReturnStatus::Ok) {
agClient->setClientReady(false);
lastCellSignalQuality = 99;
return;
}
// Save last signal quality
lastCellSignalQuality = result.data;
if (result.data == 99) {
// 99 indicate cellular not attached to network
agClient->setClientReady(false);
return;
}
Serial.printf("Cellular signal strength %d\n", result.data);
Serial.printf("Cellular signal quality %d\n", result.data);
}
}
/**
* If in 2 hours cellular client still not ready, then restart system
*/
void restartIfCeClientIssueOverTwoHours() {
if (agCeClientProblemDetectedTime > 0 &&
(MINUTES() - agCeClientProblemDetectedTime) >
TIMEOUT_WAIT_FOR_CELLULAR_MODULE_READY) {
// Give up wait
Serial.println("Rebooting because CE client issues for 2 hours detected");
int i = 3;
while (i != 0) {
if (ag->isOne()) {
String tmp = "Rebooting in " + String(i);
oledDisplay.setText("CE error", "since 2h", tmp.c_str());
} else {
Serial.println("Rebooting... " + String(i));
}
i = i - 1;
delay(1000);
}
oledDisplay.setBrightness(0);
esp_restart();
}
}
void networkingTask(void *args) {
// OTA check on boot
#ifdef ESP8266
// ota not supported
#else
// because cellular it takes too long, watchdog triggered
checkForFirmwareUpdate();
checkForUpdateSchedule.update();
// If cloud connection enabled, run first transmission to server at boot
if (configuration.isCloudConnectionDisabled() == false) {
// OTA check on boot
#ifndef ESP8266
checkForFirmwareUpdate();
checkForUpdateSchedule.update();
#endif
// Because cellular interval is longer, needs to send first measures cycle on
// boot to indicate that its online
if (networkOption == UseCellular) {
Serial.println("Prepare first measures cycle to send on boot for 20s");
delay(20000);
newMeasurementCycle();
sendDataToServer();
measurementSchedule.update();
// Because cellular interval is longer, needs to send first measures cycle on
// boot to indicate that its online
if (networkOption == UseCellular) {
Serial.println("Prepare first measures cycle to send on boot for 20s");
delay(20000);
networkSignalCheck();
newMeasurementCycle();
postUsingCellular(true);
measurementSchedule.update();
}
// Reset scheduler
configSchedule.update();
transmissionSchedule.update();
}
// Reset scheduler
configSchedule.update();
transmissionSchedule.update();
while (1) {
// Handle reconnection based on mode
if (networkOption == UseWifi) {
@ -1521,21 +1606,50 @@ void networkingTask(void *args) {
}
else if (networkOption == UseCellular) {
if (agClient->isClientReady() == false) {
Serial.println("Cellular client not ready, ensuring connection...");
// Start time if value still default
if (agCeClientProblemDetectedTime == 0) {
agCeClientProblemDetectedTime = MINUTES();
}
// Enable at command debug
agSerial->setDebug(true);
if (agClient->ensureClientConnection() == false) {
Serial.println("Cellular client connection not ready, retry in 5s...");
delay(5000);
// Check if cellular client not ready until certain time
// Redundant check in both task to make sure its executed
restartIfCeClientIssueOverTwoHours();
// Power cycling cellular module due to network issues for more than 1 hour
bool resetModule = true;
if ((MINUTES() - agCeClientProblemDetectedTime) >
TIME_TO_START_POWER_CYCLE_CELLULAR_MODULE) {
Serial.println("The CE client hasn't recovered in more than 1 hour, "
"performing a power cycle");
cellularCard->powerOff();
delay(2000);
cellularCard->powerOn();
delay(10000);
// no need to reset module when calling ensureClientConnection()
resetModule = false;
}
// Attempt to reconnect
Serial.println("Cellular client not ready, ensuring connection...");
if (agClient->ensureClientConnection(resetModule) == false) {
Serial.println("Cellular client connection not ready, retry in 30s...");
delay(30000); // before retry, wait for 30s
continue;
}
agSerial->setDebug(false);
// Client is ready
agCeClientProblemDetectedTime = 0; // reset to default
agSerial->setDebug(false); // disable at command debug
}
}
// If connection to AirGradient server disable don't run config and transmission schedule
if (configuration.isCloudConnectionDisabled()) {
delay(1000);
return;
continue;
}
// Run scheduler
@ -1558,7 +1672,10 @@ void newMeasurementCycle() {
measurementCycleQueue.erase(measurementCycleQueue.begin());
}
// Get current measures
auto mc = measurements.getMeasures();
mc.signal = cellularCard->csqToDbm(lastCellSignalQuality); // convert to RSSI
measurementCycleQueue.push_back(mc);
Serial.println("New measurement cycle added to queue");
// Release mutex

View File

@ -6,8 +6,11 @@ OpenMetrics::OpenMetrics(Measurements &measure, Configuration &config,
OpenMetrics::~OpenMetrics() {}
void OpenMetrics::setAirGradient(AirGradient *ag, AirgradientClient *client) {
void OpenMetrics::setAirGradient(AirGradient *ag) {
this->ag = ag;
}
void OpenMetrics::setAirgradientClient(AirgradientClient *client) {
this->agClient = client;
}

View File

@ -19,7 +19,8 @@ public:
OpenMetrics(Measurements &measure, Configuration &config,
WifiConnector &wifiConnector);
~OpenMetrics();
void setAirGradient(AirGradient *ag, AirgradientClient *client);
void setAirGradient(AirGradient *ag);
void setAirgradientClient(AirgradientClient *client);
const char *getApiContentType(void);
const char* getApi(void);
String getPayload(void);

View File

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

@ -12,7 +12,7 @@
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 CORE_DEBUG_LEVEL=3 -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 =

View File

@ -827,6 +827,12 @@ std::string Measurements::buildMeasuresPayload(Measures &mc) {
oss << std::round(mc.pm_03_pc[1]);
}
oss << ",";
if (mc.signal < 0) {
oss << mc.signal;
}
return oss.str();
}

View File

@ -15,7 +15,7 @@
#include "Main/utils.h"
#ifndef GIT_VERSION
#define GIT_VERSION "3.3.3-snap"
#define GIT_VERSION "3.3.6-snap"
#endif

View File

@ -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;

View File

@ -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;