October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Build and Test a BLE GATT Server with ESP-IDF

Build Espressif’s NimBLE GATT server example, connect to it from a phone, write an LED characteristic and read or subscribe to generated heart-rate data.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To learn Bluetooth Low Energy (BLE) with ESP-IDF, build Espressif’s NimBLE_GATT_Server example, flash it to a compatible ESP32-series development board, then use a phone to connect, control the board’s LED characteristic, and read or subscribe to demonstration heart-rate data. The tutorial uses NimBLE, a BLE-only host stack; choose Bluedroid instead if your project also needs Classic Bluetooth.

Understand the BLE pieces in this example

BLE software is commonly described in three layers. Your application calls host APIs; the host implements protocols such as GAP, GATT/ATT, SMP and L2CAP, and communicates with the controller through HCI. The controller handles lower-level radio and link functions, including the PHY and Link Layer. Host and controller may be integrated on one chip or separated.

As an Amazon Associate I earn from qualifying purchases.

GAP: finding devices and making connections

GAP defines how devices advertise, scan and connect, as well as the roles they take. An advertiser sends advertising data; a scanner listens for it. An initiator can request a connection to a connectable advertiser. Once connected, the advertiser is the peripheral and the initiator is the central. BLE also supports connectionless broadcast and observer roles.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

GATT and ATT: organizing data

ATT describes attributes and how clients and servers access them. An attribute has a handle, type, value and permissions; its type is identified by a UUID. Bluetooth SIG-defined UUIDs commonly use 16 bits, while vendor-defined UUIDs often use 128 bits. GATT builds on ATT to organize data into services and characteristics: a GATT server stores and manages characteristics, and a GATT client reads or writes them.

#1 Best Overall
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (3PCS)
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Support LWIP protocol, Freertos
  • SupportThree Modes: AP, STA, and AP+STA
  • Ultra-Low power consumption, Compatible with Arduino IDE
  • ESP32 is a safe, reliable, and scalable to a variety of applications

Choose a host stack and check your chip

Stack Bluetooth support Practical fit
ESP-Bluedroid Classic Bluetooth and BLE Consider it when the project needs Classic Bluetooth as well as BLE.
ESP-NimBLE BLE only A natural choice for this BLE-only tutorial; Espressif says it requires less heap and flash than Bluedroid.

Both stacks have documented GATT client/server paths, but available examples and features depend on the target. Espressif’s current chip support overview lists Bluetooth controller, Bluedroid and NimBLE support across multiple ESP32-series chips, while support differs among modules. Check the exact chip and example configuration before building. Espressif’s statement that the original ESP32 supports Dual-Mode Bluetooth 4.2 and is certified for Dual-Mode Bluetooth 4.2 and Bluetooth LE 5.0 applies to that chip; it should not be generalized to every ESP32-series device. See Espressif’s Bluetooth LE overview and the ESP-IDF Bluetooth API index.

Prepare the board and phone

  • An ESP32-series development board whose chip target is supported by the example.
  • An ESP-IDF development environment.
  • A phone with nRF Connect for Mobile installed.

The walkthrough does not require a particular board model. Confirm the board’s chip target before proceeding. Espressif’s BLE device discovery and GATT server tutorial provides the example details and procedure below.

Rank #2
ELEGOO 3PCS ESP-32 Dev Boards, ESP-WROOM-32, USB-C, WiFi Bluetooth 4.2
  • Dual-Core Performance Up to 240 MHz: Run sensor processing, wireless communication, automation logic and connected-device tasks on a 32-bit dual-core ESP32 platform designed for responsive embedded and IoT projects
  • Built-in Wi-Fi and Bluetooth 4.2: Connect to 2.4 GHz Wi-Fi networks or use Bluetooth Classic and BLE for wireless sensors, smart devices, remote controls, home automation and other connected projects
  • Flexible Power-Saving Modes: ESP32 power-management features support dynamic clock scaling and low-power operating modes, helping developers reduce energy use in compatible sensing, monitoring and connected-device applications, suitable for battery-powered Internet of Things (IoT) devices.
  • USB-C Programming with CP2102: Connect through USB-C for power, sketch uploads and serial monitoring, while GPIO, UART, SPI and I2C interfaces support sensors, displays, motor drivers and other modules (USB-C cable not included)
  • Over-the-Air Update Support: Configure OTA functionality through a compatible ESP-32 software framework to update deployed firmware over Wi-Fi without reconnecting the board by USB for every revision

