This example demonstrates how to use the NimBLEStreamClient class to connect to a BLE GATT server and communicate using the familiar Arduino Stream interface.
- 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
- 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()
- First, upload the NimBLE_Stream_Server example to one ESP32
- Upload this client sketch to another ESP32
- The client will automatically:
- Scan for the server
- Connect when found
- Set up the stream interface
- Begin bidirectional communication
- You can also type in the Serial monitor to send data to the server
Must match the server:
- Service:
6E400001-B5A3-F393-E0A9-E50E24DCCA9E - Characteristic:
6E400002-B5A3-F393-E0A9-E50E24DCCA9E
The example displays:
- Server discovery progress
- Connection status
- All data received from the server
- Confirmation of data sent to the server
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 Serial monitor