Chat freely about anything...

User avatar
By Sgt laGrange
#29511 Hi,

I've been trying to reduce the power consumption of my ESP8266 sensor project. One (obvious) direction is to use deep sleep inbetween reads. While putting the unit in deep sleep mode (and waking up) is not a problem, the various sleep modes should contribute to further power savings: WAKE_RF_DEFAULT, WAKE_RFCAL, WAKE_NO_RFCAL and WAKE_RF_DISABLED. I have a problem and a few questions that I couldn't find any answers to.

1) There seems to be no difference in power consumption when using different sleep modes. I took measurements with an Arduino and INA-19 in all 4 modes (~500 reads/sec) and there is always a ~400 mA spike at the beginning and no visible differences in total power consumption. I'm happy to post the graphs in case anyone's interested. If I understand correctly, the WAKE_RF_DISABLED mode should prevent the unit from connecting to WiFi altogether, however it seems to make no difference and the ESP operates normally after waking up.

Below is the relevant function. I've been experimenting with different options, including those commented out.
Code: Select all    void sleep (long sleep_duration, byte sleep_mode) {
      //system_deep_sleep_set_option(sleep_mode);
      //ESP.deepSleep(sleep_duration * 1000, sleep_mode);
      if (sleep_duration > 9) { //Protection from negative sleep times after counter reset
        //system_deep_sleep(sleep_duration * 1000);
        if (sleep_mode == 0) {Serial.println ("Mode = WAKE_RF_DEFAULT"); ESP.deepSleep(sleep_duration * 1000, WAKE_RF_DEFAULT);}
        if (sleep_mode == 1) {Serial.println ("Mode = WAKE_RFCAL"); ESP.deepSleep(sleep_duration * 1000, WAKE_RFCAL);}
        if (sleep_mode == 2) {Serial.println ("Mode = WAKE_NO_RFCAL"); ESP.deepSleep(sleep_duration * 1000, WAKE_NO_RFCAL);}
        if (sleep_mode == 3) {Serial.println ("Mode = WAKE_RF_DISABLED"); ESP.deepSleep(sleep_duration * 1000, WAKE_RF_DISABLED);}
      } else {
        reset();
      }
      delay(100);
    }



2) Any best practices on how to ensure equal intervals between data uplaods? I put the device to sleep by calling sleep(interval - millis(), sleep_mode);
It always seems to wake up around 15 seconds early for a 5 minute sleep. I'm not after an up to the second accuracy (partially it will vary with how quickly the router can connect) but this seems a bit too much off. The problem are not resets, but consistently early wake ups.

3) What is the difference between deep_sleep_set_option(mode) and system_deep_sleep_set_option(mode) (other than the latter is the one that compiles)? I've seen both in code listings and the Espressif SDK is a bit ambiguous on this as well: the function is called system_deep_sleep_set_option but the parameters section lists it as deep_sleep_set_option(0), (1) etc. Am I using the wrong function or pass a wrong parameter?

4) There is an obvious advantage to using WAKE_NO_RFCAL as it (theoretically) reduces power consumption. I am wondering how "safe" it is. Does not calibrating RF influence the unit's ability to connect to the network? If so, are there "safe" thresholds for how often the ESP8266 should wake with WAKE_RFCAL to ensure proper continuous operation?
User avatar
By WereCatf
#39624 The whole thing is confusing, indeed, and the documentation could definitely be better. What little I've played with the flag I didn't notice them doing anything useful, either. What's more, you can force WiFi to sleep even without using deepSleep():
Code: Select allWiFi.mode(WIFI_OFF);
WiFi.forceSleepBegin();
delay(1); //Needed, at least in my tests WiFi doesn't power off without this for some reason


With these three lines power-consumption should drop to around 15mA and stay there, and as such, is there any reason to use those flag to deepSleep() in the first place? One could just turn WiFi off in setup() and only wake it up when it's needed even without using deepSleep().