Bluetooth not connecting after waking up from deepsleep...

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
netsrac
Posts: 17
Joined: Sun Jun 07, 2020 7:19 pm
Location: Berlin, Germany

Bluetooth not connecting after waking up from deepsleep...

Post by netsrac » Wed Dec 22, 2021 8:52 pm

Hi,

I'm using an ESP32 with the latest version of MicroPython. This is a client for a bluetooth sensor. Everything works fine. I can read values from the remote bluetooth-sensor. I can even disconnect and connect again (my client is based on the ble_sample.py from the MicroPython examples).

Now the problem starts: Once the reading is done I put the machine into deepsleep for 60 seconds. The ESP32 wakes up from sleep, it initialises Bluetooth in the exact same way like before. It scan for devices, find the sensor, trying to connect, but the connection never succeeded.

This is reproducible and repeat as long as I'm waking up from deepsleep. As soon as I power-cycle the ESP32 or press the reset button everything works fine. Until it got trapped in the deepsleep-not-working-cycle again.

Any ideas?

Thanks, Carsten

davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Bluetooth not connecting after waking up from deepsleep...

Post by davef » Wed Dec 22, 2021 9:26 pm

Could you do a machine.reset() after wake-up, maybe that is different than a wake from deepsleep()?

Maybe ...
https://lastminuteengineers.com/esp32-d ... p-sources/
However, the RTC memory is kept powered on. So, its contents are preserved during deep sleep and can be retrieved after we wake the chip up. That’s the reason, the chip stores Wi-Fi and Bluetooth connection data in RTC memory before disabling them.

So, if you want to use the data over reboot, store it into the RTC memory by defining a global variable with RTC_DATA_ATTR attribute. For example, RTC_DATA_ATTR int bootCount = 0;

In Deep sleep mode, power is shut off to the entire chip except RTC module. So, any data that is not in the RTC recovery memory is lost, and the chip will thus restart with a reset. This means program execution starts from the beginning once again.
Seems to suggest that a reset should start at the beginning. Hmmm ...

netsrac
Posts: 17
Joined: Sun Jun 07, 2020 7:19 pm
Location: Berlin, Germany

Re: Bluetooth not connecting after waking up from deepsleep...

Post by netsrac » Thu Dec 23, 2021 12:56 pm

Well, I can give it a try. But I also need to save data to the RTC memory and load it after I wake up again. So a machine.reset() - if it works - doesn’t really solve my problem…

davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Bluetooth not connecting after waking up from deepsleep...

Post by davef » Thu Dec 23, 2021 7:38 pm

My thinking was maybe the different reset modes leave the machine in different states. Then I'd need an expert to fix it!

Post Reply