

Then, the battery voltage in mV is read as in uint32_t getVcc = ESP.getVcc()

#DEEPSLEEP ESP8266 CODE#
In the code example above, the ESP8266 is configured to read the V3.3 voltage by placing ADC_MODE(ADC_VCC) on top of the sketch. give the web browser time to receive the data you've gotten a character on the current line character) and the line is blank, the http request has ended,Ĭlient.println("Content-Type: text/html") Ĭlient.println("Connection: close") // the connection will be closed after completion of the responseĬlient.println("Refresh: 5") // refresh the page automatically every 5 secĬlient.println("Battery voltage is: ") // refresh the page automatically every 5 sec if you've gotten to the end of the line (received a newline an http request ends with a blank line WiFiClient client = server.available() // Listen for incoming clients Print local IP address and start web server
#DEEPSLEEP ESP8266 PASSWORD#
Connect to Wi-Fi network with SSID and password

But there is a method to detect a discharged battery indirectly, by measuring the input voltage of ESP8266 – that would be V3.3. By the way most ESP8266 boards are designed, one cannot read the battery voltage Vin without external components. Serial.println("connecting to AP " STASSID) Serial.println("waking WiFi up, sleeping 5s") an average of 20mA with a Wemos D1 mini during this period, a simple amp meter shows The below is a static class method, which is similar to a function, so it's ok. No global object methods or C++ exceptions can be called in here! (global class instances like WiFi, Serial. Global WiFi constructors are not called yet from nonos-sdk's user entry point user_init() preinit() is called before system startup When dealing with slow sensors such as the DGS-H2S sensor from SPEC sensors, one can use this trick to keep the modem off while the sensor data is gathered and to turn on the modem just before uploading to online services. It allows the ESP8266 to start with the modem off, then to start the modem at the desired moment in the code. This is a neat trick I found in the Arduino examples, in ESP8266 board version 2.5.0 (or higher). That means that the EEPROM will wear in less than one year. The AT25SF041 used by ESP8266 Thing Dev is rated for 100,000 Program/Erase Cycles. But, if a node wakes up every five minutes, this will result in having 288 writes to the EEPROM per day. Of course, one can save some context variables in the EEPROM. On other boards, one has to use a wire to connect the RST and GPIO16 pins.Īnother aspect is that the ESP8266 will lose everything in its memory, and it will run the code just as it does when it’s powered on for the first time. On the ESP8266 Thing Dev you do this by closing the SJ2 jumper. However, there’s a catch: to wake up the ESP8266 one has to connect the RST pin to GPIO16 (WAKE). Serial.println("Going into deep sleep for 20 seconds") ĮSP.deepSleep(20e6) // 20e6 is 20 microseconds deepSleep(sleepTimeSeconds * 1000000) #include On Arduino IDE one can put the ESP8266 in deep sleep mode by using ESP. * On some routers you cannot change the DTIM value ESP8266 deep sleepįor a sensor node that wakes up and sends data from time to time, the most interesting is the deep sleep mode. There are three sleep modes, as detailed in the table below: Then, we go deep into the ESP8266 sleep modes. On other boards, one has to physically remove the LED – SMD hot tweezers are a must. Some ESP8266 boards have a trace that has to be cut, such as the ESP8266 Thing Dev I’m using in this tutorial. The first and the simplest way to cut down a few milliamps is to remove the power LED. So, this blog post is about implementing some strategies to reduce the power consumption of ESP8266 modules and of protecting LiPo batteries from over-discharging. Still, to achieve good results I have to reduce the power draw of the ESP8266 to the minimum possible, and I also have to provide a means to protect the LiPo battery when its voltage drops below-given value (typically 3V).īy itself, this proves to be a challenging thing – enough to become a separate blog post. I have found a 9800mAh LiPo battery that should provide me enough juice to run for several months. One of the challenges I’m facing is running the sensor node on battery power, and it should be able to run for extended periods with no human intervention. These days I’m working on a somewhat bigger project, a sensor node with ESP8266 which has to collect some sensor data and upload the sensor values to cloud services.
