🤖
LinkIt 7697 BlocklyDuino 使用指南
  • LinkIt 7697 BlocklyDuino 使用指南
    • 認識 LinkIt 7697
    • 認識 BlocklyDuino
    • BlocklyDuino v2 & v3 比較
    • 安裝開發環境 (v2)
      • 安裝 Arduino 編輯器
      • 安裝驅動並連接開發板
      • 安裝 BlocklyDuino 編輯器
      • 連結兩個編輯器並上傳程式
    • 安裝開發環境 (v3)
    • BlocklyDuino 基礎操作
    • 實作範例教學
      • A01. 內建 LED 閃爍
      • A02. 外接 LED 閃爍
      • A03. 外接 LED 呼吸燈
      • A04. RGB LED 顏色變化
      • A05. 外部按鈕控制開關
      • A06. 蜂鳴器播放聲音
      • A07 .可變電阻控制電壓輸出
      • A08. 伺服馬達控制
      • A21. DHT: 溫濕度感應器
      • A22. HTU21D: 溫溼度感應器
      • A23. PMSX003: PM2.5 感測器
      • A24. HC-SR04P: 超音波測距
      • A25. ADXL345: 加速規(動態)
      • A26. ADXL345: 加速規(手勢)
      • A27. 1602/2004: 液晶顯示模組
      • A28. WS2812: RGB 彩色燈條
      • A29. MFRC522: RFID
      • B00. Grove 相關基礎知識
      • B01. Grove 光感應器
      • B02. Grove 超音波測距感應器
      • B03. Grove 溫溼度感應器
      • B04. Grove 繼電器
      • B05. Grove LED 燈條
      • B06. Grove OLED 顯示器
      • C01. 雲端控制 LED 開關
      • C02. 上傳溫溼度到雲端
      • D01. 手機透過 BLE 讀寫裝置資料
      • E01. 遙控器: 按鈕控制 LED
    • 資源鏈結
  • LinkIt 7697 - Arduino IDE 開發指南
    • 環境設定
      • 設定 Arduino IDE
      • 將 LinkIt 7697 連接到電腦
        • 在 Windows 上安裝 CP2102N 驅動程式
        • 在 macOS 上安裝 CP2102N 驅動程式
      • 執行第一個程式
    • 開發指南
      • GPIO
      • UART
      • ADC
      • EINT (外部中斷 / External Interrupt)
      • I2C
      • SPI
      • EEPROM
      • Timer
      • Flash (索引式儲存空間)
      • RTC (Real-Time Clock)
      • Software Serial
      • 使用 Wi-Fi 函式庫
      • 使用 MCS 函式庫
        • 連接到 MCS
        • 連接到 MCSLite
          • 建立可透過 MCS Lite 控制的 Beacon
        • MCS 函式庫 API 使用手冊
          • MCSDevice
          • MCSLiteDeviceMCSLiteDevice
          • MCSDataChannel 相關類別
      • 使用 BLE 低功耗藍牙
        • 藍牙信標
        • 主控裝置
        • 周邊裝置
        • 已知限制
        • LBLE API 指南
          • LBLE
          • LBLECentral
          • LBLEPeripheral
          • LBLEAdvertisementData
          • LBLEService
          • LBLECharacteristic
          • LBLEAddress
          • LBLEUuid
          • LBLEClient
      • 使用 LinkIt Remote
        • LRemote API
        • LRemote 控制元件 API
      • LinkIt 7697 腳位的初始狀態
      • LinkIt 7697 供電說明
      • 更新 Bootloader 與韌體
      • Flash 燒錄工具
      • FOTA 更新
      • LinkIt 7697 的功能限制
      • 自行編譯 Arduino Package
      • 回報問題
    • 週邊元件連接教學
      • SMD 按鈕
      • RGB 三色 LED
      • 可變電阻
      • 九軸感應器 (MPU-9250)
      • 溫度與濕度感應器 (AM2302)
      • 超音波距離感應器
      • 光感應器 (LM358)
      • 0.96 吋 OLED 顯示模組 (SSD1308Z)
      • 長條型 LED 顯示模組 (MY9221)
      • 繼電器
      • 伺服馬達 (EMAX 9g ES08A Servo)
      • 使用 74HC595 驅動七段顯示器
      • 使用 MAX7219 驅動七段顯示器
      • 使用 MAX7219 驅動 8x8 矩陣式顯示器
      • 使用 OLED 模組 (如 SH1106 / SSD1306... 等模組)
      • 使用 PCF8574 / PCF8574A 驅動 1602 LCD
    • 開發套件與擴充板
      • Grove Starter Kit
      • Robot Shield
        • OTTO97
    • 下載
    • 資源連結
    • BSP 版本更新資訊
  • LinkIt 7697 - Development Guide for Arduino IDE
    • Environment Setup
      • Setup Arduino IDE
      • Connecting LinkIt 7697 to Computer
        • Install CP2102N Driver on Windows
        • Install CP2102N Driver on macOS
      • Run Your First Sketch
    • Developer Guide
      • GPIO
      • UART
      • ADC
      • External Interrupt
      • I2C
      • SPI
      • EEPROM
      • Timer
      • Flash (Key-Pair Storage)
      • RTC (Real-Time Clock)
      • Software Serial
      • Using the Wi-Fi Library
      • Using MCS Library
        • Connecting to MCS
        • Connecting to MCSLite
          • Build a Beacon controlled by MCS Lite
        • MCS Library API Reference
          • MCSDevice
          • MCSLiteDevice
          • MCSDataChannel Classes
      • Using Bluetooth
        • Beacons
        • Central Devices
        • Peripheral Devices
        • Limitations of LBLE library
        • LBLE Library API Guide
          • LBLE
          • LBLECentral
          • LBLEPeripheral
          • LBLEAdvertisementData
          • LBLEService
          • LBLECharacteristic
          • LBLEAddress
          • LBLEUuid
          • LBLEClient
      • Using LinkIt Remote
        • LRemote
        • LRemote Control Classes
      • Initial Pin State of LinkIt 7697
      • Powering the LinkIt 7697
      • Update Bootloader and Firmware
      • Flash Uploading Tool
      • FOTA Update
      • Limitations of LinkIt 7697
      • Source Code of Arduino Package
      • Issue Report
    • Tutorial
      • SMD Buttons
      • RGB LED
      • Potentiometer
      • IMU 9DOF v2.0 (MPU-9250)
      • Temperature and Humidity Sensor Pro (AM2302)
      • Grove Ultrasonic Ranger
      • Light Sensor (LM358)
      • Grove OLED Display 0.96" (SSD1308Z)
      • LED Bar v2.0 (MY9221)
      • Relay
      • Mini Servo (EMAX 9g ES08A Servo)
      • Driving 7-segment Displays with 74HC595
      • Driving 7-segment Displays with MAX7219
      • Driving 8x8 Dot Matrices with MAX7219
      • Using OLED module (SH1106 / SSD1306... etc.)
      • Driving 1602 LCD with PCF8574 / PCF8574A
    • Kits and Shields
      • Grove Starter Kit
      • Robot Shield
        • OTTO97
    • Download
    • Resources
    • BSP Release Notes
