I'm trying to find some example code for using the pi as a bluetooth device so that other devices can search for it and pair with it. Specifically I want to make it behave like a bicycle power meter for the project I have in mind.
I can't seem to find the correct keywords to search for in Google, but from looking around this site it does seem like it's possible (I saw that someone used it as a bluetooth printer..)
Just some direction needed really - maybe a library or even what to search for.
1 Answer 1
My assumption is that you are looking at being one of the standard cycling profiles/services as defined by the Bluetooth SIG.
These are Bluetooth Low Energy (BLE) and use the GATT specification.
On Linux, the Bluetooth stack is BlueZ which uses D-Bus to expose its API. For example the GATT API is documented at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/gatt-api.txt
Your device will be taking the Peripheral role which means creating a GATT server. There is an example of this in the BlueZ source code: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/example-gatt-server
The peripheral will also need to advertise the GATT service: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/example-advertisement
By default the RPi is both BR/EDR (classic) and LE Bluetooth. When acting as a BLE peripheral it is good to configure the controller to Bluetooth Low Energy only.It has been discovered that to get reliable connection to Android phones this is required. This configuration change is done in the /etc/bluetooth/main.conf
file. Ensure that it contains the following:
ControllerMode = le
-
1Excellent, just what I was looking for. I will indeed be treating the Pi as a BLE peripheral.John Hunt– John Hunt2020年08月20日 09:44:50 +00:00Commented Aug 20, 2020 at 9:44
-
1Awkwardly bumped into my own question 4 years laterJohn Hunt– John Hunt2024年12月10日 18:43:27 +00:00Commented Dec 10, 2024 at 18:43