# 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** ](https://developer.mbed.org/blog/entry/BLE-Beacons-URIBeacon-AltBeacons-iBeacon/#iBeacon)or [**Eddystone-URL**](https://github.com/google/eddystone/tree/master/eddystone-url) beacons with LinkIt 7697:

* [Using LinkIt 7697 as an iBeacon](https://docs.labs.mediatek.com/resource/linkit7697-arduino/en/developer-guide/using-bluetooth/beacons#Beacons-UsingLinkIt7697asaniBeacon)
* [Using LinkIt 7697 as an Eddystone-URL Beacon](https://docs.labs.mediatek.com/resource/linkit7697-arduino/en/developer-guide/using-bluetooth/beacons#Beacons-UsingLinkIt7697asanEddystone-URLBeacon)

## Using LinkIt 7697 as an iBeacon <a href="#beacons-usinglinkit7697asanibeacon" id="beacons-usinglinkit7697asanibeacon"></a>

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](https://developer.apple.com/library/content/samplecode/AirLocate/Introduction/Intro.html). 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](https://itunes.apple.com/tw/app/locate-beacon/id738709014?mt=8) to search for this beacon. A screenshot of the result of the scan in the app is shown below:

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FteZLvX5L0rn47eB5ie3I%2Flocate_beacon.png?alt=media\&token=788eb986-f84b-4e16-869c-bf99b1dfe26e)

## Using LinkIt 7697 as an Eddystone-URL Beacon <a href="#beacons-usinglinkit7697asaneddystone-urlbeacon" id="beacons-usinglinkit7697asaneddystone-urlbeacon"></a>

An [**Eddystone-URL**](http://https/github.com/google/eddystone/tree/master/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**](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 <a href="#beacons-urlconfiguration" id="beacons-urlconfiguration"></a>

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 | [https://www](http://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**](https://en.wikipedia.org/wiki/URL_shortening) 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 <a href="#beacons-beaconadvertisement" id="beacons-beaconadvertisement"></a>

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 <a href="#beacons-discovereddyston-urlbeacons" id="beacons-discovereddyston-urlbeacons"></a>

You can use [**Physical Web**](https://itunes.apple.com/app/physical-web/id927653608?mt=8) APP or other tools that supports Google Beacons framework to discover an Eddystone-URL beacon.

* [Android download link](https://play.google.com/store/apps/details?id=physical_web.org.physicalweb)&#x20;
* [iOS download link](https://itunes.apple.com/app/physical-web/id927653608?mt=8)

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:

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FscC062Cf5ZCGDtvaPVEY%2Fpw.png?alt=media\&token=3f7e9d94-5d47-440c-8ac3-c574e78d3fea)

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.

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2FiD9HYmTwYFPFekwRBzS7%2Fpw_w.png?alt=media\&token=fe5eb463-7546-4a56-876e-2ca825639cdd)

{% hint style="danger" %}
Note

Make sure you've turned on the BLE function on your phone.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cavedu.gitbook.io/linkit-7697/linkit-7697-development-guide-for-arduino-ide/developer-guide/using-bluetooth/beacons.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
