Bluetooth LE AT Example ================================= This document mainly describes :doc:`../command-set/BLE_AT_Commands` detailed examples of commands. .. contents:: :local: :depth: 1 .. Important:: - This example will be adapted differently for different modules,Please check the support of the module instruction in your hand: :doc:`../instruction/other/firmware_differences`。 The following example uses two development boards at the same time, with one as the slave and the other as the host. Explanation: ``Note Optional instructions can be set or not set, according to their actual situation to decide whether to set``. BLE communication based on Gatt ------------------------------------------------------------------------ **Slave:** 1. Set the Bluetooth name. If not set the default is ai-thinker. (Optional, must be set before enabling slave mode) Command: .. code-block:: none AT+BLENAME=ai-thinker Response: .. code-block:: none OK 2. Enable slave mode Command: .. code-block:: none AT+BLEMODE=0 Response: .. code-block:: none OK **Host:** 1. Enabling host Mode Command: .. code-block:: none AT+BLEMODE=1 Response: .. code-block:: none OK 2. Scan for nearby devices (optional, set after host mode is enabled) Command: .. code-block:: none AT+BLESCAN=1 Response: .. code-block:: none OK Devices Found:1/5 name:ai-thinker MAC:a81710d8f4e4 rssi:-23 Devices Found:2/5 name:N/A MAC:03f3e35771ce rssi:-73 Devices Found:3/5 name:N/A MAC:45797518112f rssi:-71 Devices Found:4/5 name:N/A MAC:53e4da7c288f rssi:-82 Devices Found:5/5 name:PB02-LIGHT MAC:bb02bbbbbb0d rssi:-89 Description: - Different Bluetooth devices in your environment have different scanning responses. 3.Connecting slave Command: .. code-block:: none AT+BLECONNECT=a81710d8f4e4 Response: .. code-block:: none OK > Response: ``After ble is connected, it enters transparent mode by default. Any data received by the serial port is directly sent to the peer device. If you need to send other commands or receive data from other connections (such as tcp connections), exit the transparent mode first. The command to exit transparent transmission mode is +++ (without bringing back the car line feed). If you need to send ble data after exiting transparent transmission mode, you can use the command AT+BLESEND to send it.Or send the command AT+TRANSENTER to re-enter transparent transmission.`` **GIF presentation** ``Please click on the larger view. Left window host, right window slave`` .. figure:: ../../_static/ble_connect_example.gif :scale: 50 % :align: center :alt: blecommunication link ------------------------------------------------------------------------ BLE iBeacon ------------------------------------------------------------------------ 1. Set Bluetooth iBeacon UUID (Optional, set before enabling iBeacon) command : .. code-block:: none AT+BLEIBCNUUID=00112233445566778899aabbccddeeff Response: .. code-block:: none OK 2. Set Bluetooth iBeacon data (optional, set before enabling iBeacon) command : .. code-block:: none AT+BLEIBCNDATA=1122,3344,5566,14 Response: .. code-block:: none OK 3. Open iBeacon command : .. code-block:: none AT+BLEMODE=2 Response: .. code-block:: none OK