藍牙低功耗Bluetooth Low Energy

藍牙低功耗 (LE) 是一種規格,定義通訊協定來進行探索以及在省電裝置之間進行通訊。Bluetooth Low Energy (LE) is a specification that defines protocols for discovery and communication between power-efficient devices. 透過泛型存取設定檔 (間隔) 通訊協定完成裝置探索。Discovery of devices is done through the Generic Access Profile (GAP) protocol. 在探索之後,透過泛型屬性 (GATT) 通訊協定完成裝置間的通訊。After discovery, device-to-device communication is done through the Generic Attribute (GATT) protocol. 本主題提供 UWP app 中藍牙 LE 的快速概觀。This topic provides a quick overview of Bluetooth LE in UWP apps. 若要查看藍牙 LE 的詳細資料,請參閱引進藍牙 LE 的藍牙核心規格版本 4.0。To see more detail about Bluetooth LE, see the Bluetooth Core Specification version 4.0, where Bluetooth LE was introduced.

藍牙 LE 角色

Windows 10 版本 1703 引進 GATT 和 GAP 角色GATT and GAP roles were introduced in Windows 10 version 1703

使用下列命名空間,即可在 UWP app 中實作 GATT 和 GAP 通訊協定。GATT and GAP protocols can be implemented in your UWP app by using the following namespaces.

中央和周邊Central and Peripheral

探索的兩個主要角色稱為「中央」和「周邊」。The two primary roles of discovery are called Central and Peripheral. 一般而言,Windows 會以中央模式運作,並連線至不同的周邊裝置。In general, Windows operates in Central mode and connects to various Peripheral devices.

屬性Attributes

您在 Windows 藍牙 API 中看到的常見縮寫是泛型屬性 (GATT)。A common acronym you will see in the Windows Bluetooth APIs is Generic Attribute (GATT). GATT 設定檔定義資料結構以及兩個藍牙 LE 裝置的通訊作業模式。The GATT Profile defines the structure of data and modes of operation by which two Bluetooth LE devices communicate. 屬性是 GATT 的主要建置組塊。The attribute is the main building block of GATT. 主要類型的屬性是服務、特性和描述元。The main types of attributes are services, characteristics and descriptors. 這些屬性在用戶端與伺服器之間的執行方式不同,因此,更適合在相關小節中討論其互動。These attributes perform differently between clients and servers, so it is more useful to discuss their interaction in the relevant sections.

一般設定檔中的一般屬性階層

以 GATT Server API 形式表示心率服務The heart rate service is expressed in GATT Server API form

用戶端與伺服器Client and Server

建立連線之後,包含資料的裝置 (通常是小型 IoT 感應器或穿戴式裝置) 稱為「伺服器」。After a connection has been established, the device that contains the data (usually a small IoT sensor or wearable) is known as the Server. 使用該資料來執行功能的裝置稱為「用戶端」。The device that uses that data to perform a function is known as the Client. 例如,Windows 電腦 (用戶端) 會讀取心率監視器 (伺服器) 中的資料,來追蹤使用者是否以最佳狀態進行鍛鍊。For example, a Windows PC (Client) reads data from a heart rate monitor (Server) to track that a user is working out optimally. 如需詳細資訊,請參閱GATT 用戶端GATT 伺服器主題。For more information, see the GATT Client and GATT Server topics.

監看員和發行者 (指標)Watchers and Publishers (Beacons)

除了「中央」和「周邊」角色之外,還有「觀察者」和「廣播者」角色。In addition to the Central and Peripheral roles, there are Observer and Broadcaster roles. 廣播者通常稱為「指標」,它們不透過 GATT 進行通訊,因為它們使用廣告封包中所提供的有限空間進行通訊。Broadcasters are commonly referred to as Beacons, they don't communicate over GATT because they use the limited space provided in the Advertisement packet for communication. 同樣地,觀察者不需要建立連線即可接收資料,它會掃描附近的廣告。Similarly, an Observer does not have to establish a connection to receive data, it scans for nearby advertisements. 若要設定 Windows 觀察附近的廣告,請使用 BluetoothLEAdvertisementWatcher 類別。To configure Windows to observe nearby advertisements, use the BluetoothLEAdvertisementWatcher class. 若要廣播指標承載,請使用BluetoothLEAdvertisementPublisher類別。In order to broadcast beacon payloads, use the BluetoothLEAdvertisementPublisher class. 如需詳細資訊,請參閱廣告主題。For more information, see the Advertisement topic.

另請參閱See Also