From 4a93e78c14003b4d0bcf2fc97e91b8f6eed36b97 Mon Sep 17 00:00:00 2001 From: Rajko Zschiegner Date: Fri, 29 Mar 2024 21:53:55 +0100 Subject: [PATCH] first parts of SCD30 calibration --- airrohr-firmware/airrohr-cfg.h.py | 1 + airrohr-firmware/airrohr-firmware.ino | 35 ++++++++++++++++++++++++++- airrohr-firmware/defines.h | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/airrohr-firmware/airrohr-cfg.h.py b/airrohr-firmware/airrohr-cfg.h.py index a5afd39c..42dfbef2 100755 --- a/airrohr-firmware/airrohr-cfg.h.py +++ b/airrohr-firmware/airrohr-cfg.h.py @@ -29,6 +29,7 @@ String dnms_correction String temp_correction String height_above_sealevel +String last_calibration_scd30 Bool gps_read Bool send2dusti Bool ssl_dusti diff --git a/airrohr-firmware/airrohr-firmware.ino b/airrohr-firmware/airrohr-firmware.ino index 0ee7fd1f..47ed95e4 100644 --- a/airrohr-firmware/airrohr-firmware.ino +++ b/airrohr-firmware/airrohr-firmware.ino @@ -173,9 +173,10 @@ namespace cfg bool sps30_read = SPS30_READ; bool bmp_read = BMP_READ; bool bmx280_read = BMX280_READ; - char height_above_sealevel[8] = "0"; + char height_above_sealevel[LEN_HEIGHT_ABOVE_SEALEVEL] = "0"; bool sht3x_read = SHT3X_READ; bool scd30_read = SCD30_READ; + char last_calibration_scd30[LEN_LAST_CALIBRATION_SCD30] = ""; bool ds18b20_read = DS18B20_READ; bool dnms_read = DNMS_READ; char dnms_correction[LEN_DNMS_CORRECTION] = DNMS_CORRECTION; @@ -622,6 +623,10 @@ unsigned long SPS30_read_error_counter = 0; unsigned long SPS30_read_timer = 0; bool sps30_init_failed = false; +bool scd30_calibration = 0; +unsigned long scd30_start_cal = 0; +unsigned long scd30_last_val_change = 0; + float last_value_PPD_P1 = -1.0; float last_value_PPD_P2 = -1.0; float last_value_SDS_P1 = -1.0; @@ -2523,6 +2528,11 @@ static void webserver_status() add_table_row_from_value(page_content, F("SCD30 measurement interval"), String(settingVal)); scd30.getTemperatureOffset(&settingVal); add_table_row_from_value(page_content, F("SCD30 temperature offset"), String(settingVal)); + if (scd30_calibration) { + add_table_row_from_value(page_content, F("SCD30 calibration running since", delayToString(millis() - scd30_start_cal)); + } else { + add_table_row_from_value(page_content, F("SCD30 last calibration"), cfg::last_calibration_scd30); + } } page_content += FPSTR(EMPTY_ROW); @@ -2765,6 +2775,29 @@ static void webserver_reset() end_html_page(page_content); } +/***************************************************************** + * Webserver start SCD30 calibration * + *****************************************************************/ +static void webserver_scd30_calib() { + if (!webserver_request_auth()) + { return; } + + String page_content; + page_content.reserve(512); + + start_html_page(page_content, FPSTR(INTL_SCD30_CALIBRATION)); + debug_outln_info(F("ws: start SCD30 calibration...")); + + page_content += FPSTR(WEB_SCD30_CALIBRATION_CONTENT); + + if (! scd30_calibration) { + scd30_calibration = true; + scd30_start_cal = millis(); + } + + end_html_page(page_content); +} + /***************************************************************** * Webserver data.json * *****************************************************************/ diff --git a/airrohr-firmware/defines.h b/airrohr-firmware/defines.h index 8294be79..40dc37a3 100644 --- a/airrohr-firmware/defines.h +++ b/airrohr-firmware/defines.h @@ -22,6 +22,7 @@ #define LEN_DNMS_CORRECTION 8 #define LEN_TEMP_CORRECTION 8 #define LEN_HEIGHT_ABOVE_SEALEVEL 8 +#define LEN_LAST_CALIBRATION_SCD30 20 #define LEN_SENSEBOXID 30