BLE + light sleep, any tips appreciated

karelchik
Posts: 3
Joined: Sun Mar 28, 2021 3:55 pm

BLE + light sleep, any tips appreciated

Postby karelchik » Sun Mar 28, 2021 4:13 pm

Hi guys! We are new to ESP32. Our aim is to develop a system of one central device and multiple peripheral devices, each p. device making measurements with sensors and sending those values to the central device (about once per second). Since peripheral devices are running on batteries, their current consumption has to be as low as possible.

How we think the problem should be solved:
*using BLE
*so-called peripheral devices are servers and the central device is a client
*servers go to light sleep as much as possible
*client connects to servers once and remains connected
*client gets data from servers' characteristics

We have tried using Neil Kolban's library (https://github.com/nkolban/ESP32_BLE_Arduino)

The problem is that once a server is put to light sleep the connection is immediately lost. We suppose that the problem is related to latency and connection interval, because it seems that by default latency is 0 and connection interval is 7.5 ms. We have tried setting higher latency and connection interval by using this function

Code: Select all

void BLEServer::updateConnParams(esp_bd_addr_t remote_bda, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout)
but it seems to not do anything and nRf Connect app still shows the default parameters (interval 7.5 ms, latency 0) when connecting to the server.

We would appreciate it a lot when somebody could point us in the right direction, for example mentioning whether our logic is faulty to begin with or providing some example codes / sources, recommending another library ... etc. Thanks!

PS. We are aware of the automatic light sleep on ESP32 (https://github.com/espressif/esp-idf/is ... -500312453), and got it working. But we haven't been able to fully understand any of esp-idf BLE examples as they are veery long. So any tips on getting a BLE communication going with esp-idf would be very much appreciated.

ndaniels
Posts: 1
Joined: Mon May 20, 2024 1:35 pm

Re: BLE + light sleep, any tips appreciated

Postby ndaniels » Mon May 20, 2024 1:44 pm

I just wanted to bump this thread. Are there any tips to light sleeping more often? As the OP mentioned, it seems if you force a light sleep in either the IDF or Arduino libs it will kill the current connection.

I tried adjusting my connection parameters to extremely large intervals and timeouts with no success. I have the settings for modem sleep implemented in my build (Arduino + IDF using platformio). I'm able to reduce my current quite a bit, but really want to get everything I can out of a battery driven system.

Code: Select all

        esp_ble_conn_update_params_t conn_params = {0};
        BLEAddress address = pClient->getPeerAddress();
        memcpy(conn_params.bda, address.getNative(), sizeof(conn_params.bda));
        conn_params.min_int = 0x0032;
        conn_params.max_int = 0x0032;
        conn_params.latency = 0;
        conn_params.timeout = 1000;

        esp_err_t errRc = esp_ble_gap_update_conn_params(&conn_params);
        if (errRc != ESP_OK) {
            Serial.printf("Failed to update connection parameters: %d\n", errRc);
        } else {
            Serial.println("Connection parameters updated");
        }
This is what I'm using right now on my client. The speed here is quite fast, but I'm doing some work on my server to update characteristics less often to keep the current down. I'd rather update the characteristic, then light sleep without dropping the client connection.
Attachments
sdkconfig - Copy.esp32-s3-devkitc-1.txt
(70.73 KiB) Downloaded 75 times

Who is online

Users browsing this forum: No registered users and 105 guests