Commit 90f80906 authored by Eric Duminil's avatar Eric Duminil
Browse files

Fixing set_temperature_offset

Give the sensor some time to adjust
Display the applied offset on the webpage, not just the parameter
parent 29e78fc3
Pipeline #5981 passed with stage
in 2 minutes and 30 seconds
...@@ -52,6 +52,10 @@ namespace sensor { ...@@ -52,6 +52,10 @@ namespace sensor {
state current_state = BOOTUP; state current_state = BOOTUP;
void switchState(state); 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() { void initialize() {
#if defined(ESP8266) #if defined(ESP8266)
...@@ -82,14 +86,17 @@ namespace sensor { ...@@ -82,14 +86,17 @@ namespace sensor {
// for acclimatization. Resetting it after startup seems to fix this behaviour. // for acclimatization. Resetting it after startup seems to fix this behaviour.
scd30.reset(); 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(F("Setting temperature offset to -"));
Serial.print(abs(config::temperature_offset)); Serial.print(abs(config::temperature_offset));
Serial.println(F(" K.")); Serial.println(F(" K."));
scd30.setTemperatureOffset(abs(config::temperature_offset)); // setTemperatureOffset only accepts positive numbers, but shifts the temperature down. 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 : -")); //NOTE: Even once the temperature offset is saved, the sensor still needs some time (~10 minutes?) to apply it.
Serial.print(scd30.getTemperatureOffset()); Serial.print(F("Temperature offset is : "));
Serial.print(getTemperatureOffset());
Serial.println(F(" K")); Serial.println(F(" K"));
Serial.print(F("Auto-calibration is ")); Serial.print(F("Auto-calibration is "));
...@@ -281,6 +288,10 @@ namespace sensor { ...@@ -281,6 +288,10 @@ namespace sensor {
return freshData && (current_state == READY || current_state == NEEDS_CALIBRATION); return freshData && (current_state == READY || current_state == NEEDS_CALIBRATION);
} }
float getTemperatureOffset() {
return -abs(scd30.getTemperatureOffset());
}
/***************************************************************** /*****************************************************************
* Callbacks for sensor commands * * Callbacks for sensor commands *
*****************************************************************/ *****************************************************************/
......
...@@ -12,12 +12,8 @@ namespace sensor { ...@@ -12,12 +12,8 @@ namespace sensor {
void initialize(); void initialize();
bool processData(); bool processData();
void startCalibrationProcess(); void startCalibrationProcess();
void setCO2forDebugging(int32_t fakeCo2);
void setTimer(int32_t timestep); void setTimer(int32_t timestep);
void calibrateSensorToSpecificPPM(int32_t calibrationLevel);
void calibrateSensorRightNow(int32_t calibrationLevel);
void setAutoCalibration(int32_t autoCalibration);
void resetSCD(); void resetSCD();
float getTemperatureOffset();
} }
#endif #endif
...@@ -29,11 +29,11 @@ namespace web_server { ...@@ -29,11 +29,11 @@ namespace web_server {
void handleDeleteCSV(); void handleDeleteCSV();
void handleWebServerCSV(); void handleWebServerCSV();
const __FlashStringHelper* showHTMLIf(bool is_active){ const __FlashStringHelper* showHTMLIf(bool is_active) {
return is_active ? F("") : F("hidden"); 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"); return is_active ? F("Yes") : F("No");
} }
...@@ -63,37 +63,13 @@ namespace web_server { ...@@ -63,37 +63,13 @@ namespace web_server {
"<li class='pure-menu-item'><a href='#graph' class='pure-menu-link'>Graph</a></li>" "<li class='pure-menu-item'><a href='#graph' class='pure-menu-link'>Graph</a></li>"
"<li class='pure-menu-item'><a href='#log' class='pure-menu-link'>Log</a></li>"); "<li class='pure-menu-item'><a href='#log' class='pure-menu-link'>Log</a></li>");
body1_template = PSTR("<li class='pure-menu-item'><a href='%s' class='pure-menu-link'>Download CSV</a></li>" body1_template =
"<li class='pure-menu-item' id='led'>&#11044;</li>" // LED PSTR(
"</ul></div></div>" "<li class='pure-menu-item'><a href='%s' class='pure-menu-link'>Download CSV</a></li>" "<li class='pure-menu-item' id='led'>&#11044;</li>" // LED
"<script>" "</ul></div></div>" "<script>"
// Show a colored dot on the webpage, with a similar color than on LED Ring. // Show a colored dot on the webpage, with a similar color than on LED Ring.
"hue=(1-(Math.min(Math.max(parseInt(document.title),500),1600)-500)/1100)*120;" "hue=(1-(Math.min(Math.max(parseInt(document.title),500),1600)-500)/1100)*120;" "document.getElementById('led').style.color=['hsl(',hue,',100%%,50%%)'].join('');" "</script>" "<div class='pure-g'>" "<div class='pure-u-1' id='graph'></div>"// Graph placeholder
"document.getElementById('led').style.color=['hsl(',hue,',100%%,50%%)'].join('');" "</div>" "<div class='pure-g'>" "<table id='table' class='pure-table-striped pure-u-1 pure-u-md-1-2'>" "<tr><th colspan='2'>%s</th></tr>" "<tr><td>CO<sub>2</sub></td><td>%5d ppm</td></tr>" "<tr><td>Temperature</td><td>%.1f&#8451;</td></tr>" "<tr><td>Humidity</td><td>%.1f%%</td></tr>" "<tr><td>Last measurement</td><td>%s</td></tr>" "<tr><td>Timestep</td><td>%5d s</td></tr>" "<tbody %s>" "<tr><th colspan='2'>CSV</th></tr>" "<tr><td>Last write</td><td>%s</td></tr>" "<tr><td>Interval</td><td>%5d s</td></tr>" "<tr><td>Available space</td><td>%d kB</td></tr>" "</tbody>" "<tbody %s>" "<tr><th colspan='2'>MQTT</th></tr>" "<tr><td>Connected?</td><td>%s</td></tr>" "<tr><td>Last publish</td><td>%s</td></tr>" "<tr><td>Interval</td><td>%5d s</td></tr>" "</tbody>"
"</script>"
"<div class='pure-g'>"
"<div class='pure-u-1' id='graph'></div>"// Graph placeholder
"</div>"
"<div class='pure-g'>"
"<table id='table' class='pure-table-striped pure-u-1 pure-u-md-1-2'>"
"<tr><th colspan='2'>%s</th></tr>"
"<tr><td>CO<sub>2</sub></td><td>%5d ppm</td></tr>"
"<tr><td>Temperature</td><td>%.1f&#8451;</td></tr>"
"<tr><td>Humidity</td><td>%.1f%%</td></tr>"
"<tr><td>Last measurement</td><td>%s</td></tr>"
"<tr><td>Timestep</td><td>%5d s</td></tr>"
"<tbody %s>"
"<tr><th colspan='2'>CSV</th></tr>"
"<tr><td>Last write</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"<tr><td>Available space</td><td>%d kB</td></tr>"
"</tbody>"
"<tbody %s>"
"<tr><th colspan='2'>MQTT</th></tr>"
"<tr><td>Connected?</td><td>%s</td></tr>"
"<tr><td>Last publish</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"</tbody>"
#if defined(ESP32) #if defined(ESP32)
"<tbody %s>" "<tbody %s>"
"<tr><th colspan='2'>LoRaWAN</th></tr>" "<tr><th colspan='2'>LoRaWAN</th></tr>"
...@@ -103,7 +79,7 @@ namespace web_server { ...@@ -103,7 +79,7 @@ namespace web_server {
"<tr><td>Interval</td><td>%5d s</td></tr>" "<tr><td>Interval</td><td>%5d s</td></tr>"
"</tbody>" "</tbody>"
#endif #endif
); );
body2_template = body2_template =
PSTR( PSTR(
...@@ -229,8 +205,8 @@ namespace web_server { ...@@ -229,8 +205,8 @@ namespace web_server {
snprintf_P(content, sizeof(content), body1_template, csv_writer::filename, config::ampel_name(), sensor::co2, snprintf_P(content, sizeof(content), body1_template, csv_writer::filename, config::ampel_name(), sensor::co2,
sensor::temperature, sensor::humidity, sensor::timestamp, config::measurement_timestep, sensor::temperature, sensor::humidity, sensor::timestamp, config::measurement_timestep,
showHTMLIf(config::is_csv_active()), csv_writer::last_successful_write, config::csv_interval, showHTMLIf(config::is_csv_active()), csv_writer::last_successful_write, config::csv_interval,
csv_writer::getAvailableSpace() / 1024, showHTMLIf(config::is_mqtt_active()), csv_writer::getAvailableSpace() / 1024, showHTMLIf(config::is_mqtt_active()), yesOrNo(mqtt::connected),
yesOrNo(mqtt::connected), mqtt::last_successful_publish, config::mqtt_sending_interval mqtt::last_successful_publish, config::mqtt_sending_interval
#if defined(ESP32) #if defined(ESP32)
, showHTMLIf(config::is_lorawan_active()), yesOrNo(lorawan::connected), , showHTMLIf(config::is_lorawan_active()), yesOrNo(lorawan::connected),
config::lorawan_frequency_plan, lorawan::last_transmission, config::lorawan_sending_interval config::lorawan_frequency_plan, lorawan::last_transmission, config::lorawan_sending_interval
...@@ -241,7 +217,7 @@ namespace web_server { ...@@ -241,7 +217,7 @@ namespace web_server {
Serial.print(strlen(content)); Serial.print(strlen(content));
web_config::http.sendContent(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, 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(), 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, esp_get_heap_fragmentation(), ampel.max_loop_duration, ampel.board, ampel.sensorId, ampel.version, dd, hh, mm,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment