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 {
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 *
*****************************************************************/
......
......@@ -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
......@@ -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 {
"<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>");
body1_template = PSTR("<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
"</ul></div></div>"
"<script>"
// 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;"
"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
"</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>"
body1_template =
PSTR(
"<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
"</ul></div></div>" "<script>"
// 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;" "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
"</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)
"<tbody %s>"
"<tr><th colspan='2'>LoRaWAN</th></tr>"
......@@ -103,7 +79,7 @@ namespace web_server {
"<tr><td>Interval</td><td>%5d s</td></tr>"
"</tbody>"
#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,
......
Supports Markdown
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