I have a BLE device that follows the following forkflow: sleep before pressing a button (on the device) → Wake up and advertise for 60 seconds → Wait until the phone asks for data → send data → close the connection and sleep mode until the next button appears .
This means that the device does not support a permanent BLE connection. I need to connect to the device when it wakes up. I am considering two different strategies:
- Run a scan only for the first time. Save the MAC address of the device. Call
connectGatt with autoConnect to true . Wait for automatic connection if the device is disconnected. - A call to
connectGatt with autoConnect to false . close BluetoothGatt and start a new scan immediately after disconnecting the device.
I believe the first approach is better in terms of energy consumption. But I saw several suggestions not to use autoConnect true .
I have a bad opinion about the second approach, because the docs say: “ Never look at the loop and do not set a time limit for scanning ” / Probably I should scan 3 seconds, and not wait 30 seconds. But it looks like a loop.
Please tell me which strategy is better. Considering the second approach, is it normal to scan all the time (with pauses)? Maybe there are some best practices for implementing a similar workflow?
source share