3

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.

asked Aug 20, 2020 at 7:55

1 Answer 1

3

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

answered Aug 20, 2020 at 8:59
2
  • 1
    Excellent, just what I was looking for. I will indeed be treating the Pi as a BLE peripheral. Commented Aug 20, 2020 at 9:44
  • 1
    Awkwardly bumped into my own question 4 years later Commented Dec 10, 2024 at 18:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.