Hello,
I'm pretty new to this, but I've been trying to chip away at different tutorials and example projects.
My goal is to have an app that autoconnects to specific, saved bluetooth devices.
I have a BlueFruit Circuit Playground with the bleuart.ino example sketch.
My problem is that I connect, then refresh the companion screen to simulate restart. The device is already connected (solid red light), but the app thinks it is not connected and the state of the app doesn't match the connection status. IsDeviceConnected and ConnectedDeviceName are false or blank. So I'm trying to handle this case.
I also get some strange behavior where the device would disconnect and reconnect multiple times.
The current (intended) workflow is
- App Loads
- If there is already a BLE device connected, show that view and display the name of the device connected.
-> Otherwise Start a Clock, and start scanning for bluetooth devices nearby. - As devices are found, check for the BLE device name to contain a keyword. (I figure I can set that).
-> If the name doesn't match the keyword, it ignores that device.
-> Otherwise it puts it in a list. - When the clock times out, stop scanning for devices. Check the list of "filtered" devices against the database of saved devices by MAC address (I figured those will be unique).
-> If there's one match - connect to it.
-> If there's no matches, show the list of "filtered" devices for the user to select and connect to that.
-> If there's more than one match, show the list of "filtered" devices for the user to select and connect to that. - If a user selected a device, and we connected successfully, try to add it to the database for next time.
Is there a trick to some of the BluetoothLE extension statuses? Do I need delays or communication initialization step? Or maybe there's a better way for me to check the connection status?
I would very much appreciate any feedback or guidance to improve.
Thanks so much!
DB_Autoconnect_BLE.aia (211.0 KB)