Reputation: 13
I have a M5StickC device, that is basically a battery operated ESP32.
What I want to achieve: I want the M5StickC device to wirelessly cause an Android device do something when a button is pressed on the M5StickC. The M5StickC should only wake up when button is pressed, do the thing and then sleep and wake up again when button is pressed again.
What I have tried: I have found example codes on the internet and was able to make a 2-way BT serial connection, but the problem is that the Android device is the one that starts the connection. Also I would have to keep the devices connected all the time to receive button presses. As the M5StickC device is battery operated, it needs to conserve power and can not be on 24/7. Also it does not look like a good idea to constantly try to connect to the M5Stick device from Android (by polling) and asking whether the button was pressed, as that will probably drain the phone battery.
Can anyone please point me in the right direction how to achieve this? I am experienced in software development, so I can figure things out. I am just lost right now.
(I don't care if it's Bluetooth Classic or BLE.)
Upvotes: 1
Views: 228
Reputation: 18452
Let Android be the central and use connectGatt with the autoConnect parameter set to true. That will result in a low duty cycle initiate attempt as well as automatic re-connect attempts that won't drain the battery.
Upvotes: 1