Add retries for SCD4X data reading (#11058)
* Add retries for SCD4X data reading * Adds a retry loop with 3 tries by default to get sensor data from the SCD4X * Fix log and happy path
This commit is contained in:
@@ -104,8 +104,18 @@ bool SCD4XSensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||
reClockI2C.setClock(SCD4X_I2C_CLOCK_SPEED);
|
||||
#endif /* SCD4X_I2C_CLOCK_SPEED */
|
||||
|
||||
bool dataReady;
|
||||
error = scd4x.getDataReadyStatus(dataReady);
|
||||
bool dataReady = false;
|
||||
uint8_t dataReadyTries = 0;
|
||||
|
||||
while (!dataReady && (dataReadyTries < SCD4X_MAX_RETRIES)) {
|
||||
error = scd4x.getDataReadyStatus(dataReady);
|
||||
if (error != SCD4X_NO_ERROR || !dataReady) {
|
||||
LOG_WARN("%s: Error collecting data. Retrying", sensorName);
|
||||
delay(100);
|
||||
dataReadyTries++;
|
||||
}
|
||||
}
|
||||
|
||||
if (error != SCD4X_NO_ERROR || !dataReady) {
|
||||
#ifdef SCD4X_I2C_CLOCK_SPEED
|
||||
LOG_DEBUG("%s: restoring clock speed", sensorName);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
// Max speed 400kHz
|
||||
#define SCD4X_I2C_CLOCK_SPEED 400000
|
||||
#define SCD4X_WARMUP_MS 5000
|
||||
#define SCD4X_MAX_RETRIES 3
|
||||
|
||||
class SCD4XSensor : public TelemetrySensor
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user