Beacon demo for the BLE API using the nRF51822 native mode drivers

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

Introduction

Bluetooth Low Energy Beacons are a service that allow for highly localized positioning. The Beacon service is particularly useful for indoor positioning, low power positioning and location aware software. A particular use of the Beacon service is iBeacon. The iBeacon standard is a Apple specific implementation of Beacons.

The Basics

The Beacon service is a BLE Service that operates in advertising mode only. A Beacon service advertises 4 things:

  • A company ID
  • A unique UUID (unique to a retailer)
  • A Major number (ex a store number)
  • A Minor number (ex a location in the store)
  • Signal Strength at transmitter (requires calibration per each device)

These pieces of information are all you need for a Beacon service to work. The majority of the heavy lifting is done by the smart phone application that reads these four fields and then uses a web app or a database of some sort to turn these numbers into valuable information about what you are near and how near you are to it.

The signal strength field is compared to the actual signal strength at the receiver to determine how close the beacon is to the phone. The number used is the calibrated signal strength 1 meter from the device. By doing this 1 meter increments can be used to measure distance from the Beacon. The distances usually get broken down into 3 ranges:

  • Immediate: Within a few centimeters
  • Near: Within a couple of meters
  • Far: Greater than 10 meters away

Company ID's are used to make beacon UUID's unique to companies. Some example company UUID's are:

  • 0x004C - Apple Inc.
  • 0x0059 - Nordic Semiconductor
  • 0x0078 - Nike
  • ​0x015D - Estimote
  • ​0x0171 - Amazon Fulfillment Service
  • 0xFFFF - reserved for internal testing before release

Here is the Bluetooth SIG's full list of Company ID's.

Example : Coffee Shop X

For example, if a smartphone app reads a BLE Beacon with UUID = 0x1234546... , Major Number=5, Minor number = 3, it would check that against a database. From that database it would find out that UUID 0x123456... is owned by Coffee Shop X, that Major number 5 belongs to the store on main street and that Minor number 3 belongs to the coffee rack in that store. Then the application could check to see if there are any deals for the Coffee Shop X on Main Street on Coffee today. If there are any deals the phone could then alert the user and display a coupon code.

Example : museum

The Beacon service also provides a way for the phone to tell how close it is to the beacon. This can be useful for location aware applications, such as in a museum. For example, the smartphone reads a BLE Beacon with UUID = 0x98765....., Major Number=1, minor number = 0. The smartphone then looks this up in a database and find the UUID is for the Natural Science Museum, Major Number 1 = the Art Gallery room 1, and the minor number 0 = an abstract painting of a duck. If we assume all the paintings are spread out at 10feet each, then the application can sense when you are within 3 feet of the painting (based on signal strength of the Beacon) and give the user information about the painting they are approaching.

Technical Details

An iBeacon is just a normal Bluetooth LE device broadcasting advertisements with special data shoved into the Manufacturer Specific Data field.

The iBeacon prefix is little more than metadata about the advertisement packet.

BytesDatadescription
0,1,20x020106This sets the flags for General Discoverable and BR/EDR not supported
3,40x1AFFThis says the length of the Manufacturer specific data field will be 26 bytes
0,10x4C00Company ID
20x02ID
30x15length of remaining data in bytes (16B UUID+ 2B major, 2B minor, 1B Txpower)

Note that bytes 0-4 are set implicitly by the API by declaring the advertising data to be LE General Discoverable and BR/EDR not supported. The remaining fields that make up an iBeacon advertisement packet can be clearly seen in the image below.

http://www.havlena.net/wp-content/uploads/ibeacon-packet.png

For a more depth explanation please see these well done explanations:

Changes

