Skip to content

Commit

Permalink
Merge pull request #967 from gvidinski/fix_power_saving
Browse files Browse the repository at this point in the history
Added KEEP_ALIVE_TIME_MS period in favor of web interface;
  • Loading branch information
ricki-z authored Oct 13, 2024
2 parents b51a4ef + 39f6bda commit 37d26c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
26 changes: 16 additions & 10 deletions airrohr-firmware/airrohr-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
* *
************************************************************************
*
* latest build
* RAM: [==== ] 41.8% (used 34220 bytes from 81920 bytes)
* Flash: [======= ] 67.1% (used 701191 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)
*
************************************************************************/

#include <WString.h>
Expand Down Expand Up @@ -661,6 +661,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\":[";
Expand Down Expand Up @@ -1401,6 +1403,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)
Expand Down Expand Up @@ -2709,6 +2712,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);
Expand All @@ -2725,6 +2730,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();
Expand Down Expand Up @@ -5972,7 +5978,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, result_SCD30;

Expand All @@ -5982,10 +5987,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 &&
Expand Down Expand Up @@ -6306,7 +6312,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);
}

Expand Down
1 change: 1 addition & 0 deletions airrohr-firmware/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37d26c6

Please sign in to comment.