From cfc2f59caa8d896d8d2ff6b442a808d905425614 Mon Sep 17 00:00:00 2001 From: oscgonfer Date: Thu, 17 Jul 2025 11:05:02 +0200 Subject: [PATCH] Enable PM sensor before sending telemetry. This enables the PM sensor for a predefined period to allow for warmup. Once telemetry is sent, the sensor shuts down again. --- src/modules/Telemetry/AirQualityTelemetry.cpp | 18 ++++++++++++------ src/modules/Telemetry/Sensor/SEN5XSensor.cpp | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/modules/Telemetry/AirQualityTelemetry.cpp b/src/modules/Telemetry/AirQualityTelemetry.cpp index 73f6af45e..a3a3ecb85 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.cpp +++ b/src/modules/Telemetry/AirQualityTelemetry.cpp @@ -93,8 +93,14 @@ int32_t AirQualityTelemetryModule::runOnce() return pmsa003iSensor.wakeUp(); #endif /* PMSA003I_ENABLE_PIN */ - if (sen5xSensor.hasSensor() && !sen5xSensor.isActive()) - return sen5xSensor.wakeUp(); + // Wake up the sensors that need it, before we need to take telemetry data + if ((lastSentToMesh == 0) || + !Throttle::isWithinTimespanMs(lastSentToMesh - SEN5X_WARMUP_MS_1, Default::getConfiguredOrDefaultMsScaled( + moduleConfig.telemetry.air_quality_interval, + default_telemetry_broadcast_interval_secs, numOnlineNodes))) { + if (sen5xSensor.hasSensor() && !sen5xSensor.isActive()) + return sen5xSensor.wakeUp(); + } if (((lastSentToMesh == 0) || !Throttle::isWithinTimespanMs(lastSentToMesh, Default::getConfiguredOrDefaultMsScaled( @@ -112,14 +118,14 @@ int32_t AirQualityTelemetryModule::runOnce() lastSentToPhone = millis(); } - // TODO - When running this continuously, we are turning on and off the sensors but not sending data to mesh or phone, which turns on the device unnecessarily for a while + + // TODO - Add logic here to send the sensor to idle ONLY if there is enough time to wake it up before the next reading cycle #ifdef PMSA003I_ENABLE_PIN pmsa003iSensor.sleep(); #endif /* PMSA003I_ENABLE_PIN */ - // TODO - Add logic here to send the sensor to idle ONLY if there is enough time to wake it up before the next reading cycle - sen5xSensor.idle(); - + if (sen5xSensor.hasSensor() && sen5xSensor.isActive()) + sen5xSensor.idle(); } return min(sendToPhoneIntervalMs, result); } diff --git a/src/modules/Telemetry/Sensor/SEN5XSensor.cpp b/src/modules/Telemetry/Sensor/SEN5XSensor.cpp index 66ae77f27..9c25c859b 100644 --- a/src/modules/Telemetry/Sensor/SEN5XSensor.cpp +++ b/src/modules/Telemetry/Sensor/SEN5XSensor.cpp @@ -122,7 +122,7 @@ bool SEN5XSensor::sendCommand(uint16_t command, uint8_t* buffer, uint8_t byteNum #endif // Transmit the data - LOG_INFO("Beginning connection to SEN5X: 0x%x", address); + // LOG_INFO("Beginning connection to SEN5X: 0x%x", address); bus->beginTransmission(address); size_t writtenBytes = bus->write(toSend, bufferSize); uint8_t i2c_error = bus->endTransmission(); @@ -276,14 +276,14 @@ bool SEN5XSensor::isActive(){ } uint32_t SEN5XSensor::wakeUp(){ - LOG_INFO("SEN5X: Attempting to wakeUp sensor"); + // LOG_INFO("SEN5X: Attempting to wakeUp sensor"); if (!sendCommand(SEN5X_START_MEASUREMENT)) { LOG_INFO("SEN5X: Error starting measurement"); return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } delay(50); // From Sensirion Arduino library - LOG_INFO("SEN5X: Setting measurement mode"); + // LOG_INFO("SEN5X: Setting measurement mode"); uint32_t now; now = getTime(); measureStarted = now;