I'm new to using the esp32 as a microcontroller. I'm currently working on a so-to-say remote control. Since I want to use the esp32 with an external battery I need to put it in deep-sleep after I pressed some buttons to preserve battery.
All that works fine I've connected a small touchpad to put the esp32 into deep sleep mode using the
esp_deep_sleep_start() function . The controller itself goes to sleep and can be woken up using the following 2 lines:
touchAttachInterrupt(T0, wakeCallback, TOUCH_THRESHOLD); esp_sleep_enable_touchpad_wakeup();
In order to communicate with my Raspberry Pi 'Base Station' I decided to use BLE.
My server is configured the following way (where
bleService are global variables):
BLEDevice::init("esp-32-remote"); bleServer = BLEDevice::createServer(); bleServer->setCallbacks(new ServerCallbacks()); bleService = bleServer->createService(SERVICE_UUID); bleCharacteristic = bleService->createCharacteristic( CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE ); bleCharacteristic->addDescriptor(new BLE2902()); bleService->start(); BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); pAdvertising->addServiceUUID(SERVICE_UUID); pAdvertising->setScanResponse(true); pAdvertising->setMinPreferred(0x06); pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising();
Upon regular restart using the buttons everything works fine. I can connect to the device using python and the bluepy library.
If I now wake the controller I can't do anything anymore. The
setup() function gets called and there are no errors, nor does the controller crash due to any code errors (seemingly).
Then the loop function gets called once, and thats it. I can't connect to the device anymore until I press the hardware reset button.
The questions that arise are:
- might there be some error in the way I shutdown the bluetooth module?
- Does the loop function work after being woken up from deep sleep?
Maybe one of you has an idea regarding my issue. If there are more information that I need to provide, don't hesitate to tell me, I'm new to the whole mcu topic and I don't know whats best to provide here.