Powered by GitBook
On this page
  • Constructors
  • Connection Methods
  • Service Methods
  • Characteristic Methods
  1. LinkIt 7697 - Arduino IDE 開發指南
  2. 開發指南
  3. 使用 BLE 低功耗藍牙
  4. LBLE API 指南

LBLEClient

此類別允許使用者連線到其他的低功耗藍牙周邊裝置。

若欲存取其他低功耗藍牙周邊裝置,首先請建構一個 LBLEClient 物件,然後呼叫 LBLEClient::connect(address) 來連接到該裝置所對應的裝置地址,如下:

// assume LBLECentral::scan has already performed.
// connect to the 1st device scanned.
LBLEClient client;
LBLEAddress serverAddress = LBLECentral.getBLEAddress(0);
client.connect(serverAddress);
while(!client.connected()){
    delay(100); 
}
// now we are connnected.

如果連線成功的話,client.connected() 將會回傳 true。

接著,搜尋該裝置是否支援開發者所需要的服務,可以透過這幾個 API 來使用:

  • getServiceCount()

  • getServiceUuid(index)

  • hasService(uuid).

當確認該裝置上面有所需的服務之後,可以利用不同的 API 來讀寫該服務所提供的資料特性。此時有兩個選擇:

  • 根據資料特性的 UUID 來讀寫:如果本來就知道要讀寫的資料特性的 UUID 的話,此方法相當簡便。然而,有些情況,同一個裝置的不同服務,是有可能會提供相同 UUID 的資料特性的。用這個方法的話,最終可能會存取到意料之外的資料特性。

  • 根據資料特性的流水號來讀寫:開發者要先取得每一個服務的流水號,再取得每一個服務當中的每一個資料特性的流水號,並搜尋自己所需要的資料特性的 UUID。最後,可以根據服務與特性的流水號來進行讀寫。利用這個方法,需要呼叫比較多的 API,但好處是可以處理有相同的 UUID 的資料特性的情形。

