I am also having having difficulties with BLE on Mbed for about a year now. I tend to think i was expecting too much from BLE.
Do not use Sparkfun's fork of Mbed OS, they used that for an initial commit but after that Sparkfun is not really updating that repo or actively fixing bugs. You are better off by using the official Mbed OS releases which contain some fixes since the Artemis boards have been released.
As for BLE in Mbed... it is a work in progress and to be honest i really do not understand the concept Mbed is following in this regard. By that i mean:
- they changed to Cordio BLE stack 2-3 years ago. So basically one could program Mbed BLE in Cordio, however i did not find any documentation on that.
- I guess Mbed is trying to come up with their "own" BLE APIs based on the Cordio stack, but they seem to prefer showing off capabilities of advanced usage of C++ language instead of coming up with a reliable BLE API everyone could use easily
- If you carefully examine the code of all their examples and also the ble utils repo, you will discover 2-3 different BLE coding flavors to make it more confusing than it should be
- Inside the ble utils repo you will find ble_app.h in which they show a new concept in case BLE is not the main and only feature of your application (which is the case about 100% in real life), however no advancement ever since that
- With ArduinoBLE i could cover my basic needs in just 2-3 days, the same took several weeks with Mbed BLE API
- In the last 6 month i learned to implement custom BLE services with Mbed BLE, also made a UART-like service to stream data via BLE...however throughput is way behind any expectation: have a really hard time to stream 8-bit data at 512Hz (~4 kbit/s) into my phone despite 0.27 Mbit/s should be feasible even with basic MTU based on my readings.
- While things seem to work with nRF connect App while testing, odds are about 0% anyone would use that for data exchange...
- I made my mobile app with AppInventor, but for some reason my Artemis board programmed with Mbed BLE APIs has a hard time connecting to the phone. In about 50% of the cases it connects as expected, but then in 50% of cases it seems to hang up somewhere in the middle of trying to connect and when i start scanning again for BLE devices it succeeds to establish the connection in the middle of the scanning phase even before i would select any BLE device from the list of found devices. So for me it seems that Mbed BLE (or just the Artemis board??) does not communicate it's state in a reliable fashion to other devices. The root of this is beyond my capabilities. It might be my phone, Mbed BLE, some weird and hardly documented limitation of Android, or who knows what.
In general BLE might be a good idea if you are about to turn the lights on in a room, but you will have a really hard time in case of data streaming and with Mbed you will hit throughput limits way before those are expected.
I am really torn by my own findings and by what i read from other users as with bluetooth classic i can stream data with 2 Mbit/s in a reliable fashion using https://github.com/bluekitchen/btstack
. I tend to think BLE just s***s with Mbed BLE API and this seems to be specially true on Android HW.