Browse Source

Merge pull request #1576 from mcspr/wifi/sleep-setting

Set wifi sleep mode from settings
rules-rpn
Xose Pérez 5 years ago
committed by GitHub
parent
commit
0512fdd6f6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 17 deletions
  1. +3
    -12
      code/espurna/system.ino
  2. +18
    -3
      code/espurna/utils.ino
  3. +4
    -2
      code/espurna/wifi.ino

+ 3
- 12
code/espurna/system.ino View File

@ -10,9 +10,7 @@ Copyright (C) 2018 by Xose Pérez <xose dot perez at gmail dot com>
// -----------------------------------------------------------------------------
#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP
unsigned long _loop_delay = 0;
#endif
bool _system_send_heartbeat = false;
unsigned char _heartbeat_mode = HEARTBEAT_MODE;
@ -75,11 +73,9 @@ bool systemGetHeartbeat() {
return _system_send_heartbeat;
}
#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP
unsigned long systemLoopDelay() {
return _loop_delay;
}
#endif
unsigned long systemLoadAverage() {
return _load_average;
@ -160,10 +156,7 @@ void systemLoop() {
// -------------------------------------------------------------------------
// Power saving delay
// -------------------------------------------------------------------------
#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP
delay(_loop_delay);
#endif
if (_loop_delay) delay(_loop_delay);
}
@ -202,10 +195,8 @@ void systemSetup() {
_systemSetupSpecificHardware();
// Cache loop delay value to speed things (recommended max 250ms)
#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP
_loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str());
_loop_delay = constrain(_loop_delay, 0, 300);
#endif
_loop_delay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str());
_loop_delay = constrain(_loop_delay, 0, 300);
// Register Loop
espurnaRegisterLoop(systemLoop);


+ 18
- 3
code/espurna/utils.ino View File

@ -368,6 +368,16 @@ void infoMemory(const char * name, unsigned int total_memory, unsigned int free_
}
const char* _info_wifi_sleep_mode(WiFiSleepType_t type) {
switch (type) {
case WIFI_NONE_SLEEP: return "NONE";
case WIFI_LIGHT_SLEEP: return "LIGHT";
case WIFI_MODEM_SLEEP: return "MODEM";
default: return "UNKNOWN";
}
}
void info() {
DEBUG_MSG_P(PSTR("\n\n---8<-------\n\n"));
@ -469,9 +479,14 @@ void info() {
#if ADC_MODE_VALUE == ADC_VCC
DEBUG_MSG_P(PSTR("[MAIN] Power: %u mV\n"), ESP.getVcc());
#endif
#if WIFI_SLEEP_MODE != WIFI_NONE_SLEEP
if (systemLoopDelay()) {
DEBUG_MSG_P(PSTR("[MAIN] Power saving delay value: %lu ms\n"), systemLoopDelay());
#endif
}
const WiFiSleepType_t sleep_mode = WiFi.getSleepMode();
if (sleep_mode != WIFI_NONE_SLEEP) {
DEBUG_MSG_P(PSTR("[MAIN] WiFi Sleep Mode: %s\n"), _info_wifi_sleep_mode(sleep_mode));
}
// -------------------------------------------------------------------------
@ -606,4 +621,4 @@ bool isNumber(const char * s) {
}
}
return digit;
}
}

+ 4
- 2
code/espurna/wifi.ino View File

@ -75,6 +75,10 @@ void _wifiConfigure() {
jw.enableScan(getSetting("wifiScan", WIFI_SCAN_NETWORKS).toInt() == 1);
unsigned char sleep_mode = getSetting("wifiSleep", WIFI_SLEEP_MODE).toInt();
sleep_mode = constrain(sleep_mode, 0, 2);
WiFi.setSleepMode(static_cast<WiFiSleepType_t>(sleep_mode));
}
void _wifiScan(uint32_t client_id = 0) {
@ -603,8 +607,6 @@ void wifiRegister(wifi_callback_f callback) {
void wifiSetup() {
WiFi.setSleepMode(WIFI_SLEEP_MODE);
_wifiInject();
_wifiConfigure();


Loading…
Cancel
Save