2

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.

2

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

1
  • 1
    Excellent, just what I was looking for. I will indeed be treating the Pi as a BLE peripheral.
    – John Hunt
    Aug 20 '20 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.