mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2026-07-04 23:41:07 +02:00
ee8ea37ebb
Co-authored-by: doudar <17362216+doudar@users.noreply.github.com>
1.6 KiB
1.6 KiB
NimBLE Stream Server Example
This example demonstrates how to use the NimBLEStreamServer class to create a BLE GATT server that behaves like a serial port using the familiar Arduino Stream interface.
Features
- Uses Arduino Stream interface (print, println, read, available, etc.)
- Automatic connection management
- Bidirectional communication
- Buffered TX/RX using ring buffers
- Similar usage to Serial communication
How it Works
- Creates a BLE GATT server with a custom service and characteristic
- Initializes
NimBLEStreamServerwith the characteristic configured for notifications and writes - Uses familiar Stream methods like
print(),println(),read(), andavailable() - Automatically handles connection state and MTU negotiation
Usage
- Build and flash this example to your ESP32 using ESP-IDF (
idf.py build flash monitor) - The device will advertise as "NimBLE-Stream"
- Connect with a BLE client (such as the NimBLE_Stream_Client example or a mobile app)
- Once connected, the server will:
- Send periodic messages to the client
- Echo back any data received from the client
- Display all communication in
idf.py monitor
Service UUIDs
- Service:
6E400001-B5A3-F393-E0A9-E50E24DCCA9E - Characteristic:
6E400002-B5A3-F393-E0A9-E50E24DCCA9E
These are based on the Nordic UART Service (NUS) UUIDs for compatibility with many BLE terminal apps.
Compatible With
- NimBLE_Stream_Client example
- nRF Connect mobile app
- Serial Bluetooth Terminal apps
- Any BLE client that supports characteristic notifications and writes