Bluetooth LE AT Example¶
This document mainly describes Bluetooth® Low Energy AT order set detailed examples of commands.
Important
This example will be adapted differently for different modules,Please check the support of the module instruction in your hand: Firmware iterations and 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:
Set the Bluetooth name. If not set the default is ai-thinker. (Optional, must be set before enabling slave mode)
Command:
AT+BLENAME=ai-thinkerResponse:
OK
Enable slave mode
Command:
AT+BLEMODE=0Response:
OK
Host:
Enabling host Mode
Command:
AT+BLEMODE=1Response:
OK
Scan for nearby devices (optional, set after host mode is enabled)
Command:
AT+BLESCAN=1Response:
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:
AT+BLECONNECT=a81710d8f4e4Response:
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
BLE iBeacon¶
Set Bluetooth iBeacon UUID (Optional, set before enabling iBeacon)
command :
AT+BLEIBCNUUID=00112233445566778899aabbccddeeffResponse:
OK
Set Bluetooth iBeacon data (optional, set before enabling iBeacon)
command :
AT+BLEIBCNDATA=1122,3344,5566,14Response:
OK
Open iBeacon
command :
AT+BLEMODE=2Response:
OK