Thursday, 5 May 2016

Bluetooth advertising and micro:bit

The BBC micro:bit has a special "pairing mode" which it needs to be in for you to be able to pair it with another device such as your smartphone. When not in pairing mode it's in... well let's call it "normal mode". I published a video showing how to pair with your micro:bit some time ago.

When a micro:bit is not in a Bluetooth connection with another device it will be broadcasting small packets of data over Bluetooth called "advertising packets" (provided it has been paired with at least one device at some point - if you've not yet paired your micro:bit with anything it will not be advertising when in "normal mode").

Advertising is the Bluetooth mechanism which allows other devices like a smartphone to discover your micro:bit.

There are important differences between the advertising (ADV) packets which are broadcast when in pairing mode vs those which are broadcast when in normal mode however and this may have an impact on how the Bluetooth settings screen of your smartphone or tablet behaves.

Here's an ADV packet from when my micro:bit was in pairing mode:


The LE General Discoverable Mode flag is set and this means other devices can regard the micro:bit as willing to be discovered. This is not a security mechanism by the way, it's an expression of intent of sorts.

When a previously paired micro:bit is in normal mode however, the ADV flags look like this:


Neither of the discoverable mode flags are set and the micro:bit is said to be "non-discoverable". It's there of course and it's advertising. Other devices can see those advertising packets as plain as day but they're being politely asked to pretend they can't see it. In practice what this means is that if you've not paired your micro:bit with your smartphone it may not be listed in the smartphone's Bluetooth settings screen under "Available devices". Here's a screen shot from my Nexus 9 tablet which I have *not* paired with my micro:bit which is currently on and advertising:


My micro:bit is not listed despite the fact that it is in range and is advertising because this device has not paired with it and the advertising packets are indicating that the micro:bit does not want to be discovered by random devices it has never been introduced formally to.

On the other hand. my Nexus 5 smartphone has been paired with the micro:bit and so it is listed in the Bluetooth settings screen.


The moral to this story? If you can't see your micro:bit listed on your phone's Bluetooth settings screen and you think it should be, check the description of micro:bit's expected advertising behaviour that I've given here. Hopefully all you need to do is pair your micro:bit.

No comments :

Post a Comment