mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2026-07-04 23:41:07 +02:00
59ef15a218
Co-authored-by: doudar <17362216+doudar@users.noreply.github.com>
NimBLE Stream Client Example
This example demonstrates how to use the NimBLEStreamClient class to connect to a BLE GATT server and communicate using the familiar Arduino Stream interface.
Features
- Uses Arduino Stream interface (print, println, read, available, etc.)
- Automatic server discovery and connection
- Bidirectional communication
- Buffered TX/RX using ring buffers
- Automatic reconnection on disconnect
- Similar usage to Serial communication
How it Works
- Scans for BLE devices advertising the target service UUID
- Connects to the server and discovers the stream characteristic
- Initializes
NimBLEStreamClientwith the remote characteristic - Subscribes to notifications to receive data in the RX buffer
- Uses familiar Stream methods like
print(),println(),read(), andavailable()
Usage
- Build and flash the NimBLE_Stream_Server example to one ESP32 using ESP-IDF (
idf.py build flash monitor) - Build and flash this client example to another ESP32 using ESP-IDF
- The client will automatically:
- Scan for the server
- Connect when found
- Set up the stream interface
- Begin bidirectional communication
- Open
idf.py monitoron each board to observe stream traffic
Service UUIDs
Must match the server:
- Service:
6E400001-B5A3-F393-E0A9-E50E24DCCA9E - Characteristic:
6E400002-B5A3-F393-E0A9-E50E24DCCA9E
Monitor Output
The example displays:
- Server discovery progress
- Connection status
- All data received from the server
- Confirmation of data sent to the server
Testing
Run with NimBLE_Stream_Server to see bidirectional communication:
- Server sends periodic status messages
- Client sends periodic uptime messages
- Both echo data received from each other
- You can send data from either
idf.py monitorsession