diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp index 40f725e9b4073a22e49098a4ff5de739fdf0d3c9..b7a98d213ddf4e3625db19a5f284907c32072216 100644 --- a/ampel-firmware/co2_sensor.cpp +++ b/ampel-firmware/co2_sensor.cpp @@ -52,6 +52,10 @@ namespace sensor { state current_state = BOOTUP; void switchState(state); + void setCO2forDebugging(int32_t fakeCo2); + void calibrateSensorToSpecificPPM(int32_t calibrationLevel); + void calibrateSensorRightNow(int32_t calibrationLevel); + void setAutoCalibration(int32_t autoCalibration); void initialize() { #if defined(ESP8266) @@ -82,14 +86,17 @@ namespace sensor { // for acclimatization. Resetting it after startup seems to fix this behaviour. scd30.reset(); + //NOTE: It seems that the sensor needs some time for getting/setting temperature offset. + delay(500); Serial.print(F("Setting temperature offset to -")); Serial.print(abs(config::temperature_offset)); Serial.println(F(" K.")); scd30.setTemperatureOffset(abs(config::temperature_offset)); // setTemperatureOffset only accepts positive numbers, but shifts the temperature down. - delay(100); + delay(500); - Serial.print(F("Temperature offset is : -")); - Serial.print(scd30.getTemperatureOffset()); + //NOTE: Even once the temperature offset is saved, the sensor still needs some time (~10 minutes?) to apply it. + Serial.print(F("Temperature offset is : ")); + Serial.print(getTemperatureOffset()); Serial.println(F(" K")); Serial.print(F("Auto-calibration is ")); @@ -281,6 +288,10 @@ namespace sensor { return freshData && (current_state == READY || current_state == NEEDS_CALIBRATION); } + float getTemperatureOffset() { + return -abs(scd30.getTemperatureOffset()); + } + /***************************************************************** * Callbacks for sensor commands * *****************************************************************/ diff --git a/ampel-firmware/co2_sensor.h b/ampel-firmware/co2_sensor.h index 00b81d09846a53b8fa4d6cfcff5cb70a720807f0..e152f2777e87947d0b15a7712985fe9deddf1e7a 100644 --- a/ampel-firmware/co2_sensor.h +++ b/ampel-firmware/co2_sensor.h @@ -12,12 +12,8 @@ namespace sensor { void initialize(); bool processData(); void startCalibrationProcess(); - - void setCO2forDebugging(int32_t fakeCo2); void setTimer(int32_t timestep); - void calibrateSensorToSpecificPPM(int32_t calibrationLevel); - void calibrateSensorRightNow(int32_t calibrationLevel); - void setAutoCalibration(int32_t autoCalibration); void resetSCD(); + float getTemperatureOffset(); } #endif diff --git a/ampel-firmware/web_server.cpp b/ampel-firmware/web_server.cpp index 0065644d700cb2d129a0cbdfacb951c27b466142..07901a845afce1bcf31601918f08227b5b610d09 100644 --- a/ampel-firmware/web_server.cpp +++ b/ampel-firmware/web_server.cpp @@ -29,11 +29,11 @@ namespace web_server { void handleDeleteCSV(); void handleWebServerCSV(); - const __FlashStringHelper* showHTMLIf(bool is_active){ + const __FlashStringHelper* showHTMLIf(bool is_active) { return is_active ? F("") : F("hidden"); } - const __FlashStringHelper* yesOrNo(bool is_active){ + const __FlashStringHelper* yesOrNo(bool is_active) { return is_active ? F("Yes") : F("No"); } @@ -63,37 +63,13 @@ namespace web_server { "
  • Graph
  • " "
  • Log
  • "); - body1_template = PSTR("
  • Download CSV
  • " - "
  • ⬤
  • " // LED - "" - "" - "
    " - "
    "// Graph placeholder - "
    " - "
    " - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" + body1_template = + PSTR( + "
  • Download CSV
  • " "
  • ⬤
  • " // LED + "" "" "
    " "
    "// Graph placeholder + "
    " "
    " "
    %s
    CO2%5d ppm
    Temperature%.1f℃
    Humidity%.1f%%
    Last measurement%s
    Timestep%5d s
    CSV
    Last write%s
    Interval%5d s
    Available space%d kB
    MQTT
    Connected?%s
    Last publish%s
    Interval%5d s
    " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" #if defined(ESP32) "" "" @@ -103,7 +79,7 @@ namespace web_server { "" "" #endif - ); + ); body2_template = PSTR( @@ -229,8 +205,8 @@ namespace web_server { snprintf_P(content, sizeof(content), body1_template, csv_writer::filename, config::ampel_name(), sensor::co2, sensor::temperature, sensor::humidity, sensor::timestamp, config::measurement_timestep, showHTMLIf(config::is_csv_active()), csv_writer::last_successful_write, config::csv_interval, - csv_writer::getAvailableSpace() / 1024, showHTMLIf(config::is_mqtt_active()), - yesOrNo(mqtt::connected), mqtt::last_successful_publish, config::mqtt_sending_interval + csv_writer::getAvailableSpace() / 1024, showHTMLIf(config::is_mqtt_active()), yesOrNo(mqtt::connected), + mqtt::last_successful_publish, config::mqtt_sending_interval #if defined(ESP32) , showHTMLIf(config::is_lorawan_active()), yesOrNo(lorawan::connected), config::lorawan_frequency_plan, lorawan::last_transmission, config::lorawan_sending_interval @@ -241,7 +217,7 @@ namespace web_server { Serial.print(strlen(content)); web_config::http.sendContent(content); - snprintf_P(content, sizeof(content), body2_template, config::temperature_offset, + snprintf_P(content, sizeof(content), body2_template, sensor::getTemperatureOffset(), yesOrNo(config::auto_calibrate_sensor), config::ampel_name(), config::ampel_name(), wifi::local_ip, wifi::local_ip, ampel.macAddress, ESP.getFreeHeap(), esp_get_max_free_block_size(), esp_get_heap_fragmentation(), ampel.max_loop_duration, ampel.board, ampel.sensorId, ampel.version, dd, hh, mm,
    %s
    CO2%5d ppm
    Temperature%.1f℃
    Humidity%.1f%%
    Last measurement%s
    Timestep%5d s
    CSV
    Last write%s
    Interval%5d s
    Available space%d kB
    MQTT
    Connected?%s
    Last publish%s
    Interval%5d s
    LoRaWAN
    Interval%5d s