1 (edited by LeFish 2022-06-30 06:14:37)

Topic: Solved: Optimizing RemoteXY in battery low-power device

Hi there,

First of all: RemoteXY is great! Thank you for this great eco-system!

I am planning to implement a low-power application on a ESP32C3 with BLE.

I have come pretty far and basically everything is working fine. Now I would like to optimize current consumption while no BLE device is connected to the ESP32.

I have activated all the necessary features as stated here: https://github.com/espressif/esp-idf/issues/947

The problem is, that calling the default

remotexy->handler();

function in

void loop() 

prevents the ESP32 to enter light sleep. Therefore the current consumption is 30mA instead of <5mA without calling the handler function.

I tried to simply not call 

remotexy->handler();

periodically without established connection (

remotexy->isConnected() == false

and I come this far:
https://paste.pics/aa26d4d8dec4634c5bf02b34417b60a3
The current consumption drops to <5mA while no device is connected, which is the desired behaviour.

My intention is to call only the bare minimum handler() portion for establishing a connection periodically and only when BLE device is connected calling the full handler.

Would you kindly help me on this?

Thank you!

Best regards
LeFish

2

Re: Solved: Optimizing RemoteXY in battery low-power device

Unfortunately the library does not provide for transferring the ESP to low power consumption.
You will have to implement this in the module responsible for the BLE, it is file  RemoteXYStream_BLEPeripheral.h of RemoteXY library.

3 (edited by LeFish 2022-06-30 05:56:17)

Re: Solved: Optimizing RemoteXY in battery low-power device

Thanks for your reply.

I tried to implement BLE interface myself (->Kodular) all from scratch and got it to work on my android cell phone. So I have some experience in BLE implementation. Disclaimer: Still I am a rookie smile

I already altered RemoteXYStream_BLEDevice_h to optimize power consumption. This is what I did:

...
    // Start advertising
    pServer->getAdvertising()->addServiceUUID(pService->getUUID());
    pServer->getAdvertising()->setMinInterval(0x640); //LeFish
    pServer->getAdvertising()->setMaxInterval(0x640); //LeFish
    pServer->getAdvertising()->start();
    BLEDevice::setPower(ESP_PWR_LVL_N9); //LeFish
...

This is all one can change to optimize power consumption to my knowledge.

Therefore I think BLE Communication is perfectly fine when comparing to my own implementation on which automatic light sleep did work. I come to this statement due to the fact that I had i.e. TickTwo.h (https://github.com/sstaub/TickTwo) implemented. And when using this library this also prevented the ESP to go into light sleep. Some locks must be acquired by this library that prevent esp from going into light sleep. And I think this also applies to RemoteXY.

I tried and the ESP actually goes into light sleeps when not periodically calling the default

remotexy->handler();

but leaving the rest on default.

Therefore I think the "problem" must be some statement within the handler function which prevents the esp from sleep.

Do you have any idea where I could start to dig? I am willing to dig further with your help as I believe RemoteXY is just what I need to finish my project.
If we get this to work it could help others to implement RemoteXY in low power consumption devices.

This is my idea:

My idea is to set some flag within the CRemoteXYStream_BLEDevice::onConnect() which is readable by CRemoteXY::handler ()

If this flag is true the full handler funtion is called. Otherwise only necessary portion (none?) for "standby" (able to accept BLE connections, which is afaik not handled by RemoteXY anyways.)

4

Re: Solved: Optimizing RemoteXY in battery low-power device

Yeah, just got it working:

I simply altered the handler function like so:

void handler () {
    uint8_t connect_flag = 0;
    
    // threads handler

    CRemoteXYThread * pt = data.threads;
    while (pt) {   
      pt->handler ();     
      connect_flag += pt->connect_flag;
      pt = pt->next;
    }
    *data.connect_flag = connect_flag;

    if (connect_flag == 1) // LeFish
    {

      // communications handler    

      CRemoteXYComm * comm = data.comms; 
      while (comm) {
        comm->handler (); 
        comm = comm->next;
      } 

      // connections handler    

      CRemoteXYConnectionComm * connection = data.connections; 
      while (connection) {
        connection->handler (); 
        connection = connection->next;
      }   
    }

Now it connects to the gui and still goes into light sleep when no BLE device is connected.

I think we could mark this as solved...

5

Re: Solved: Optimizing RemoteXY in battery low-power device

that sounds very promissing - i am looking for for low-power consumption as well.
did you put this code behind void loop()?
thanks, thomas