BLE - UART 客戶端

Materials

  • AmebaD [AMB21 / AMB22 / AMB23 / BW16] x 2

範例説明

介紹

在此範例中,使用BLE連接兩個RTL8722開發板。 其中一個運行BLE UART服務,另一個使用客戶端連接到該服務,並且兩塊開發板都可以通過UART服務進行通信。

步驟

在第一個開發板上,上傳BLE UART服務範例代碼。 有關詳細說明,請參考範例說明。

For the second board, open the example, “Files” “Examples” “AmebaBLE” “BLEUartClient”.

../../../../_images/image13.png

Upload the code and press the reset button on Ameba once the upload is finished. Reset the UART service board first, wait for the BLE advertisement process to begin, and reset the UART client board. The client board should scan, discover, and connect to the service board. After connecting, the client board will verify that the correct UART service exists on the service board, before enabling notifications on the TX characteristic. Any message typed in the serial terminal will be sent to the other board using the UART service.

../../../../_images/image23.png

程式碼説明

BLEClient class 用於發現連接的BLE設備上存在的服務。 發現過程將創建與連接的設備上存在的服務,特徵和描述符相對應的BLERemoteService,BLERemoteCharacteristic和BLERemoteDescriptor對象。然後可以使用這些對象讀取與寫入數據至所連接的設備。