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.
This commit is contained in:
oscgonfer 2025-07-17 11:05:02 +02:00
parent e985e97f76
commit cfc2f59caa
2 changed files with 15 additions and 9 deletions

View File

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

View File

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