From 90f80906826011650df6125d8ffd5878285f950d Mon Sep 17 00:00:00 2001 From: Eric Duminil Date: Thu, 3 Mar 2022 12:39:29 +0100 Subject: [PATCH] Fixing set_temperature_offset Give the sensor some time to adjust Display the applied offset on the webpage, not just the parameter --- ampel-firmware/co2_sensor.cpp | 17 +++++++++--- ampel-firmware/co2_sensor.h | 6 +---- ampel-firmware/web_server.cpp | 50 +++++++++-------------------------- 3 files changed, 28 insertions(+), 45 deletions(-) diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp index 40f725e..b7a98d2 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 00b81d0..e152f27 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 0065644..07901a8 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, -- GitLab
    %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