Beacons

Beacons

An Bluetooth beacon is a Bluetooth Low Energy device that only advertises itself with a specific format of advertising data. In most cases it cannot be connected. The LBLE library allows developers to create iBeacon or Eddystone-URL beacons with LinkIt 7697:

Using LinkIt 7697 as an iBeacon

An iBeacon is a Bluetooth Low Energy device that only advertises itself with a specific format of advertising data. It cannot be connected.

You can use the class LBLEAdvertisement for easy generation of iBeacon advertisement data. Call the method configAsIBeacon to set the advertisement data to iBeacon format, for example the following code snippet:

LBLEAdvertisementData beaconData;
beaconData.configAsIBeacon("E2C56DB5-DFFB-48D2-B060-D0F5A71096E0", 01, 02, -40);
  • E2C56DB5-DFFB-48D2-B060-D0F5A71096E0 is the UUID for your iBeacon. Usually, this is a vendor-specific UUID that you should generate by yourself. The value, E2C56DB5-DFFB-48D2-B060-D0F5A71096E0, is widely used because this is the UUID used in the example project of the iOS AirLocate iBeacon example. Many iOS tool provides built-in settings that searches this UUID.

  • The number 01 and 02 are major and minor IDs that can be used to distinguish between different iBeacon devices. For example, you may want to deploy several LinkIt 7697 devices in each meeting room in your office. You can then set major number as the floor number, and set minor number as the room number. Then your iBeacon scanner can detect and know which meeting room the user is currently in by checking the major and minor numbers.

  • The last TX Power number, -40, is an indicator of what the expected signal level should be when you are one meter away from the beacon. The beacon scanner can compare this value with the actual signal strength to have a rough estimation on the distance. The actual value depends on various conditions such as antenna setup and housing of your device, so it's recommend to calibrate this value with the scanner together.

After setting up the advertisement data, call advertise method of the LBLEPeripheral to start broadcasting the advertisement data, for example:

LBLEPeripheral.advertise(beaconData);

LinkIt 7697 will now start broadcasting the advertisement data. Call stopAdvertise() to stop broadcasting.

An example can be found in the IDE menu File > Examples > LBLE > BeaconAdvertisement. After upload this sketch, you can use iBeacon tools such as Locate Beacon to search for this beacon. A screenshot of the result of the scan in the app is shown below:

Using LinkIt 7697 as an Eddystone-URL Beacon

An Eddystone-URL beacon broadcast information of a specific URL. The length of the URL is limited due to the size limitation of BLE advertisement data, so usually a shortened URL such as https://goo.gl/Aq18zF is used.

To create an Eddystone-URL beacon, simply create an LBLEAdvertisementData object and call its configAsEddystoneURL method:

LBLEAdvertisementData beaconData;
beaconData.configAsEddystoneURL(EDDY_HTTPS, "labs.mediatek", EDDY_DOT_COM);

URL Configuration

As you can see, the Eddystone-URL format provides several pre-defined symbols to compress the URL. The total length of the URL data is limited to 17 bytes. In the example above, a single-byte EDDY_HTTPS symbol denotes a https:// URL prefix that would require 8-bytes to represent. Similarly, the EDDY_DOT_COM symbol denotes the suffix .com. The table below shows you the prefix and suffex symbols that you can choose from:

Prefix Symbol
Corresponding URL

EDDY_HTTP_WWW

http://www.

EDDY_HTTPS_WWW

EDDY_HTTP

http://

EDDY_HTTPS

https://

Suffix Symbol
Corresponding URL

EDDY_URL_NONE

(append nothing)

EDDY_DOT_COM_SLASH

.com/

EDDY_DOT_ORG_SLASH

.org/

EDDY_DOT_EDU_SLASH

.edu/

EDDY_DOT_NET_SLASH

.net/

EDDY_DOT_INFO_SLASH

.info/

EDDY_DOT_BIZ_SLASH

.biz/

EDDY_DOT_GOV_SLASH

.gov/

EDDY_DOT_COM

.com

EDDY_DOT_ORG

.org

EDDY_DOT_EDU

.edu

EDDY_DOT_NET

.net

EDDY_DOT_INFO

.info

EDDY_DOT_BIZ

.biz

EDDY_DOT_GOV

.gov

If you cannot find a matching suffix, or that the total URL length still exceeds 17 bytes, you need to consider a URL shortener service. To describe a shortened URL, simply discard the suffix symbol as shown below:

beaconData.configAsEddystoneURL(EDDY_HTTPS, "goo.gl/Aq18zF");	// This results in "https://goo.gl/Aq18zF"

Beacon Advertisement

After configuring the URL, simply pass the beacon data to the advertiseAsBeacon method of LBLEPeripheral to start broadcasting advertisements.

LBLEPeripheral.advertiseAsBeacon(beaconData); 

Discover Eddyston-URL Beacons

You can use Physical Web APP or other tools that supports Google Beacons framework to discover an Eddystone-URL beacon.

As an example, please download the example from File > Examples > LBLE > EddystoneURLAdvertisement to LinkIt 7697. Open the the Physical Web app and it should be able to detect the beacon as shown below:

This app can also work under the widget mode. If you put it into the widget space (e.g. the Today view in iOS), you'll see all the Eddystone URLs discovered around you when you check the widget space.

Note

Make sure you've turned on the BLE function on your phone.

Last updated