要注意的是,在讀寫資料特性時,LBLE 程式庫不會進行任何的型別檢查。所以,必須自行確保讀寫的資料特性的資料型別,在周邊裝置跟主控裝置上面都是一致的。

Constructors

LBLEClient

建構一個可以連線到周邊裝置的 LBLEClient 物件。

Syntax

Parameters

none

Returns

LBLEClient 物件

Connection Methods

connect()

connected()

disconnect()

根據裝置地址,開始連接至一個低功耗藍牙周邊裝置。

你可以利用 LBLECentral 單件來掃描鄰近的周邊裝置以及其對應的裝置地址。

呼叫此函式之後,可透過不斷呼叫 connected() 方法來確認是否已經成功完成連線。請注意,連線過程當中,程式庫會列舉遠端裝置的服務以及資料特性,所以會需要一些時間才能完成連線。

Syntax

Parameters

none

Returns

回傳 true:開始連線。請注意,這並不代表連線已經完成。

回傳 false:無法開始連線。

檢查連線是否已經完成。

Syntax

Parameters

none

Returns

回傳 true:已經連線成功。

回傳 false:尚未連線成功。

從遠端裝置斷線。

Syntax

client.disconnect();

Parameters

none

Returns

none

Service Methods

hasService()

getServiceCount()

getServiceName()

getServiceUuid()

getCharacteristicCount()

查詢遠端的周邊裝置是否有此 UUID 對應的服務。

Syntax

bool serviceAvailable = client.hasService(serviceUUID);

Parameters

serviceUUID 128-bit or 16-bit UUID to identify the service.

Returns

回傳 true:遠端的周邊裝置有支援此服務,反之則回傳 false。

查詢遠端的周邊裝置所支援的服務數量

Syntax

int serviceCount = client.getServiceCount();

Parameters

none

Returns

遠端裝置所支持的服務的數量。

這個幫手 API 可以協助查詢某個 service 是否有已知的名字。

Syntax

String serviceName = client.getServiceName(serviceIndex);

Parameters

serviceIndex 介於 0 到 (getServiceCount() - 1) 之間的流水號

Returns

該 Service 的名字。

根據服務的流水號,取得其 UUID。

Syntax

LBLEUuid uuid = clinet.getServiceUuid(serviceIndex);

Parameters

serviceIndex

介於 0 到 (getServiceCount() - 1) 之間的流水號

Returns

該服務的 UUID。

取得服務當中的資料特性的數目。

Syntax

LBLEUuid uuid = clinet.getCharacteristicCount(serviceIndex);

Parameters

serviceIndex

介於 0 到 (getServiceCount() - 1) 之間的流水號

Returns

服務當中的資料特性的數目。

Characteristic Methods

getCharacteristicUuid()

readCharacteristicString()

readCharacteristicInt()