RevisionDateWhoCommit message
79:4e16bde5c10a 2016-09-20 Vincent Coubard Update libraries. default tip
78:88531e13c8e7 2016-04-11 vcoubard Update libraries to the latest revision.
77:7674b63f8aea 2015-12-03 rgrover1 fixed a typo in main(). We would previously be spinning on initialization and never enter low-power mode.
76:776e4ef44177 2015-11-26 rgrover1 updating underlying libraries.
75:b0385b4fdc3e 2015-11-06 rgrover1 oops. had forgotten to put in the spin loop during initialization(). This isn't necessary for nRF, but could be necessary for other controllers.
74:7754bf460f52 2015-11-06 rgrover1 updating to the latest of the underlying libraries.
73:abad114618b5 2015-09-29 rgrover1 updating the underlying libraries.
72:eb4de3de66b8 2015-07-22 rgrover1 minor cosmetic change.
71:12660a3eb07d 2015-07-21 rgrover1 updating to the latest of the underlying libraries.
70:5f9c3ea19f5b 2015-07-02 rgrover1 updating to the latest of the underlying libraries.;
69:f121dba6fcd3 2015-06-20 rgrover1 switch to newer APIs; rename BLEDevice to BLE
68:10ab1574c6dd 2015-06-19 rgrover1 updating to the latest of the underlying libraries.
67:643fca5e7ea5 2015-06-08 rgrover1 updating to the latest of the underlying libraries.
66:ce3926095f2f 2015-05-18 rgrover1 switch to the latest of the underlying libraries.
65:359308d229cc 2015-05-13 rgrover1 updating to Nordic's S130 and to the latest of BLE_API and nRF51
64:7a9ec1127dfd 2015-05-11 rgrover1 Updating to the latest of the underlying libraries.
63:e100e3e587f1 2015-04-30 rgrover1 updating to v8 of the Nordic SDK.
62:3774cc553029 2015-04-20 rgrover1 updating underlying libraries.
61:23fea56a32ef 2015-03-27 rgrover1 update underlying libraries.
60:3034dc913ea1 2015-03-24 rgrover1 updating underlying libraries.
59:4cd4f48e2775 2015-02-17 rgrover1 reduce advertising frequency to 1hz
58:ea344155a388 2015-02-16 rgrover1 remove some unnecessary comments.
57:9782cb35c494 2015-02-16 rgrover1 adding a const qualifier to a global variable.
56:56bc0cab3916 2015-02-14 mbedAustin changed example code for clarity
55:b9616b70d6a3 2015-02-13 rgrover1 simplified iBeacon based on the iBeaconService
54:3a655a9fce9a 2015-02-12 mbedAustin Changed default MajorNumber MinorNumber to decimal numbers instead of hex numbers because most smartphone applications display decimal not hex
53:f9ec2c7a47f5 2015-02-12 mbedAustin Updated BLE_API library and mbed library, added iBeaconService.h and altered main.cpp to reflect the use of iBeaconService.h accordingly
52:9e6dff2c4c70 2015-01-21 rgrover1 update to the latest of the underlying libraries.
51:4d655ed0ef9b 2014-12-09 rgrover1 updating underlying libraries.
50:7bc38f01d2d3 2014-12-08 mbedAustin Added comments to iBeacon structure for clarity.
49:2d05e684f9c3 2014-12-08 mbedAustin Changed the name of the example;
48:2f0f293a4966 2014-11-28 rgrover1 updating to 0.2.5 of the BLE_API
47:447eb23e67e2 2014-11-05 rgrover1 updating underlying libraries.
46:3adb4c6927ab 2014-09-30 rgrover1 updating underlying libraries;
45:2b9e4c7c2f84 2014-09-23 rgrover1 updating to the latest of the underlying libraries.
44:71ff94cd9c1d 2014-09-22 rgrover1 updating to 0.2.0 of the BLE_API
43:b5dc3241fc91 2014-09-02 rgrover1 updating underlying libraries.
42:bb46ad5c24dd 2014-08-12 rgrover1 minor cosmetic change to a comment block
41:51f585d14675 2014-08-12 rgrover1 lower advertising frequency to 1hz
40:52e9de9e0186 2014-07-25 rgrover1 updating underlying libraries.
39:1dfed56efe26 2014-07-04 rgrover1 updating underlying libraries.
38:33ee358dc876 2014-07-04 Rohit Grover resolve merge
37:205deeded79d 2014-07-04 Rohit Grover include LE_GENERAL_DISCOVERABLE in advertising payload
36:282289e1c629 2014-06-13 rgrover1 updating underlying libraries.
35:c370b193f4f4 2014-06-11 rgrover1 updating underlying libraries.
34:1fc5103e2346 2014-06-10 rgrover1 updating to the latest of the underlying libraries.
33:005c45ac0e93 2014-06-10 rgrover1 updating to the latest version of the depending libraries.
32:7b7093b653a8 2014-06-10 Rohit Grover reverting to BLEDevice (from BLEPeripheral)
31:93e50a3c3dc6 2014-06-10 Rohit Grover simplifying the BEACON template; add use of waitForEvent() and DEBUG(...)
30:746d37d781de 2014-06-10 Rohit Grover remove ticker; consumes un-necessary power
29:bf3c27639f58 2014-06-10 rgrover1 updating versions of depending libraries.
28:a96e2fd7153e 2014-06-10 Rohit Grover merge
27:8d4f5bda1191 2014-06-10 Rohit Grover update due to rename of BLEDevice to BLEPeripheral
26:95e71514c560 2014-06-05 rgrover1 updating to the latest version of the dependent libraries
25:a56462536345 2014-05-30 Rohit Grover no need to call reset() separately after init()
24:9bcd0dbf0f41 2014-05-23 Rohit Grover removed use of forward declarations for helper functions
23:b66fa312e926 2014-05-23 Rohit Grover using simplified API to accumulate adv payload
22:080d9bf2f5c0 2014-05-23 Rohit Grover adding static const to the definition to beaconPayload
21:a61af863b273 2014-05-23 Rohit Grover white space diff
20:5e84b5b253a5 2014-05-23 Rohit Grover using simplified GAP advertising API to setup advertising type