BLE - UART 客户端

材料准备

  • 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对象。然后可以使用这些对象读取与写入数据至所连接的设备。