Tuesday, 1 November 2016

micro:bit proximity beacons

One the big growth areas for Bluetooth is in "beacons". Bluetooth beacons broadcast data which can be used by another device to deduce roughly where it is. This can be in terms of a particular location or perhaps in terms of proximity to an object of interest.

ABI predict that by 2020, there will be 400 million Bluetooth beacons shipping each year.

Beacons work by using Bluetooth "advertising" to broadcast a small amount of data, which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application.

There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data. iBeacon is Apple's beacon message format. Eddystone comes from Google.

Google have a very interesting project called the Physical Web and it in large part, is all about how Bluetooth beacon technology, coupled with software on smartphones and tablets, coupled with the web, can enable people to more easily discover and interact with physical things in the environment.

Believe me. This is going to be BIG.

I just helped add Eddystone beacon capabilities to the BBC micro:bit. Kudos to Thomas Beverly for having kicked things off by implementing support for Eddystone URL messages in the micro:bit's "runtime". I tagged along for the ride and added support for UID messages over the weekend and it's now pretty easy to use a micro:bit for a wide range of beacon scenarios.

I have a couple of videos on my Bitty Software web site. The first shows the UID Eddystone message type in use and the second uses the URL message type. Take a look at them now to get the idea, especially if you're not already familiar with beacons.

Don't forget, you don't need to make a Bluetooth connection to a beacon to use it... you just have to be near enough to it to receive its broadcast data and as I've noted elsewhere in this blog, micro:bits can have a range of hundreds of metres when using Bluetooth at full power. 

So you could place micro:bit beacons all over (say) your school, and with a suitable application on phones and tablets, provide information pertinent to each location or some other response, automatically on someone simply coming into range of the micro:bit's beacon broadcasts.

Right now, turning your micro:bit into a beacon requires you to do some C/C++ programming. I'm hoping though that Microsoft's awesome PXT tool will end up with a "Bluetooth Beacon Block" in the future so that making micro:bit beacons is as easy as can be.

The microbit-samples repo will soon have Eddystone beacon code examples in it and I've also submitted updates to the Lancaster University micro:bit documentation on the subject.

Meanwhile, to whet your appetite, here's some code:

#include "MicroBit.h"

MicroBit uBit;

char URL[] = "https://goo.gl/TlUTF7";
const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10};

uint8_t advertising = 0;
uint8_t tx_power_level = 6;

void startAdvertising() {
    uBit.bleManager.advertiseEddystoneUrl(URL, CALIBRATED_POWERS[tx_power_level-1], false);
    uBit.bleManager.setTransmitPower(tx_power_level);
    uBit.display.scroll("ADV");
    advertising = 1;
}


8 comments :

  1. http://microbit-drill.org/#eddystone We are hoping for an easy implementation using PXT and allowing the children to embed beacons in their projects: go near a micro:bit project and get direct to "how I did it".
    Also, we want to go for a treasure hunt :)

    ReplyDelete
  2. Me too! I logged the request for this feature with Microsoft a while back. Looks like they're making progress :-)

    ReplyDelete
  3. https://github.com/Microsoft/pxt-microbit-eddystone
    Peli wrote on https://microbit-community.slack.com/messages/pxt/details/
    "correction: it is not part of rc5, will need to wait for a new tag from Lancaster" in regard to implementing the feature

    ReplyDelete
  4. ? a micro:bit can send a beacon, but can it receive a beacon ...

    Two micro:bits meet and swap beacons gives some play possibilities.

    ReplyDelete
  5. You mean beacon data? The micro:bit *is* the beacon by virtue of the data in its advertising packets.

    No, today's micro:bit can only advertise. It cannot scan. This is a consequence of it's limited memory so that it does not have the part of the Bluetooth stack required for it to be able to scan (and request connections).

    See http://bluetooth-mdw.blogspot.co.uk/2016/07/microbit-and-bluetooth-roles.html

    ReplyDelete
  6. Pity it cannot scan: such is life.
    In another micro:bit version of hardware there will hopefully come more memory :)

    ReplyDelete
  7. I know! I'm hoping for a 32k version at some point. Then the Nordic S130 stack, which can accommodate all Bluetooth GAP roles should be possible. For now, you could use a smartphone or Raspberry Pi as a hub and have it act as an intermediary between micro:bit beacons.....

    ReplyDelete