Sunday, 12 March 2017

Is Bluetooth useful?

I have "acquired" (translation: I have borrowed from Code Club) a couple of BBC micro:bits. These have a Bluetooth stack on them, which can be used to connect to other devices. The uBits are pretty capable microcontrollers, with lots of low power features, and if they were connected to sensors etc. they could easily transmit information to more powerful devices, like... a Raspberry Pi! Quite what I'll do with this yet I don't know, but in the best open-ended fashion, let's see if I can get anything working before we worry about an interesting application. Code Club Kids might like this...

First thing is to identify a suitable RPi. I'll be using the server, all the others are configured with the Rune image.

Next, check on the installation of BlueZ, the Linux Bluetooth stack. Need to update the distro and firmware - apt-get update, apt-get upgrade, apt-get dist-upgrade. Hurrah!

Testing... Running bluetoothctl, but it can't see any Bluetooth controllers. More research - try installing pi-bluetooth, already installed. BlueZ also already installed, but bluem not... apt running hard on this one! Still no controllers visible. Reboot....

Bingo. Controller available!


pi@server:~ $ sudo bluetoothctl

[NEW] Controller B8:27:EB:BF:C4:1D server [default]
[NEW] Device 48:74:6E:CD:96:2A John's iPhone

As can be seen, my phone is visible. Hurrah. Can't connect though. However, I'm interested as much in connecting the uBit, let's find out about that.

Super useful blog here - Martin W is a Bluetooth aficionado and has lots of info and help on Bt generally and RPi/uBit specifically.

Bluetooth Roles: (credited to Martin Woolley, at the above blog)

Bluetooth devices will play one of 4 possible Bluetooth roles as defined by that masterpiece, the Bluetooth core specification. The four roles are called
  1. Peripheral
  2. Central
  3. Broadcaster
  4. Observer
These terms are part of "GAP", the Generic Access Profile, which is a part of the Bluetooth architecture.

Peripheral (
like a uBit, smartphones with specific software) advertises, inviting and (perhaps) accepting connections from Central devices. 'Advertising' means transmitting small amounts of data, quite frequently, which other Bluetooth devices can receive and act upon if they think the advertising device is of interest.

Central (smartphones) device scans, looking for advertising packets and based on their content, may decide to connect to a device it thinks is suitable.

Broadcaster (Bluetooth beacon) is like a peripheral in that it advertises but it does not accept connections. It's sole purpose is to advertise.


An Observer (e.g. a beacon app on a smartphone, alerting one to special offers etc.) scans and processes advertising packets but never tries to connect to another device.