ESP32 integrates Bluetooth link controller and Bluetooth baseband, which carry out the baseband protocols and other low-level link routines, such as modulation/demodulation, packets processing, bitstream processing, frequency hopping, etc. This tutorial “SimpleBLE on ESP32” shows how to use SimpleBLE to advertise the name of the device and change it on the press of a button. The button is attached between GPIO0 and GND, and the device name changes each time the button is pressed.
BLE stands for Bluetooth Low Energy. It’s a Bluetooth protocol that boosts considerably lower power consumption compared to “Classic” Bluetooth. BLE “servers” (like the ESP32 reading sensor data) can “notify” clients (like your smartphone) periodically to send them bits of data. Therefore, BLE is more suitable for low-power IoT applications where large amounts of data aren’t required.
All BLE devices use the Generic Attribute Profile (GATT). The Generic Attributes (GATT) services are collections of characteristics and relationships to other services that encapsulate the behavior of part of a device. The GATT has the following terms
Here using the library SimpleBLE
#include<SimpleBLE.h>
After enabling the Bluetooth on the device, connect to the ESP32 SimpleBLE. When pressing the push button, changing the device’s name.
ble.begin("ESP32 SimpleBLE");
Initializes the BLE in order to use all its methods within the sketch.
ble.begin("ESP32 SimpleBLE"); Serial.println("Press the button to change the device's name");
The ESP32 (acting as the server) “notifies” the client via the TX characteristic UUID and data is sent to the ESP32 and received via the RX characteristic UUID. However, since there is sending and receiving, TX on the ESP32 is actually RX on the Android app, so inside Thunkable you will notice that the UUID’s are swapped from those in the Arduino sketch.