writeCharacteristicFloat()

writeCharacteristicString()

writeCharacteristicInt()

writeCharacteristicFloat()

根據流水號取得資料特性的 UUID

Syntax

LBLEUuid uuid = clinet.getCharacteristicUuid(serviceIndex, characteristicIndex);

Parameters

serviceIndex

介於 0 到 (getServiceCount() - 1) 之間的流水號

characteristicIndex

介於 0 到 (getCharacteristicCount(serviceIndex) - 1) 之間的流水號

Returns

該流水號所對應的資料特性的UUID

從遠端的周邊裝置讀取一個資料特性的值,並以字串形式呈現。

Syntax

String value = client.readCharacteristicString(uuid)

String value = client.readCharacteristicString(serviceIndex, characteristicIndex)

Parameters

serviceIndex

介於 0 到 (getServiceCount() - 1) 之間的流水號

characteristicIndex

介於 0 到 (getCharacteristicCount(serviceIndex) - 1) 之間的流水號

Returns

該資料特性的數值,以字串型別表示。如果讀取失敗,則回傳空字串。

從遠端的周邊裝置讀取一個資料特性的值,並以整數形式呈現。

Syntax

int value = client.readCharacteristicInt(uuid)

int value = client.readCharacteristicInt(serviceIndex, characteristicIndex)

Parameters

serviceIndex

介於 0 到 (getServiceCount() - 1) 之間的流水號

characteristicIndex

介於 0 到 (getCharacteristicCount(serviceIndex) - 1) 之間的流水號

Returns

該資料特性的數值,以整數型別表示。如果讀取失敗,則回傳 0。

從遠端的周邊裝置讀取一個資料特性的值,並以浮點數形式呈現。

Syntax

float value = client.readCharacteristicFloat(uuid)

float value = client.readCharacteristicFloat(serviceIndex, characteristicIndex)

Parameters

serviceIndex

介於 0 到 (getServiceCount() - 1) 之間的流水號

characteristicIndex

介於 0 到 (getCharacteristicCount(serviceIndex) - 1) 之間的流水號

Returns

該資料特性的數值,以浮點數型別表示。如果讀取失敗,則回傳 0.0f。

將字串資料寫入遠端周邊裝置的特性。

Syntax

client.writeCharacteristicString(uuid, string_to_write)

client.writeCharacteristicString(serviceIndex, characteristicIndex, string_to_write)

Parameters

uuid
要存取的資料特性的 UUID

string_to_write

要寫入的字串值

serviceIndex

介於 0 到 (getServiceCount() - 1) 之間的流水號

characteristicIndex

介於 0 到 (getCharacteristicCount(serviceIndex) - 1) 之間的流水號

Returns

>0 :表示寫入成功。

0 : 表示寫入失敗。

將一個整數資料寫入遠端周邊裝置的特性。

Syntax

client.writeCharacteristicString(uuid, int_value)

client.writeCharacteristicString(serviceIndex, characteristicIndex, int_value)

Parameters

uuid
要存取的資料特性的 UUID

int_value

要寫入的數值

serviceIndex

介於 0 到 (getServiceCount() - 1) 之間的流水號

characteristicIndex

介於 0 到 (getCharacteristicCount(serviceIndex) - 1) 之間的流水號

Returns

>0 :表示寫入成功。

0 : 表示寫入失敗。

將一個浮點數資料寫入遠端周邊裝置的特性。

Syntax

client.writeCharacteristicString(uuid, float_value)

client.writeCharacteristicString(serviceIndex, characteristicIndex, float_value)

Parameters

uuid
要存取的資料特性的 UUID

float_value

要寫入的數值

serviceIndex

介於 0 到 (getServiceCount() - 1) 之間的流水號

characteristicIndex

介於 0 到 (getCharacteristicCount(serviceIndex) - 1) 之間的流水號

Returns

>0 :表示寫入成功。

0 : 表示寫入失敗。

PreviousLBLEUuidNext使用 LinkIt Remote

Last updated 3 years ago