📜 ⬆️ ⬇️

Sleep and self-powered ESP8266

Often the question arises with the autonomous power of the now popular ESP8266 module. This note is without unique photos, but it tells how it is done on C and SDK from Espressif and how much it consumes.



1. Iron intervention


To begin with, if ESP-01 (and it is the most popular and reasonable in this situation), you need to make a jumper with 8 legs esp8266 to pin RST and remove the LED, as shown in the photo above. If the jumper is not made, the module will not exit the Deep Sleep mode.

2. We program


Installation of a set for Windows, made under good article with geektimes .
For example, we take the examples \ dht22_thingspeak project . It is good in that it is very easy to fix it for your purposes of sending temperature and humidity.
')
From the whole project we need user_main.c , which contains the main user code, and user_config.h , which contains the settings.

#define USE_WIFI_MODE STATION_MODE #define WIFI_CLIENTSSID "wifi_net_name" #define WIFI_CLIENTPASSWORD "wifi_net_pass" #define DATA_SEND_DELAY 1000 /* milliseconds */ #define THINGSPEAK_SERVER "narodmon.ru" 

This is the contents of the user_config.h file. Delay sending is not necessary to change, but if you want, then you can. But for a single send - not necessary.

If you need not national monitoring, but something else, write your server in the line. I have my Raspberry IP listed there.

Next, we make changes to the code of the user_main.c file, in the dht22_cb procedure:

 os_sprintf(data, "http://%s/post.php?ID=xx-xx-xx-xx-xx-xxx&T1=%s&H1=%s", THINGSPEAK_SERVER, temp, hum); 

This line specifies everything we need to send. For national monitoring, you can automatically get a MAC address, but in my opinion this is superfluous - it's easier to write once.

Further in the same file, but in the user_init procedure, we set a timer for the hibernation procedure:

 os_timer_disarm(&sleep_timer); os_timer_setfn(&sleep_timer, sleep_cb, NULL); os_timer_arm(&sleep_timer, 5000, 1); //5s 

Here, 5000 is time in milliseconds, and 1 is repeat.

Well, the last one, in fact, is the hibernation procedure itself. In this case, 10 minutes.

 static ETSTimer sleep_timer; LOCAL void ICACHE_FLASH_ATTR sleep_cb(void *arg) { os_timer_disarm(&sleep_timer); system_deep_sleep(600*1000*1000);//second*1000*1000 } 

As a result, we have a module that sleeps 10 minutes, wakes up, sends data from the DHT22 (GPIO2) to the right place and falls asleep for the next 10 minutes.

Until I figured out what is connected with, but 10 minutes swim ± 30 seconds.

3. We measure


Laboratories and megatesters do not have. All measurements were made by a cheap Chinese tester with appropriate accuracy.
In active mode (from waking up to falling asleep) - from 240mA to 360mA. On average, 300mA somewhere around 5-10 seconds.
In sleep - <1mA.
In fact, the tester tried to show some tsiferki, but its accuracy is less than 1mA under great doubt. But I also consider 1 mA when powered from finger-type batteries as a worthy result.

4. Results


You can throw a lot of this project, if you plan a simple stand-alone temperature sensor. At least, the output to the terminal is superfluous.

I don’t even try to judge the real life expectancy from batteries - too little time for such exploitation.

All found on the Internet and is the property of those who wrote. I just gathered in a handful and showed how to press the buttons on the keyboard.

Sources


ESP8266 Community forum
Low Power ESP8266 - Sleeping at 78 micro Amps
ESP8266 SDK API Guide v1.0.0

Source: https://habr.com/ru/post/257141/


All Articles