Skip to content

Commit 37d26c6

Browse files
authored
Merge pull request #967 from gvidinski/fix_power_saving
Added KEEP_ALIVE_TIME_MS period in favor of web interface;
2 parents b51a4ef + 39f6bda commit 37d26c6

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

airrohr-firmware/airrohr-firmware.ino

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
* *
4949
************************************************************************
5050
*
51-
* latest build
52-
* RAM: [==== ] 41.8% (used 34220 bytes from 81920 bytes)
53-
* Flash: [======= ] 67.1% (used 701191 bytes from 1044464 bytes)
54-
*
51+
* latest build using lib 2.6.2
52+
* DATA: [==== ] 41.7% (used 34128 bytes from 81920 bytes)
53+
* PROGRAM: [====== ] 67.2% (used 701371 bytes from 1044464 bytes)
54+
*
5555
************************************************************************/
5656

5757
#include <WString.h>
@@ -661,6 +661,8 @@ IPAddress addr_static_subnet;
661661
IPAddress addr_static_gateway;
662662
IPAddress addr_static_dns;
663663

664+
665+
664666
#define msSince(timestamp_before) (act_milli - (timestamp_before))
665667

666668
const char data_first_part[] PROGMEM = "{\"software_version\": \"" SOFTWARE_VERSION_STR "\", \"sensordatavalues\":[";
@@ -1401,6 +1403,7 @@ static void end_html_page(String &page_content)
14011403
server.sendContent(page_content);
14021404
}
14031405
server.sendContent_P(WEB_PAGE_FOOTER);
1406+
14041407
}
14051408

14061409
static void add_form_input(String &page_content, const ConfigShapeId cfgid, const __FlashStringHelper *info, const int length)
@@ -2709,6 +2712,8 @@ static void webserver_not_found()
27092712
*****************************************************************/
27102713
static void setup_webserver()
27112714
{
2715+
//server.addHandler( new AllRequestHandler());
2716+
27122717
server.on("/", webserver_root);
27132718
server.on(F("/config"), webserver_config);
27142719
server.on(F("/wifi"), webserver_wifi);
@@ -2725,6 +2730,7 @@ static void setup_webserver()
27252730
server.on(F("/favicon.ico"), webserver_favicon);
27262731
server.on(F(STATIC_PREFIX), webserver_static);
27272732
server.onNotFound(webserver_not_found);
2733+
27282734

27292735
debug_outln_info(F("Starting Webserver... "), WiFi.localIP().toString());
27302736
server.begin();
@@ -5972,7 +5978,6 @@ else if (cfg::ips_read)
59725978
*****************************************************************/
59735979
void loop(void)
59745980
{
5975-
unsigned long sleep = SLEEPTIME_MS;
59765981
String result_PPD, result_SDS, result_PMS, result_HPM, result_NPM, result_IPS;
59775982
String result_GPS, result_DNMS, result_SCD30;
59785983

@@ -5982,10 +5987,11 @@ void loop(void)
59825987
act_milli = millis();
59835988
send_now = msSince(starttime) > cfg::sending_intervall_ms;
59845989

5985-
if (send_now)
5986-
{
5987-
sleep = 0;
5988-
}
5990+
unsigned int pastTime = act_milli - last_page_load;
5991+
bool keepAlive = pastTime < KEEP_ALIVE_TIME_MS;
5992+
unsigned long sleep = send_now || keepAlive
5993+
? 0
5994+
: SLEEPTIME_MS;
59895995

59905996
// Wait at least 30s for each NTP server to sync
59915997
if (!sntp_time_set && send_now &&
@@ -6306,7 +6312,7 @@ void loop(void)
63066312

63076313
// Sleep if all of the tasks have an event in the future. The chip can then
63086314
// enter a lower power mode.
6309-
if (cfg::powersave) {
6315+
if (cfg::powersave && sleep > 0) {
63106316
delay(sleep);
63116317
}
63126318

airrohr-firmware/defines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* Constants *
4848
******************************************************************/
4949
constexpr const unsigned long SLEEPTIME_MS = 250;
50+
constexpr const unsigned long KEEP_ALIVE_TIME_MS = 30000;
5051
constexpr const unsigned long SAMPLETIME_MS = 30000; // time between two measurements of the PPD42NS
5152
constexpr const unsigned long SAMPLETIME_SDS_MS = 1000; // time between two measurements of the SDS011, PMSx003, Honeywell PM sensor
5253
constexpr const unsigned long WARMUPTIME_SDS_MS = 15000; // time needed to "warm up" the sensor before we can take the first measurement

0 commit comments

Comments
 (0)