Bluetooth Low Energy (BLE) is a popular wireless communication protocol designed for low power consumption and efficient data exchange. With its integration into the ESP32 chip, BLE opens up a range of possibilities for creating innovative and battery-efficient applications.
In this post, we’ll explore the capabilities of BLE on the ESP32 and provide a practical code example to get you started.
The ESP32’s built-in BLE functionality provides a seamless way to incorporate low-energy wireless communication into your projects. Here’s why BLE with ESP32 is so compelling:
To demonstrate the power of BLE with the ESP32, we’ll create a simple BLE server that advertises a service and allows a BLE client to connect and read a characteristic value.
Prerequisites:
Ensure you have the ESP32 board package installed in your Arduino IDE. If not, follow these instructions:
https://dl.espressif.com/dl/package_esp32_index.json
to the “Additional Boards Manager URLs” fieldBelow is a basic example of a BLE server code that advertises a service and provides a characteristic that clients can read.
Explanation:
BLEDevice::init("ESP32_BLE_Server")
: Initializes the BLE device with a name.BLEServer::createServer()
: Creates a BLE server.BLEService::createService(SERVICE_UUID)
: Creates a BLE service with a unique UUID.BLECharacteristic::createCharacteristic(CHARACTERISTIC_UUID, PROPERTY_READ)
: Creates a characteristic with read properties.pCharacteristic->setValue("Hello from ESP32")
: Sets the initial value of the characteristic.BLEAdvertising::start()
: Starts BLE advertising so that clients can discover the service.With this basic setup, you can expand your BLE server to include multiple services and characteristics, handle client connections, and even write data to characteristics. The ESP32’s BLE capabilities offer a wealth of possibilities for creating innovative and interactive applications.
We’d love to hear from you! Join our community and let’s create something amazing together.
#esp32 #bluetooth #pleasedontcode #lightblue #bledevice