From fc4b76c057952ea7a072f6e3d88e111af5c080ed Mon Sep 17 00:00:00 2001 From: Georgi Vidinski Date: Wed, 19 Oct 2022 07:00:40 +0300 Subject: [PATCH 1/2] Added keepAlive period in favor of web interface; --- airrohr-firmware/airrohr-firmware.ino | 22 ++++++++++++++-------- airrohr-firmware/defines.h | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/airrohr-firmware/airrohr-firmware.ino b/airrohr-firmware/airrohr-firmware.ino index 0b915bff..0b5fc3a6 100644 --- a/airrohr-firmware/airrohr-firmware.ino +++ b/airrohr-firmware/airrohr-firmware.ino @@ -48,8 +48,8 @@ ************************************************************************ * * latest build using lib 3.1.0 - * DATA: [==== ] 41.5% (used 34000 bytes from 81920 bytes) - * PROGRAM: [====== ] 58.0% (used 605529 bytes from 1044464 bytes) + * DATA: [==== ] 42.2% (used 34592 bytes from 81920 bytes) + * PROGRAM: [====== ] 58.8% (used 614105 bytes from 1044464 bytes) * ************************************************************************/ @@ -658,6 +658,8 @@ IPAddress addr_static_subnet; IPAddress addr_static_gateway; IPAddress addr_static_dns; + + #define msSince(timestamp_before) (act_milli - (timestamp_before)) const char data_first_part[] PROGMEM = "{\"software_version\": \"" SOFTWARE_VERSION_STR "\", \"sensordatavalues\":["; @@ -1391,6 +1393,7 @@ static void end_html_page(String &page_content) server.sendContent(page_content); } server.sendContent_P(WEB_PAGE_FOOTER); + } static void add_form_input(String &page_content, const ConfigShapeId cfgid, const __FlashStringHelper *info, const int length) @@ -2697,6 +2700,8 @@ static void webserver_not_found() *****************************************************************/ static void setup_webserver() { + //server.addHandler( new AllRequestHandler()); + server.on("/", webserver_root); server.on(F("/config"), webserver_config); server.on(F("/wifi"), webserver_wifi); @@ -2713,6 +2718,7 @@ static void setup_webserver() server.on(F("/favicon.ico"), webserver_favicon); server.on(F(STATIC_PREFIX), webserver_static); server.onNotFound(webserver_not_found); + debug_outln_info(F("Starting Webserver... "), WiFi.localIP().toString()); server.begin(); @@ -5942,7 +5948,6 @@ else if (cfg::ips_read) *****************************************************************/ void loop(void) { - unsigned long sleep = SLEEPTIME_MS; String result_PPD, result_SDS, result_PMS, result_HPM, result_NPM, result_IPS; String result_GPS, result_DNMS; @@ -5952,10 +5957,11 @@ void loop(void) act_milli = millis(); send_now = msSince(starttime) > cfg::sending_intervall_ms; - if (send_now) - { - sleep = 0; - } + unsigned int pastTime = act_milli - last_page_load; + bool keepAlive = pastTime < KEEP_ALIVE_TIME_MS; + unsigned long sleep = send_now || keepAlive + ? 0 + : SLEEPTIME_MS; // Wait at least 30s for each NTP server to sync if (!sntp_time_set && send_now && @@ -6274,7 +6280,7 @@ void loop(void) // Sleep if all of the tasks have an event in the future. The chip can then // enter a lower power mode. - if (cfg::powersave) { + if (cfg::powersave && sleep > 0) { delay(sleep); } diff --git a/airrohr-firmware/defines.h b/airrohr-firmware/defines.h index 8294be79..6bfc1a13 100644 --- a/airrohr-firmware/defines.h +++ b/airrohr-firmware/defines.h @@ -47,6 +47,7 @@ * Constants * ******************************************************************/ constexpr const unsigned long SLEEPTIME_MS = 250; +constexpr const unsigned long KEEP_ALIVE_TIME_MS = 30000; constexpr const unsigned long SAMPLETIME_MS = 30000; // time between two measurements of the PPD42NS constexpr const unsigned long SAMPLETIME_SDS_MS = 1000; // time between two measurements of the SDS011, PMSx003, Honeywell PM sensor constexpr const unsigned long WARMUPTIME_SDS_MS = 15000; // time needed to "warm up" the sensor before we can take the first measurement From 39f6bdac961d04af022729ed61b83ed423e75c2f Mon Sep 17 00:00:00 2001 From: Georgi Vidinski Date: Mon, 30 Sep 2024 05:09:03 +0300 Subject: [PATCH 2/2] Add updated info about memory ussage; --- airrohr-firmware/airrohr-firmware.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/airrohr-firmware/airrohr-firmware.ino b/airrohr-firmware/airrohr-firmware.ino index 41293ae1..7b6b4cb4 100644 --- a/airrohr-firmware/airrohr-firmware.ino +++ b/airrohr-firmware/airrohr-firmware.ino @@ -48,9 +48,9 @@ * * ************************************************************************ * - * latest build using lib 3.1.0 - * DATA: [==== ] 42.2% (used 34592 bytes from 81920 bytes) - * PROGRAM: [====== ] 58.8% (used 614105 bytes from 1044464 bytes) + * latest build using lib 2.6.2 + * DATA: [==== ] 41.7% (used 34128 bytes from 81920 bytes) + * PROGRAM: [====== ] 67.2% (used 701371 bytes from 1044464 bytes) * ************************************************************************/