Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Orcanbull
#52090 Dear All,

I've seen a lot of on the topic of power saving for the ESP8266 however most of the real beneficial powersaving has been done using the "deep_sleep" method. Letting the ESP sleep for 15 minutes wake up and let it do its thing. A very nice concept if you need a logger or something similar.

Downside of this method however is: that it resets the ESP and it requires a new connectiont to be set up which takes time. For a project i'm conducting i need a continuous power saving method which would not loose the WIFI-Connection with the router and with which there is would not be noticible is was at a power saving mode.
After looking into the methods available i came up with the supprisingly easy method. Which i would like to share with you.

Code: Select allvoid fpm_wakup_cb_func1(void)  {
  wifi_fpm_close(); // disable force sleep function
  //wifi_set_opmode(STATION_MODE); // set station mode
  //wifi_station_connect();
  // Serial.println("Woken up...");
}
void sleepNow(int MILI) {
  // Serial.println("Going to sleep...");
  wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // light sleep
  wifi_fpm_open(); // enable force sleep
  wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1); // Set wakeup callback
  wifi_fpm_do_sleep(MILI * 1000);
  delay(MILI + 10);
}

void setup()
{

 // put setup code here
 // Connect to your Wireless here
}

void loop()
{
 sleepNow(100)  // sleep for 100 milis
 // execute code here
}


Using a 100 mili second delay it reduced my powercossumption from 70 mA to 8 mA on a 12V system with a switching power regulater. On the actual 3v3 line it reduced my powercossumtipn from 70 mA to 12 mA

Right now im capable of running the entire system for 7 hours on a capacitor bank which can be charged within 1 minute.

I hope this will help some of you who are looking to save some power for the ESP8266


Kind Regards,
Orcanbull



ps. I'm new to this forum but have been working wiht the ESP for a long time already if you have any question please send me a message and i will take a look at your problems
User avatar
By frjariello
#53834 Hi,
thanks for sharing your code.
Even your example uses the time for wake up from sleep mode, but you know any method for wake him from a digital input?
I need to monitor a digital input, and then send only when status changes

Thanks

bye bye
User avatar
By picstart
#53858 I tested the above code and it will stop working after several dozen cycles.
It goes to sleep but won't wake up.
This is an obvious omitted requirement that needs adding for the compilation
[code]
extern "C"
{
#include "user_interface.h"
}
[/code]