ESP32 Bluetooth Cheatsheet
ESP32 Bluetooth Cheatsheet
BLE server, characteristics, notifications, and Classic SPP.
BLE Setup
| BLEDevice::init("Name") | Initialise BLE with a device name |
| BLEDevice::createServer() | Create a GATT server |
| pServer->setCallbacks(new Callbacks()) | Register connect/disconnect callbacks |
| pServer->createService(SERVICE_UUID) | Create a BLE service with a UUID |
Characteristics
| PROPERTY_READ | Client can read the characteristic value |
| PROPERTY_WRITE | Client can write a new value |
| PROPERTY_NOTIFY | Server pushes updates to the client |
| addDescriptor(new BLE2902()) | Required descriptor to enable notifications |
| pChar->setValue(str) | Set the current value of a characteristic |
| pChar->notify() | Push the current value to all subscribed clients |
Advertising
| BLEDevice::getAdvertising() | Get the advertising object |
| pAdv->addServiceUUID(uuid) | Advertise a specific service UUID |
| pAdv->start() | Start advertising ߀” device becomes discoverable |
| pAdv->stop() | Stop advertising |
Classic BT Serial
| #include "BluetoothSerial.h" | Include the Classic Bluetooth serial library |
| SerialBT.begin("DeviceName") | Start Classic BT and set the pairing name |
| SerialBT.available() | Check if data is waiting in the BT receive buffer |
| SerialBT.read() | Read one byte from the BT buffer |
| SerialBT.println("Hello") | Send a line of text over Bluetooth Serial |