Comments (14)
You should be sure to disconnect and turn off the radio before deep sleep.
#include <WiFi.h>
#include <esp_wifi.h>
...
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
esp_wifi_deinit();
esp_deep_sleep_start();
from arduino-esp32.
I added those 3 lines of code. However, there are still connection issues and the board reboots after about 5 s.
13:04:28.880 -> Wakeup was not caused by deep sleep: 0
13:04:28.880 -> [ 3709][W][WiFiGeneric.cpp:639] setTxPower(): Neither AP or STA has been started
13:04:28.880 -> [ 3726][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 9 - WIFI_READY
13:04:28.974 -> [ 3809][V][STA.cpp:184] _onStaEvent(): STA Started
13:04:28.974 -> [ 3810][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 11 - STA_START
13:04:28.974 -> [ 3811][V][STA.cpp:110] _onStaArduinoEvent(): Arduino STA Event: 11 - STA_START
13:04:29.488 -> ........[ 8180][V][STA.cpp:214] _onStaEvent(): STA Disconnected: SSID: MYSSID, BSSID: 34:81:c4:1c:4b:f3, Reason: 2
13:04:33.330 -> [ 8181][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 14 - STA_DISCONNECTED
13:04:33.330 -> [ 8182][V][STA.cpp:110] _onStaArduinoEvent(): Arduino STA Event: 14 - STA_DISCONNECTED
13:04:33.330 -> [ 8183][W][STA.cpp:135] _onStaArduinoEvent(): Reason: 2 - AUTH_EXPIRE
13:04:33.330 -> [ 8183][D][STA.cpp:153] _onStaArduinoEvent(): WiFi Reconnect Running
13:04:33.330 -> [ 8184][W][STA.cpp:533] disconnect(): STA already disconnected.
13:04:33.491 -> ....ESP-ROM:esp32c6-20220919
13:04:35.085 -> Build:Sep 19 2022
13:04:35.085 -> rst:0xc (SW_CPU),boot:0x8 (SPI_FAST_FLASH_BOOT)
13:04:35.085 -> Saved PC:0x4001975a
13:04:35.118 -> SPIWP:0xee
from arduino-esp32.
After deep sleep wake up wifi needs to be started again. Have you added this too?
from arduino-esp32.
I have added the 3 lines you suggested before calling esp_deep_sleep_start(). My code looks like this:
/*
Simple Deep Sleep with Timer Wake Up
=====================================
ESP32 offers a deep sleep mode for effective power
saving as power is an important factor for IoT
applications. In this mode CPUs, most of the RAM,
and all the digital peripherals which are clocked
from APB_CLK are powered off. The only parts of
the chip which can still be powered on are:
RTC controller, RTC peripherals ,and RTC memories
This code displays the most basic deep sleep with
a timer to wake it up and how to store data in
RTC memory to use it over reboots
This code is under Public Domain License.
Author:
Pranav Cherukupalli <[email protected]>
*/
#include <WiFi.h>
#include <esp_wifi.h>
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 10 /* Time ESP32 will go to sleep (in seconds) */
#define STA_SSID "MYSSID"
#define STA_PASS "MYPW"
RTC_DATA_ATTR int bootCount = 0;
/*
Method to print the reason by which ESP32
has been awaken from sleep
*/
void print_wakeup_reason() {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch (wakeup_reason) {
case ESP_SLEEP_WAKEUP_EXT0: Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1: Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER: Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP: Serial.println("Wakeup caused by ULP program"); break;
default: Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
}
}
void setup() {
Serial.begin(115200);
delay(3000); //Take some time to open up the Serial Monitor
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
//Print the wakeup reason for ESP32
print_wakeup_reason();
//WiFi test
WiFi.setTxPower(WIFI_POWER_MINUS_1dBm);
WiFi.begin(STA_SSID, STA_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
/*
First we configure the wake up source
We set our ESP32 to wake up every 5 seconds
*/
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds");
/*
Next we decide what all peripherals to shut down/keep on
By default, ESP32 will automatically power down the peripherals
not needed by the wakeup source, but if you want to be a poweruser
this is for you. Read in detail at the API docs
http://esp-idf.readthedocs.io/en/latest/api-reference/system/deep_sleep.html
Left the line commented as an example of how to configure peripherals.
The line below turns off all RTC peripherals in deep sleep.
*/
//esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
//Serial.println("Configured all RTC Peripherals to be powered down in sleep");
/*
Now that we have setup a wake cause and if needed setup the
peripherals state in deep sleep, we can now start going to
deep sleep.
In the case that no wake up sources were provided but deep
sleep was started, it will sleep forever unless hardware
reset occurs.
*/
Serial.println("Going to sleep now");
Serial.flush();
digitalWrite(LED_BUILTIN, LOW);
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
esp_wifi_deinit();
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop() {
//This is not going to be called
}
from arduino-esp32.
After deep sleep wake up wifi is in undefined state. You have to init.
from arduino-esp32.
Isn't it enough to call WiFi.begin()?
from arduino-esp32.
Possible issue with power after a brownout - right after WiFi is started.,.
This would explain RTC Memory reset.
Check USB cables, power suply etc.
from arduino-esp32.
@QuickJack - I have tested it with a ESP32-C6-DevKitC-1 V1.2 - No issue found. It runs as expected.
Log:
14:28:47.352 -> ESP-ROM:esp32c6-20220919
14:28:47.352 -> Build:Sep 19 2022
14:28:47.352 -> rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
14:28:47.352 -> SPIWP:0xee
14:28:47.352 -> mode:DIO, clock div:2
14:28:47.352 -> load:0x4086c410,len:0xc64
14:28:47.352 -> load:0x4086e610,len:0x2730
14:28:47.352 -> load:0x40875728,len:0x594
14:28:47.352 -> entry 0x4086c410
14:28:47.352 -> Boot number: 1
14:28:47.352 -> Wakeup was not caused by deep sleep: 0
14:28:47.352 -> ......Setup ESP32 to sleep for every 10 Seconds
14:28:47.352 -> Going to sleep now
14:28:47.352 -> ESP-ROM:esp32c6-20220919
14:28:47.352 -> Build:Sep 19 2022
14:28:47.352 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:28:47.352 -> SPIWP:0xee
14:28:47.352 -> mode:DIO, clock div:2
14:28:47.352 -> load:0x4086c410,len:0xc64
14:28:47.352 -> load:0x4086e610,len:0x2730
14:28:47.352 -> load:0x40875728,len:0x594
14:28:47.352 -> entry 0x4086c410
14:28:47.352 -> Boot number: 2
14:28:47.352 -> Wakeup caused by timer
14:28:47.352 -> ....Setup ESP32 to sleep for every 10 Seconds
14:28:47.352 -> Going to sleep now
14:28:47.352 -> ESP-ROM:esp32c6-20220919
14:28:47.352 -> Build:Sep 19 2022
14:28:47.352 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:28:47.352 -> SPIWP:0xee
14:28:47.352 -> mode:DIO, clock div:2
14:28:47.352 -> load:0x4086c410,len:0xc64
14:28:47.352 -> load:0x4086e610,len:0x2730
14:28:47.352 -> load:0x40875728,len:0x594
14:28:47.352 -> entry 0x4086c410
14:28:47.352 -> Boot number: 3
14:28:47.352 -> Wakeup caused by timer
14:28:47.352 -> ....Setup ESP32 to sleep for every 10 Seconds
14:28:47.352 -> Going to sleep now
14:28:47.352 -> ESP-ROM:esp32c6-20220919
14:28:47.352 -> Build:Sep 19 2022
14:28:47.352 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:28:47.352 -> SPIWP:0xee
14:28:47.352 -> mode:DIO, clock div:2
14:28:47.352 -> load:0x4086c410,len:0xc64
14:28:47.352 -> load:0x4086e610,len:0x2730
14:28:47.352 -> load:0x40875728,len:0x594
14:28:47.352 -> entry 0x4086c410
14:28:47.352 -> Boot number: 4
14:28:47.352 -> Wakeup caused by timer
14:28:47.352 -> ....Setup ESP32 to sleep for every 10 Seconds
14:28:47.352 -> Going to sleep now
14:28:53.510 -> ESP-ROM:esp32c6-20220919
14:28:53.510 -> Build:Sep 19 2022
14:28:53.510 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:28:53.510 -> SPIWP:0xee
14:28:53.510 -> mode:DIO, clock div:2
14:28:53.510 -> load:0x4086c410,len:0xc64
14:28:53.510 -> load:0x4086e610,len:0x2730
14:28:53.510 -> load:0x40875728,len:0x594
14:28:53.510 -> entry 0x4086c410
14:28:56.573 -> Boot number: 5
14:28:56.573 -> Wakeup caused by timer
14:28:57.140 -> ....Setup ESP32 to sleep for every 10 Seconds
14:28:58.661 -> Going to sleep now
14:29:08.631 -> ESP-ROM:esp32c6-20220919
14:29:08.631 -> Build:Sep 19 2022
14:29:08.631 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:29:08.631 -> SPIWP:0xee
14:29:08.631 -> mode:DIO, clock div:2
14:29:08.631 -> load:0x4086c410,len:0xc64
14:29:08.679 -> load:0x4086e610,len:0x2730
14:29:08.679 -> load:0x40875728,len:0x594
14:29:08.679 -> entry 0x4086c410
14:29:11.671 -> Boot number: 6
14:29:11.671 -> Wakeup caused by timer
14:29:12.288 -> ...Setup ESP32 to sleep for every 10 Seconds
14:29:13.283 -> Going to sleep now
14:29:23.246 -> ESP-ROM:esp32c6-20220919
14:29:23.246 -> Build:Sep 19 2022
14:29:23.246 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:29:23.246 -> SPIWP:0xee
14:29:23.246 -> mode:DIO, clock div:2
14:29:23.246 -> load:0x4086c410,len:0xc64
14:29:23.246 -> load:0x4086e610,len:0x2730
14:29:23.246 -> load:0x40875728,len:0x594
14:29:23.246 -> entry 0x4086c410
14:29:26.288 -> Boot number: 7
14:29:26.288 -> Wakeup caused by timer
14:29:26.904 -> ....Setup ESP32 to sleep for every 10 Seconds
14:29:28.420 -> Going to sleep now
14:29:38.392 -> ESP-ROM:esp32c6-20220919
14:29:38.392 -> Build:Sep 19 2022
14:29:38.392 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:29:38.392 -> SPIWP:0xee
14:29:38.392 -> mode:DIO, clock div:2
14:29:38.392 -> load:0x4086c410,len:0xc64
14:29:38.392 -> load:0x4086e610,len:0x2730
14:29:38.392 -> load:0x40875728,len:0x594
14:29:38.392 -> entry 0x4086c410
14:29:41.427 -> Boot number: 8
14:29:41.427 -> Wakeup caused by timer
14:29:42.044 -> ....Setup ESP32 to sleep for every 10 Seconds
14:29:43.559 -> Going to sleep now
14:29:53.493 -> ESP-ROM:esp32c6-20220919
14:29:53.493 -> Build:Sep 19 2022
14:29:53.540 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:29:53.540 -> SPIWP:0xee
14:29:53.540 -> mode:DIO, clock div:2
14:29:53.540 -> load:0x4086c410,len:0xc64
14:29:53.540 -> load:0x4086e610,len:0x2730
14:29:53.540 -> load:0x40875728,len:0x594
14:29:53.540 -> entry 0x4086c410
14:29:56.567 -> Boot number: 9
14:29:56.567 -> Wakeup caused by timer
14:29:57.181 -> ...Setup ESP32 to sleep for every 10 Seconds
14:29:58.173 -> Going to sleep now
14:30:08.108 -> ESP-ROM:esp32c6-20220919
14:30:08.108 -> Build:Sep 19 2022
14:30:08.155 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:30:08.155 -> SPIWP:0xee
14:30:08.155 -> mode:DIO, clock div:2
14:30:08.155 -> load:0x4086c410,len:0xc64
14:30:08.155 -> load:0x4086e610,len:0x2730
14:30:08.155 -> load:0x40875728,len:0x594
14:30:08.155 -> entry 0x4086c410
14:30:11.184 -> Boot number: 10
14:30:11.184 -> Wakeup caused by timer
14:30:11.797 -> ...Setup ESP32 to sleep for every 10 Seconds
14:30:12.790 -> Going to sleep now
14:30:22.771 -> ESP-ROM:esp32c6-20220919
14:30:22.771 -> Build:Sep 19 2022
14:30:22.771 -> rst:0x5 (SLEEP_WAKEUP),boot:0xc (SPI_FAST_FLASH_BOOT)
14:30:22.771 -> SPIWP:0xee
14:30:22.771 -> mode:DIO, clock div:2
14:30:22.771 -> load:0x4086c410,len:0xc64
14:30:22.771 -> load:0x4086e610,len:0x2730
14:30:22.771 -> load:0x40875728,len:0x594
14:30:22.771 -> entry 0x4086c410
14:30:25.802 -> Boot number: 11
14:30:25.802 -> Wakeup caused by timer
14:30:26.418 -> ...Setup ESP32 to sleep for every 10 Seconds
14:30:27.411 -> Going to sleep now
from arduino-esp32.
Thanks for testing this with a different ESP32-C6 HW. It might be a brownout issue. Using a 65W fast charger + a high quality USB cable it happens as well. The LED does not go off for a long time which shows that there are reboots. But I am unable to log the output during this test.
I am using this board: https://www.dfrobot.com/product-2771.html. It's just a few days old. They claim to use a high quality LDO (https://dfimg.dfrobot.com/5d57611a3416442fa39bffca/wiki/6f630301d84caf0e92266e3c5cf11edc.PDF). According to the datasheet, it supports a maximum current of 1A.
It would be interesting if someone could run the sample code with the same board.
from arduino-esp32.
According to https://docs.espressif.com/projects/esp-idf/en/stable/esp32c6/api-reference/kconfig.html#config-esp-brownout-det-lvl-sel there seems to be a way to configure the brownout level for this chip.
from arduino-esp32.
Looking in the support section for the board (the page you linked) it looks like the board design has issues.
from arduino-esp32.
Where exactly do you see this?
from arduino-esp32.
Where exactly do you see this?
This is at the bottom of the product page (https://www.dfrobot.com/product-2771.html)
from arduino-esp32.
So it's definitely a hw design issue. That's very disappointing.
Thanks for helping to find out the reason behind all these strange problems.
from arduino-esp32.
Related Issues (20)
- USB is randomly disconnected from ESP32-S3 HOT 21
- W5500 crash : Stack canary watchpoint triggered (w5500_tsk) HOT 3
- Cannot open source file "fileName.h" (dependency or "Arduino.h") suddently happening after a git.merge HOT 4
- esp 32 not connecting to Mac M2 HOT 16
- TCB data getting semi-randomly corrupted HOT 6
- WiFi.status() always reports WL_STOPPED although connected HOT 6
- ledcWrite() has no option to write a LED-duty to a channel, but only to a specific pin HOT 3
- Add default 16MB partition to esp32wroverkit HOT 1
- 4-mic setup resulting in static and quiet audio HOT 3
- Segment clash error during linking HOT 2
- Arduino_GFX_Library not recognized HOT 4
- v3.0 couldn't keep the correct serial port with Arduino Nano ESP32 once RST button is pressed HOT 13
- HttpClient can not make https requests to some GMSA root CA signed server, TLS handshake failed with error code 0x2080 by mbedtls
- Repeat Timer example broken for 3.0.2 HOT 1
- Core crashes in Adafruit NeoMatrix matrixtest example sketch (32x8 matrix panel) HOT 1
- rtc timestamp, and not update HOT 1
- [Zigbee][XIAO_ESP32C6] Loop restart with Zigbee_Temperature_Sensor.ino example HOT 2
- SD MMC does not initialize when powered by external battery but works fine while powered by USB through PC. HOT 4
- ESP Rainmaker does not work with esp32c3 HOT 3
- HTTPClient writeToStream method reporting Stream write error as too few bytes written due to bug HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-esp32.