ESP8266 module sleep mode

When we use the battery to power esp module, in order to save power. When we want to practice, and we need to solve this problem.
The solution to this problem is to use sleep mode esp module

Type of sleep mode

There are three different sleep modes: modem sleep, light sleep and deep sleep. The following table shows the differences (ESP8266 information data table) between each mode.
enter description here
esp low battery solutions for official documents

We can see three kinds of sleep mode wifi are closed. This means that in many cases require a constant connection wifi scenario is not applicable.
Deep Sleep mode is only open clock. Others are closed. The deep sleep is the most energy efficient only 20μA.
Each have their sleep patterns suitable for application scenarios.

Modem sleep

Sleep modem typically used for applications CPU power. An
example of an application that requires real-time pulse width modulation (PWM) light
control of the CPU.
When no constant wifi connection, and the state of the application to be retained, to reduce power consumption is useful.
For this model the control of the control to achieve wifi

WiFi.forceSleepBegin(); // Wifi off
delay();
WiFi.forceSleepWake(); // Wifi on

When you need to go into sleep mode using the first statement
when the need to wake up, to use the second statement.
It can be used in the loop.
Examples

void loop() {
data();
delay(200);
Serial.println(“Going to sleep now”);
WiFi.forceSleepBegin(); // Wifi Off
delay(1000*10); // sleep for 10 seconds
WiFi.forceSleepWake(); // Wifi On
Serial.println(“Wake up”);
}

data () function is used to get the value of the sensor and transmits mqtt
can see after the acquired value, so esp module enters a sleep mode, the sleep 10s, wakes up. Repeat again.
Reference links

Light sleep

Light sleep.
You can still sleep in the loop.
Calls can use light_sleep ()

void light_sleep(){
wifi_station_disconnect();
wifi_set_opmode_current(NULL_MODE);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open(); // Enables force sleep
gpio_pin_wakeup_enable(GPIO_ID_PIN(2), GPIO_PIN_INTR_LOLEVEL);
wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time
}

Set sleep time there is the longest time, the button will wake up by GPIO2 ground.
Data may be transmitted by adjusting the timing of the sleep time.
After wake-up thing to do is connect wifi. It is necessary in the first loop in a wifi connection

Reference ESP8266 Light Sleep with MQTT

Deep sleeping

deep sleep
for the power required, and the transmission value frequently can not use a sleep mode, which should not execute the program data in deep sleep mode. Shutdown equivalent
implementations have two.
The first one is the wake-up timer, the timer switch may be understood to
pass after the code GPIO16 connected RST.
enter description here
Call the function ESP.deepSleep (30e6); (Units us)
so esp module into a deep sleep mode 30s.
30s Wake GPIO16 reached after
long sleep up to 4,294,967,295 μs which is about 71 minutes

esp01使用定时来实现睡眠模式不太好做,需要接出来一个非常小的引脚
enter description here

第二种方式是通过外部触发进行唤醒
enter description here
使用 ESP.deepSleep(0);
进行长时间的深度睡眠状态
当按钮按下 RST有低电平信号,将进行唤醒,唤醒后执行到这条语句将再次睡眠直到下一次按钮按下。
esp01s是同样的方式
enter description here
参考代码

void setup() {
  Serial.begin(115200);
  Serial.setTimeout(2000);

  // Wait for serial to initialize.
  while(!Serial) { }
  
  // Deep sleep mode for 30 seconds, the ESP8266 wakes up by itself when GPIO 16 (D0 in NodeMCU board) is connected to the RESET pin
  //Serial.println("I'm awake, but I'm going into deep sleep mode for 30 seconds");
  //ESP.deepSleep(30e6); 
  
  // Deep sleep mode until RESET pin is connected to a LOW signal (for example pushbutton or magnetic reed switch)
  Serial.println("I'm awake, but I'm going into deep sleep mode until RESET pin is connected to a LOW signal");
  ESP.deepSleep(0); 
}

void loop() {
}

参考ESP8266 Deep Sleep with Arduino IDE (NodeMCU)
参考 ESP8266 Deep sleep mode
参考The sleep states of the ESP8266

补充

对dht11 获取温度值 进行 light sleep模式测试
有可能是模块的原因 获取到的值不准确 因为每次都是获取到的初始化的值 可能会存在问题。(目前还不确定与轻度睡眠有关系没)

更多学习教程

ESP开发学习基础知识

基础知识包括对esp模块的认识与了解 mqtt协议的了解,arduino IDE运用代码编写等等。

  1. arduino基础学习
  2. esp系列模块的介绍
  3. mqtt协议的介绍与使用
  4. 利用mqtt esp模块 基于arduino IDE开发方法
  5. esp模块的AT指令 刷固件
  6. esp模块睡眠模式使用
  7. esp8266-01s介绍与使用
  8. esp8266-12f介绍与使用
  9. NodeMcu介绍与使用
esp开发IOT应用

基于esp8266的模块以及其他模块根据实际的应用场景与需求制作的物联网应用

  1. 基于FRID arduino 继电器 电磁锁开发的FRID门禁系统
  2. esp32-cam获取视频流图像处理
  3. 基于步进电机 esp8266 mqtt开发的自动窗帘控制
  4. 基于DHT11 Esp8266 mqtt获取室内温湿度
  5. 基于CCS811 esp8266 mqtt 获取室内空气质量
  6. Based on infrared remote control intelligent module esp8266 mqtt development
  7. Based ws2812 esp8266 mqtt development of intelligent multi-level lighting
  8. Based ws2812 esp8266 mqtt development of intelligent multi-mode light atmosphere
  9. Broadcast System Intelligent Voice mp3player esp8266 mqtt based development
  10. The wisdom of the comprehensive application of IOT classroom project development
Published 46 original articles · won praise 59 · views 70000 +

Guess you like

Origin blog.csdn.net/Nirvana_6174/article/details/104485963