Commits (4)
  • Käppler's avatar
    co2_sensor: Reset SCD30 after startup · fe023428
    Käppler authored
    Sometimes after a hard reset of the ESP the SCD30
    needs a long time until returning the first measurement.
    Resetting it after startup seems to fix this behaviour.
    fe023428
  • Käppler's avatar
    co2_sensor: Drop unused state 'CALIBRATION' · c6139baf
    Käppler authored
    c6139baf
  • Käppler's avatar
    co2_sensor: Do not report new data in all cases · 239daba6
    Käppler authored
    Log every measurement to the serial console, but
    return only `true` in `processData()`(thus starting
    further processing like CSV, MQTT, LORAWAN) if
    the data is reliable (stable measurements, CO2 > 0)
    or the sensor measures too low CO2 values (< 250).
    
    The latter condition should be reported, because
    the user can then initiate a manual calibration procedure.
    239daba6
  • Käppler's avatar
    co2_sensor: Remove state 'INVALID' · 186bf9f9
    Käppler authored
    Ongoing investigation showed that the sensor
    does report 0 ppm only after startup, i.e.
    in 'BOOTUP' state. We check for this condition
    in `hasSensprSettled()` already, so there is no
    need for this state anymore.
    186bf9f9
......@@ -33,30 +33,24 @@ namespace sensor {
* INITIAL -> initial state
* BOOTUP -> state after initializing the sensor, i.e. after scd.begin()
* READY -> sensor does output valid information (> 0 ppm) and no other condition takes place
* INVALID -> sensor does output invalid CO2 measurements (== 0 ppm)
* NEEDS_CALIBRATION -> sensor measurements are too low (< 250 ppm)
* PREPARE_CALIBRATION -> forced calibration was initiated, waiting for stable measurements
* CALIBRATION -> the sensor does calibrate itself
*/
enum state {
INITIAL,
BOOTUP,
READY,
INVALID,
NEEDS_CALIBRATION,
PREPARE_CALIBRATION_UNSTABLE,
PREPARE_CALIBRATION_STABLE,
CALIBRATION
PREPARE_CALIBRATION_STABLE
};
const char *state_names[] = {
"INITIAL",
"BOOTUP",
"READY",
"INVALID",
"NEEDS_CALIBRATION",
"PREPARE_CALIBRATION_UNSTABLE",
"PREPARE_CALIBRATION_STABLE",
"CALIBRATION" };
"PREPARE_CALIBRATION_STABLE" };
state current_state = INITIAL;
void switchState(state);
......@@ -83,6 +77,11 @@ namespace sensor {
ESP.restart();
}
// Changes of the SCD30's measurement timestep do not come into effect
// before the next measurement takes place. That means that after a hard reset
// of the ESP the SCD30 sometimes needs a long time until switching back to 2 s
// for acclimatization. Resetting it after startup seems to fix this behaviour.
scd30.reset();
switchState(BOOTUP);
Serial.print(F("Setting temperature offset to -"));
......@@ -167,7 +166,6 @@ namespace sensor {
}
void calibrateAndRestart() {
switchState(CALIBRATION);
Serial.print(F("Calibrating SCD30 now..."));
scd30.setAltitudeCompensation(config::altitude_above_sea_level);
scd30.setForcedRecalibrationFactor(config::co2_calibration_level);
......@@ -209,12 +207,7 @@ namespace sensor {
Serial.println(" s.");
scd30.setMeasurementInterval(config::measurement_timestep); // [s]
}
if (co2 == 0) {
// NOTE: Data is available, but it's sometimes erroneous: the sensor outputs
// zero ppm but non-zero temperature and non-zero humidity.
Serial.println(F("Invalid sensor data - CO2 concentration supposedly 0 ppm"));
switchState(INVALID);
} else if ((current_state == PREPARE_CALIBRATION_UNSTABLE) || (current_state == PREPARE_CALIBRATION_STABLE)) {
if ((current_state == PREPARE_CALIBRATION_UNSTABLE) || (current_state == PREPARE_CALIBRATION_STABLE)) {
// Check for pre-calibration states first, because we do not want to
// leave them before calibration is done.
bool ready_for_calibration = countStableMeasurements();
......@@ -252,9 +245,6 @@ namespace sensor {
case READY:
displayCO2OnLedRing();
break;
case INVALID:
led_effects::showWaitingLED(color::red);
break;
case NEEDS_CALIBRATION:
led_effects::showWaitingLED(color::magenta);
break;
......@@ -264,8 +254,6 @@ namespace sensor {
case PREPARE_CALIBRATION_STABLE:
led_effects::showWaitingLED(color::green);
break;
case CALIBRATION: // Nothing to do, will restart soon.
break;
default:
Serial.println(F("Encountered unknown sensor state")); // This should not happen.
}
......@@ -292,7 +280,9 @@ namespace sensor {
showState();
return freshData;
// Report data for further processing only if the data is reliable
// (state 'READY') or manual calibration is necessary (state 'NEEDS_CALIBRATION').
return freshData && (current_state == READY || current_state == NEEDS_CALIBRATION);
}
/*****************************************************************
......