Build and flash the NimBLE GATT server

  1. Open a terminal with the ESP-IDF environment enabled.
  2. Change to <ESP-IDF Path>/examples/bluetooth/ble_get_started/nimble/NimBLE_GATT_Server.
  3. Set the target to the chip on your board: idf.py set-target <chip-name>.
  4. Connect the board, then build, flash and open its serial monitor: idf.py flash monitor.

Use the target name for your actual chip; the example configuration and supported features can vary by target and ESP-IDF release.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Connect from nRF Connect and inspect the services

  1. Open nRF Connect for Mobile and scan for nearby BLE devices.
  2. Find NimBLE_GATT in the results and connect.
  3. Inspect the services. The example includes GAP and GATT foundational services, a Heart Rate Service, and an Automation IO Service.

The Heart Rate Service UUID is 0x180D, and its Heart Rate Measurement characteristic UUID is 0x2A37. The LED characteristic in the Automation IO service uses a vendor-specific 128-bit UUID.

Rank #3
ELEGOO ESP-32 Super Starter Kit with Tutorial Compatible with Arduino IDE
  • Powerful ESP-32 Board: Unlock the world of Internet of Things (IoT) and advanced electronics with the heart of this kit: the ESP-32 board. It features a powerful dual-core processor, integrated Wi-Fi and Bluetooth 4.2, making it perfect for building connected, smart devices that communicate with your phone or the cloud. It's fully compatible with the Arduino IDE for easy programming.
  • Super Starter Kit: This kit contains over 35 different modules and electronic components, including sensors, displays, motors, and input devices. From LEDs and buttons to an OLED screen, servo motor, and keypad, you have everything needed to explore a vast range of projects in one box.
  • Step by Step Online Tutorial: Jump right in with our detailed, beginner-friendly tutorial. Access 30+ projects with complete code, clear circuit diagrams, and step-by-step instructions. Learn the fundamentals of electronics, coding, and how to utilize the ESP-32's unique capabilities without any prior experience.
  • Hands-on Learning for All Skill Levels: Perfect for students, makers, engineers, and hobbyists. Start with basic circuits and coding, then progress to intermediate and advanced IoT applications. Build practical projects like weather stations, smart home controllers, remote-controlled devices, and interactive gadgets. The skills you learn are the foundation for real-world innovation.
  • Quality & Great Support: Elegoo is committed to quality. We provide a clear, detailed tutorial guide, refined code, and a well-organized component kit. All modules are carefully selected for reliability and ease of use. Our dedicated technical support team and active online community are ready to help you succeed in your learning journey.

Test LED control and heart-rate updates

Write the LED characteristic

  1. In the connected device’s service list, open Automation IO and select the LED characteristic.
  2. Choose the write action, select ON or OFF, and send the value.
  3. Check whether the board’s LED changes. If the board has no user LED, look for the corresponding indication in the serial log.

This tests a GATT write from the phone client to the board’s server characteristic.

Read or subscribe to the heart-rate characteristic

Open Heart Rate Measurement and either read its value or enable notifications to receive updates. In this example, the displayed value is randomly generated, fluctuates between 60 and 80, and updates about once per second. It is demonstration data, not a sensor measurement or a person’s heart rate. The Client Characteristic Configuration Descriptor (CCCD), UUID 0x2902, records whether notifications or indications are enabled.

Rank #4
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (1 PCS)
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Support LWIP protocol, Freertos;ESP32 is a safe, reliable, and scalable to a variety of applications
  • SupportThree Modes: AP, STA, and AP+STA
  • Ultra-Low power consumption, Compatible with Arduino IDE
  • 1PCS 30Pin ESP32 Development Board 2.4GHz WiFi Dual Cores Microcontroller Integrated with Antenna RF Low Noise Amplifiers Filters
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What to learn next

After the server exercise, use the documented ESP-IDF examples to explore the other side of a connection or different BLE roles. The API index includes GATT client/server walkthroughs and NimBLE central, peripheral and heart-rate examples. Select an example that matches the target chip and the role your application needs; the index is available at ESP-IDF Bluetooth API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Documentation pages and chip support can change across ESP-IDF releases. Use the guide matching your installed release and verify the selected target’s current configuration before adapting the example.

Best Value
HiLetgo ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA for Arduino IDE
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Ultra-Low power consumption, works perfectly with the Arduino IDE
  • Support LWIP protocol, Freertos
  • SupportThree Modes: AP, STA, and AP+STA
  • ESP32 is a safe, reliable, and scalable to a variety of applications

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.