Skip to main content
Format correction
Source Link

The problem with calling ESP.deepSleep(xx) inside loop() is that watchdog is already activated there, and then a reset occurs during the sleep state.

To fix this, I used the software's own ESP.restart() reset technique after having written a signature to a "not init" variable, as follows:

Variable area:

uint16_t SleepSign __attribute__((section(".noinit"))); // Hot reset / deep sleep signature.

Then, at the beginning of setup() we write the code that tests the content of that uninitialized variable, and if it contains the signature, ESP.deepSleep(xx) is called. In my case I use ESP.deepSleep(0) because I intend for the device to reboot only on a new boot:

void setup()
{
     if (SleepSign == 0xdd11) ESP.deepSleep(0);
     Rest of the initialization:
     ...

Inside loop():
     ...
     if ((millis() - timeconnect) > 300*1000) {
       SleepSign = 0xdd11; // deep sleep at restart
       ESP.restart();
     }
     ...

This system is tested and works correctly, reducing consumption to the minimum specified by espressif. I previously tried to block watch before exiting setup(), but it didn't work, of course:

*((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF

Obviously, if we are interested in using a timed deepSleep, and have the device do anything before going back to sleep, we can assign several values to the SleepSign variable to control the restart, also resetting its value before calling ESP.deepSleep(0):

 void setup()
 {
 if (SleepSign == 0xdd11) {
    SleepSign = 0xffff;
    ESP.deepSleep(xx);
  }
  Rest of the initialization:
  ...

{ if (SleepSign == 0xdd11) { SleepSign = 0xffff; ESP.deepSleep(xx); } Rest of the initialization: ...

The only drawback I find is that the esp will perform a reset before going to sleep, but I don't think that matters much.

The problem with calling ESP.deepSleep(xx) inside loop() is that watchdog is already activated there, and then a reset occurs during the sleep state.

To fix this, I used the software's own ESP.restart() reset technique after having written a signature to a "not init" variable, as follows:

Variable area:

uint16_t SleepSign __attribute__((section(".noinit"))); // Hot reset / deep sleep signature.

Then, at the beginning of setup() we write the code that tests the content of that uninitialized variable, and if it contains the signature, ESP.deepSleep(xx) is called. In my case I use ESP.deepSleep(0) because I intend for the device to reboot only on a new boot:

void setup()
{
     if (SleepSign == 0xdd11) ESP.deepSleep(0);
     Rest of the initialization:
     ...

Inside loop():
     ...
     if ((millis() - timeconnect) > 300*1000) {
       SleepSign = 0xdd11; // deep sleep at restart
       ESP.restart();
     }
     ...

This system is tested and works correctly, reducing consumption to the minimum specified by espressif. I previously tried to block watch before exiting setup(), but it didn't work, of course:

*((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF

Obviously, if we are interested in using a timed deepSleep, and have the device do anything before going back to sleep, we can assign several values to the SleepSign variable to control the restart, also resetting its value before calling ESP.deepSleep(0):

void setup()

{ if (SleepSign == 0xdd11) { SleepSign = 0xffff; ESP.deepSleep(xx); } Rest of the initialization: ...

The only drawback I find is that the esp will perform a reset before going to sleep, but I don't think that matters much.

The problem with calling ESP.deepSleep(xx) inside loop() is that watchdog is already activated there, and then a reset occurs during the sleep state.

To fix this, I used the software's own ESP.restart() reset technique after having written a signature to a "not init" variable, as follows:

Variable area:

uint16_t SleepSign __attribute__((section(".noinit"))); // Hot reset / deep sleep signature.

Then, at the beginning of setup() we write the code that tests the content of that uninitialized variable, and if it contains the signature, ESP.deepSleep(xx) is called. In my case I use ESP.deepSleep(0) because I intend for the device to reboot only on a new boot:

void setup()
{
     if (SleepSign == 0xdd11) ESP.deepSleep(0);
     Rest of the initialization:
     ...

Inside loop():
     ...
     if ((millis() - timeconnect) > 300*1000) {
       SleepSign = 0xdd11; // deep sleep at restart
       ESP.restart();
     }
     ...

This system is tested and works correctly, reducing consumption to the minimum specified by espressif. I previously tried to block watch before exiting setup(), but it didn't work, of course:

*((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF

Obviously, if we are interested in using a timed deepSleep, and have the device do anything before going back to sleep, we can assign several values to the SleepSign variable to control the restart, also resetting its value before calling ESP.deepSleep(0):

 void setup()
 {
 if (SleepSign == 0xdd11) {
    SleepSign = 0xffff;
    ESP.deepSleep(xx);
  }
  Rest of the initialization:
  ...

The only drawback I find is that the esp will perform a reset before going to sleep, but I don't think that matters much.

Format correction
Source Link

The problem with calling ESP.deepSleep(xx) inside loop() is that watchdog is already activated there, and then a reset occurs during the sleep state.

To fix this, I used the software's own ESP.restart() reset technique after having written a signature to a "not init" variable, as follows:

Variable area:

uint16_t SleepSign __attribute__((section(".noinit"))); // Hot reset / deep sleep signature.

Then, at the beginning of setup() we write the code that tests the content of that uninitialized variable, and if it contains the signature, ESP.deepSleep(xx) is called. In my case I use ESP.deepSleep(0) because I intend for the device to reboot only on a new boot:

void setup()
{
     if (SleepSign == 0xdd11) ESP.deepSleep(0);
     Rest of the initialization:
     ...

Inside loop():
     ...
     if ((millis() - timeconnect) > 300*1000) {
       SleepSign = 0xdd11; // deep sleep at restart
       ESP.restart();
     }
     ...

This system is tested and works correctly, reducing consumption to the minimum specified by espressif. I previously tried to block watch before exiting setup(), but it didn't work, of course:

*((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF

Obviously, if we are interested in using a timed deepSleep, and have the device do anything before going back to sleep, we can assign several values to the SleepSign variable to control the restart, also resetting its value before calling ESP.deepSleep(0):

void setup()

{ if (SleepSign == 0xdd11) { SleepSign = 0xffff; ESP.deepSleep(xx); } Rest of the initialization: ...

The only drawback I find is that the esp will perform a reset before going to sleep, but I don't think that matters much.

The problem with calling ESP.deepSleep(xx) inside loop() is that watchdog is already activated there, and then a reset occurs during the sleep state.

To fix this, I used the software's own ESP.restart() reset technique after having written a signature to a "not init" variable, as follows:

Variable area:

uint16_t SleepSign __attribute__((section(".noinit"))); // Hot reset / deep sleep signature.

Then, at the beginning of setup() we write the code that tests the content of that uninitialized variable, and if it contains the signature, ESP.deepSleep(xx) is called. In my case I use ESP.deepSleep(0) because I intend for the device to reboot only on a new boot:

void setup()
{
     if (SleepSign == 0xdd11) ESP.deepSleep(0);
     Rest of the initialization:
     ...

Inside loop():
     ...
     if ((millis() - timeconnect) > 300*1000) {
       SleepSign = 0xdd11; // deep sleep at restart
       ESP.restart();
     }
     ...

This system is tested and works correctly, reducing consumption to the minimum specified by espressif. I previously tried to block watch before exiting setup(), but it didn't work, of course:

*((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF

The problem with calling ESP.deepSleep(xx) inside loop() is that watchdog is already activated there, and then a reset occurs during the sleep state.

To fix this, I used the software's own ESP.restart() reset technique after having written a signature to a "not init" variable, as follows:

Variable area:

uint16_t SleepSign __attribute__((section(".noinit"))); // Hot reset / deep sleep signature.

Then, at the beginning of setup() we write the code that tests the content of that uninitialized variable, and if it contains the signature, ESP.deepSleep(xx) is called. In my case I use ESP.deepSleep(0) because I intend for the device to reboot only on a new boot:

void setup()
{
     if (SleepSign == 0xdd11) ESP.deepSleep(0);
     Rest of the initialization:
     ...

Inside loop():
     ...
     if ((millis() - timeconnect) > 300*1000) {
       SleepSign = 0xdd11; // deep sleep at restart
       ESP.restart();
     }
     ...

This system is tested and works correctly, reducing consumption to the minimum specified by espressif. I previously tried to block watch before exiting setup(), but it didn't work, of course:

*((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF

Obviously, if we are interested in using a timed deepSleep, and have the device do anything before going back to sleep, we can assign several values to the SleepSign variable to control the restart, also resetting its value before calling ESP.deepSleep(0):

void setup()

{ if (SleepSign == 0xdd11) { SleepSign = 0xffff; ESP.deepSleep(xx); } Rest of the initialization: ...

The only drawback I find is that the esp will perform a reset before going to sleep, but I don't think that matters much.

Code formatting and fixed typos
Source Link
Greenonline
  • 3.2k
  • 7
  • 37
  • 49

I know it's late to answer, but I think this can still help someone: TheThe problem with calling ESP.deepSleep(xx)ESP.deepSleep(xx) inside "loop"loop() is that whatchdogwatchdog is already activated there, and then a reset occurs during the sleep state. To

To fix this, I used the software's own ESP.restart()ESP.restart() reset technique after having written a signature to a "not init" variable, as follows:

Variable area: uint16_t SleepSign attribute((section(".noinit"))); // Hot reset / deep sleep signature.

uint16_t SleepSign __attribute__((section(".noinit"))); // Hot reset / deep sleep signature.

Then, at the beginning of setup()setup() we write the code that tests the content of that uninitialized variable, and if it contains the signature, ESP.deepSleep(xx)ESP.deepSleep(xx) is called. In my case I use ESP.deepSleep(0)ESP.deepSleep(0) because I intend for the device to reboot only on a new boot:

void setup() { if (SleepSign == 0xdd11) ESP.deepSleep(0); Rest of the initialization: ...

void setup()
{
     if (SleepSign == 0xdd11) ESP.deepSleep(0);
     Rest of the initialization:
     ...

Inside loop():
     ...
     if ((millis() - timeconnect) > 300*1000) {
       SleepSign = 0xdd11; // deep sleep at restart
       ESP.restart();
     }
     ...

Inside loop(): ... if ((millis() - timeconnect) > 300*1000) { SleepSign = 0xdd11; // deep sleep at restart ESP.restart(); } ... ThisThis system is tested and works correctly, reducing consumption to the minimum specified by espressif. I previously tried to block whatdogwatch before exiting "setup()"setup(), but it didn't work, of course: ((volatile uint32_t) 0x60000900) &= ~(1); // Hardware WDT OFF

*((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF

I know it's late to answer, but I think this can still help someone: The problem with calling ESP.deepSleep(xx) inside "loop" is that whatchdog is already activated there, and then a reset occurs during the sleep state. To fix this, I used the software's own ESP.restart() reset technique after having written a signature to a "not init" variable, as follows:

Variable area: uint16_t SleepSign attribute((section(".noinit"))); // Hot reset / deep sleep signature.

Then, at the beginning of setup() we write the code that tests the content of that uninitialized variable, and if it contains the signature, ESP.deepSleep(xx) is called. In my case I use ESP.deepSleep(0) because I intend for the device to reboot only on a new boot:

void setup() { if (SleepSign == 0xdd11) ESP.deepSleep(0); Rest of the initialization: ...

Inside loop(): ... if ((millis() - timeconnect) > 300*1000) { SleepSign = 0xdd11; // deep sleep at restart ESP.restart(); } ... This system is tested and works correctly, reducing consumption to the minimum specified by espressif. I previously tried to block whatdog before exiting "setup()", but it didn't work, of course: ((volatile uint32_t) 0x60000900) &= ~(1); // Hardware WDT OFF

The problem with calling ESP.deepSleep(xx) inside loop() is that watchdog is already activated there, and then a reset occurs during the sleep state.

To fix this, I used the software's own ESP.restart() reset technique after having written a signature to a "not init" variable, as follows:

Variable area:

uint16_t SleepSign __attribute__((section(".noinit"))); // Hot reset / deep sleep signature.

Then, at the beginning of setup() we write the code that tests the content of that uninitialized variable, and if it contains the signature, ESP.deepSleep(xx) is called. In my case I use ESP.deepSleep(0) because I intend for the device to reboot only on a new boot:

void setup()
{
     if (SleepSign == 0xdd11) ESP.deepSleep(0);
     Rest of the initialization:
     ...

Inside loop():
     ...
     if ((millis() - timeconnect) > 300*1000) {
       SleepSign = 0xdd11; // deep sleep at restart
       ESP.restart();
     }
     ...

This system is tested and works correctly, reducing consumption to the minimum specified by espressif. I previously tried to block watch before exiting setup(), but it didn't work, of course:

*((volatile uint32_t*) 0x60000900) &= ~(1); // Hardware WDT OFF
Source Link
Loading