Bluetooth LE AT Examples

This document describes detailed examples of Bluetooth® Low Energy AT Command Set commands.

Important

The following examples use two development boards: one as a peripheral (slave) and one as a central (master).

Note:

Optional commands may or may not be configured depending on your actual requirements.

GATT-Based BLE Communication

Peripheral (Slave):

  1. Set the Bluetooth name; the default is ai-thinker if not set. (Optional; must be set before enabling peripheral mode)

Command:

AT+BLENAME=ai-thinker

Response

OK
  1. Enable peripheral mode

Command:

AT+BLEMODE=0

Response

OK

Central (Master):

  1. Enable central mode

Command:

AT+BLEMODE=1

Response

OK
  1. Scan nearby devices (optional; set after enabling central mode)

Command:

AT+BLESCAN=1

Response

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

Note:

  • Scan results vary depending on the Bluetooth devices in your environment.

  1. Connect to the peripheral

Command:

AT+BLECONNECT=a81710d8f4e4

Response

OK
>

Note:

After BLE connects, transparent transmission mode is enabled by default; any data received on the serial port is sent directly to the peer device. To send other commands or receive data from other connections (such as TCP), exit transparent mode first using +++ (without CR/LF). After exiting transparent mode, use AT+BLESEND to send BLE data, or AT+TRANSENTER to re-enter transparent mode.

Animated Demo

Open the full-size image to view. Left window: central; right window: peripheral.

BLE Connection Communication

BLE iBeacon

  1. Set Bluetooth iBeacon UUID (optional; set before enabling iBeacon)

Command:

AT+BLEIBCNUUID=00112233445566778899aabbccddeeff

Response

OK
  1. Set Bluetooth iBeacon data (optional; set before enabling iBeacon)

Command:

AT+BLEIBCNDATA=1122,3344,5566,14

Response

OK
  1. Enable iBeacon

Command:

AT+BLEMODE=2

Response

OK