The ESP32 controller with Bluetooth Low Energy can act as either server and client. The server advertises its existence. And it can be found by other devices and it contains the data that the client can read. The BLE supports two types of modes such as Broadcast mode and Mesh network mode. In broadcast mode, the server transmits data to many clients that are connected and in a mesh network mode, all the devices are connected.


Both server and client have a “SERVICE UUID” to make a connection between server and client. Inside this service, there can be several “characteristics” which are defined by characteristic UUID’s. We use two characteristics TX and RX to send data to and receive data from the client. 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.


Code Snippet

Here using the libraries are

Next, we define the service and characteristic UUIDs for both TX and RX (two-way communication).

Initialize the ESP32 as a BLE device and set its name.

Create BLE server

Create BLE service using the service UUID.

And add characteristics

Start BLE service.

And start advertising. Advertising allows devices to broadcast information defining their intentions. Which means that when a mobile device has received a Bluetooth message, the recipient has the choice to either accept or decline the message. The recipient needs to positively indicate that they wish to receive marketing messages.

So, to create a UUID for your custom services and characteristics you would:

  1. Use a website such as UUID GENERATOR to generate a UUID (or multiple UUIDs)
  2. Make sure it does not conflict with a reserved UUID (avoid any containing XXXXXXXX-0000-1000-8000-00805F9B34FB where XXXXXXXX is any number).

Here using a BLE scanner app to send or receive the data.BLEServer2

Liked this article! You'll love our video courses.
Checkout our comprehensive pre-recorded ESP32 based Video Course for Internet of Things
More details
Spread the love, share this