> For the complete documentation index, see [llms.txt](https://cavedu.gitbook.io/linkit-7697/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cavedu.gitbook.io/linkit-7697/linkit-7697-arduinoide/kai-fa-zhi-nan/shi-yong-ble-di-gong-hao-lan-ya/lan-ya-xin-biao.md).

# 藍牙信標

所謂的藍牙信標，是最單純的一種低功耗藍牙周邊裝置，它僅僅只是不斷的發送具備特定內容的廣播信號。在大部分的應用例子當中，信標不會提供其他服務。 開發者可以使用 LBLE 程式庫與 LinkIt 7697 來建立 [iBeacon ](https://developer.mbed.org/blog/entry/BLE-Beacons-URIBeacon-AltBeacons-iBeacon/#iBeacon)或是 [Eddyston-URL ](https://github.com/google/eddystone/tree/master/eddystone-url)信標。

* 將 LinkIt 7697 設定為 iBeacon 信標
* 將 LinkIt 7697 作為 Eddystone-URL 信標

## 將 LinkIt 7697 設定為 iBeacon 信標 <a href="#beacons-jiang-linkit7697-she-ding-wei-ibeacon-xin-biao" id="beacons-jiang-linkit7697-she-ding-wei-ibeacon-xin-biao"></a>

iBeacon 就是一個以特定格式發送資料的低功耗藍牙裝置。它不能夠被主控裝置連線。

可透過 `LBLEAdvertisement` 輕易的生成並設定 iBeacon 廣播的內容，只需要呼叫 `configAsIBeacon` 這個函示來設定 iBeacon 的資訊，如下例所示：

```
LBLEAdvertisementData beaconData;
beaconData.configAsIBeacon("E2C56DB5-DFFB-48D2-B060-D0F5A71096E0", 01, 02, -40);
```

`在上面的例子當中：`

* **`E2C56DB5-DFFB-48D2-B060-D0F5A71096E0`** 是 iBeacon 的 UUID。這個 UUID 是應用程式要[自己去生成的](https://www.google.com.tw/search?q=Online+UUID+Generator\&oq=Online+UUID+Generator)。在這個例子當中，我們使用了 `E2C56DB5-DFFB-48D2-B060-D0F5A71096E0`，這是一個在 iOS  開發套件當中的 [AirLocate iBeacon ](https://developer.apple.com/library/content/samplecode/AirLocate/Introduction/Intro.html)範例。有許多 iOS 的信標偵測工具，都會提供掃描這個 UUID 對應的信標的範例。
* 參數 **01** 跟 **02** 分別是所謂的 **major ID** 與 **minor ID**。這兩個 ID 的用途是讓開發者區分同一個信標應用當中的不同實體信標。比如說，使用者可能會想要在辦公室的每一間會議室當中，都放一個 LinkIt 7697 作為 iBeacon 信標，並且把 major ID 設定為樓層號碼，把 minor ID 設定為會議室編號。這樣一來，就可以透過偵測 major 與 minor ID，得知自己所在的會議室。
* 最後一個數值 `-40，是代表「在距離此信標一公尺遠的範圍，測量此信標的信號強度所預期得到的dB值」，主要的目的是讓 iBeacon 掃描器的應用可以提供大概的距離估算。要注意的是，這個值只是單純的被保存在信標的廣播數據之中，它不會真的影響廣播信號的強度。開發者應該在實際環境與對應的 iBeacon 掃描器中，測量並且校正此數值應該有的大小。`

\
在設定好信標廣播的內容之後，只需要呼叫 `advertise` 這個方法，就可以讓 LBLEPeripheral 類別開始廣播信標，如下：&#x20;

```
LBLEPeripheral.advertise(beaconData);
```

此時 LinkIt 7697 便會開始信標的廣播。如果要停止廣播，請呼叫 `stopAdvertise()` 。

在 IDE 選單中的 `File > Examples > LBLE > BeaconAdvertisement 已經提供了一個簡單的範例。當上傳此範例檔案後，即可以使用` [Locate Beacon](https://itunes.apple.com/tw/app/locate-beacon/id738709014?mt=8) 這類的手機 iBeacon 掃描工具來掃描範例所提供的信標。下面是該手機工具的螢幕截圖：

&#x20;

![](/files/a2Gb4weCQLnMfGxOCEEQ)

## 將 LinkIt 7697 作為 Eddystone-URL 信標 <a href="#beacons-jiang-linkit7697-zuo-wei-eddystoneurl-xin-biao" id="beacons-jiang-linkit7697-zuo-wei-eddystoneurl-xin-biao"></a>

[**Eddystone-URL**](http://https//github.com/google/eddystone/tree/master/eddystone-url) 信標主要的功能便是廣播一個特定的網址（**URL**）. 因為 BLE 廣播資料有限制相當短的長度，所以一般來說，會使用縮短後的網址，比如像是 [**https://goo.gl/Aq18zF**](https://goo.gl/Aq18zF) 這種形式。

要創建一個這樣的信標，只需要呼叫 **LBLEAdvertisementData** 物件的 **configAsEddystoneURL**方法：

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

#### URL 類型設定 <a href="#beaconsurl-lei-xing-she-ding" id="beaconsurl-lei-xing-she-ding"></a>

在上面的範例當中，會看到 Eddystone-URL 已經有內定一些常見的 URL 開頭，以求更進一步縮短所需要的資料空間。URL 資料的長度限制為 **17 bytes**，而在上面的範例中，我們可以用一個 1 byte 的 **EDDY\_HTTPS** 代號來代表 **https\://** 這個需要 8 byte才能夠表示的網址開頭。同樣的， **EDDY\_DOT\_COM** 用來代表 **.com** 這個 URL 的結尾。下面的表格列出了可供選用的 URL 開頭與結尾。

| Prefix Symbol    | Corresponding URL           |
| ---------------- | --------------------------- |
| EDDY\_HTTP\_WWW  | [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              |

如果要使用的網址沒有在上面列出的表格之中，而且總長又超過了17 byte，那麼可考慮使用 [**URL shortener**](https://en.wikipedia.org/wiki/URL_shortening) 服務，這樣一來，可以輕易的把長網址轉換為短網址：

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

#### 廣播信標內容 <a href="#beacons-guang-bo-xin-biao-nei-rong" id="beacons-guang-bo-xin-biao-nei-rong"></a>

設定好要廣播的 URL 之後，只要把該資訊傳入 **advertiseAsBeacon** 方法中，就可以開始廣播：

```
LBLEPeripheral.advertiseAsBeacon(beaconData); 
```

#### 搜尋周圍的 Eddyston-URL 信標 <a href="#beacons-sou-xun-zhou-wei-de-eddystonurl-xin-biao" id="beacons-sou-xun-zhou-wei-de-eddystonurl-xin-biao"></a>

開發者可以使用  [**Physical Web**](https://itunes.apple.com/app/physical-web/id927653608?mt=8) 手機程式或是其他支援 Google Beacons 框架的工具來搜尋鄰近的 Eddystone-URL 信標。

* [Android 版本下載連結](https://play.google.com/store/apps/details?id=physical_web.org.physicalweb)
* [iOS 版本下載連結](https://itunes.apple.com/app/physical-web/id927653608?mt=8)

作為示範演練，請先燒錄 **File > Examples > LBLE > EddystoneURLAdvertisement** 這個範例到 LinkIt 7697。接著在手機上打開 Physical Web 程式，它應該會顯示如下的信標資訊：

![](/files/XBvK7KE5sZqVjeyTmTGq)

Physical Web 這個程式也支援小工具模式，如果在手機的小工具頁面當中放置此程式，就可以隨時搜尋鄰近的 Eddystone-URL 信標，並開啟對應的網址。

![](/files/sIHHI8bgNG7MrJ7YqBtk)

{% hint style="danger" %}
Note

請確認手機上面的 BLE 功能有開啟。
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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-arduinoide/kai-fa-zhi-nan/shi-yong-ble-di-gong-hao-lan-ya/lan-ya-xin-biao.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.
