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

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1


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.

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
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.

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

Revisions of main.cpp

Revision Date Message Actions
77:7674b63f8aea 2015-12-03 fixed a typo in main(). We would previously be spinning on initialization and never enter low-power mode. File  Diff  Annotate
75:b0385b4fdc3e 2015-11-06 oops. had forgotten to put in the spin loop during initialization(). This isn't necessary for nRF, but could be necessary for other controllers. File  Diff  Annotate
74:7754bf460f52 2015-11-06 updating to the latest of the underlying libraries. File  Diff  Annotate
72:eb4de3de66b8 2015-07-22 minor cosmetic change. File  Diff  Annotate
71:12660a3eb07d 2015-07-21 updating to the latest of the underlying libraries. File  Diff  Annotate
69:f121dba6fcd3 2015-06-20 switch to newer APIs; rename BLEDevice to BLE File  Diff  Annotate
60:3034dc913ea1 2015-03-24 updating underlying libraries. File  Diff  Annotate
59:4cd4f48e2775 2015-02-17 reduce advertising frequency to 1hz File  Diff  Annotate
58:ea344155a388 2015-02-16 remove some unnecessary comments. File  Diff  Annotate
57:9782cb35c494 2015-02-16 adding a const qualifier to a global variable. File  Diff  Annotate
56:56bc0cab3916 2015-02-14 changed example code for clarity File  Diff  Annotate
55:b9616b70d6a3 2015-02-13 simplified iBeacon based on the iBeaconService File  Diff  Annotate
54:3a655a9fce9a 2015-02-12 Changed default MajorNumber MinorNumber to decimal numbers instead of hex numbers because most smartphone applications display decimal not hex File  Diff  Annotate
53:f9ec2c7a47f5 2015-02-12 Updated BLE_API library and mbed library, added iBeaconService.h and altered main.cpp to reflect the use of iBeaconService.h accordingly File  Diff  Annotate
50:7bc38f01d2d3 2014-12-08 Added comments to iBeacon structure for clarity. File  Diff  Annotate
48:2f0f293a4966 2014-11-28 updating to 0.2.5 of the BLE_API File  Diff  Annotate
47:447eb23e67e2 2014-11-05 updating underlying libraries. File  Diff  Annotate
44:71ff94cd9c1d 2014-09-22 updating to 0.2.0 of the BLE_API File  Diff  Annotate
43:b5dc3241fc91 2014-09-02 updating underlying libraries. File  Diff  Annotate
42:bb46ad5c24dd 2014-08-12 minor cosmetic change to a comment block File  Diff  Annotate
41:51f585d14675 2014-08-12 lower advertising frequency to 1hz File  Diff  Annotate
37:205deeded79d 2014-07-04 include LE_GENERAL_DISCOVERABLE in advertising payload File  Diff  Annotate
32:7b7093b653a8 2014-06-10 reverting to BLEDevice (from BLEPeripheral) File  Diff  Annotate
31:93e50a3c3dc6 2014-06-10 simplifying the BEACON template; add use of waitForEvent() and DEBUG(...) File  Diff  Annotate
30:746d37d781de 2014-06-10 remove ticker; consumes un-necessary power File  Diff  Annotate
27:8d4f5bda1191 2014-06-10 update due to rename of BLEDevice to BLEPeripheral File  Diff  Annotate
25:a56462536345 2014-05-30 no need to call reset() separately after init() File  Diff  Annotate
24:9bcd0dbf0f41 2014-05-23 removed use of forward declarations for helper functions File  Diff  Annotate
23:b66fa312e926 2014-05-23 using simplified API to accumulate adv payload File  Diff  Annotate
22:080d9bf2f5c0 2014-05-23 adding static const to the definition to beaconPayload File  Diff  Annotate
21:a61af863b273 2014-05-23 white space diff File  Diff  Annotate
20:5e84b5b253a5 2014-05-23 using simplified GAP advertising API to setup advertising type File  Diff  Annotate
19:869d8c7306b4 2014-05-23 split startAdvertising(params) into setParams() and startAdvertising() File  Diff  Annotate
18:e49bb8b059bf 2014-05-22 minor white space diffs File  Diff  Annotate
17:e7748951593e 2014-05-22 using BLEDevice instead of nRF81822; File  Diff  Annotate
16:3a0aa30e3b12 2014-05-22 remove another reference of nRF51822 from main.cpp. File  Diff  Annotate
15:4e1b36b73213 2014-05-22 some more cosmetic changes File  Diff  Annotate
14:dfdf0c8b1c09 2014-05-22 cosmetic improvement to the comment describing the structure of the beacon payload File  Diff  Annotate
13:04c6103760d2 2014-05-22 user overloaded setAdvertisingData() to avoid having to specify a scan response File  Diff  Annotate
12:00545c957af4 2014-05-22 switching to new API for BLEDEvice. File  Diff  Annotate
11:6774f4827024 2014-05-22 rename "nrf" to "ble" File  Diff  Annotate
10:391c1acf4b9d 2014-05-22 minor re-organization of code to make the demo clearer File  Diff  Annotate
9:438f44012039 2014-05-22 renaming LEDs File  Diff  Annotate
8:d851d92601b7 2014-05-20 initialization quirks should be moved out of the app and into nRF51822 support library. File  Diff  Annotate
7:e2bfd5db6713 2014-05-20 better documentation to explain the structure of the beacon advertising payload File  Diff  Annotate
6:26eab6ee6df4 2014-05-20 some more white space diffs. File  Diff  Annotate
5:97ce285ff00a 2014-05-20 white space diffs. File  Diff  Annotate
4:0ce8d2dd62f9 2014-04-04 Renamed some variables File  Diff  Annotate
2:90b493cdcb1f 2014-04-02 Code cleanup File  Diff  Annotate
0:7613d21e5974 2014-03-31 First commit of iBeacon demo using the BLE API and native mode nRF51822 driver File  Diff  Annotate