This document describes the new Stream-based examples that demonstrate using BLE characteristics with the familiar Arduino Stream interface.
The NimBLE Stream classes (NimBLEStreamServer and NimBLEStreamClient) provide a simple way to use BLE characteristics like serial ports. You can use familiar methods like print(), println(), read(), and available() just like you would with Serial.
Difficulty: Beginner
Purpose: Introduction to the Stream API
This is the simplest example, perfect for getting started. It creates a BLE server that echoes back any data it receives. Uses default UUIDs for quick setup.
Key Features:
- Minimal setup code
- Simple echo functionality
- Good starting point for learning
Use Case: Testing BLE connectivity, learning the basics
Difficulty: Intermediate
Purpose: Full-featured server implementation
A complete BLE server example that demonstrates all the major features of NimBLEStreamServer. Shows connection management, bidirectional communication, and proper server setup.
Key Features:
- Custom service and characteristic UUIDs
- Connection callbacks
- Periodic message sending
- Echo functionality
- MTU negotiation
- Connection parameter updates
Use Case: Building custom BLE services, wireless data logging, remote monitoring
Difficulty: Intermediate
Purpose: Full-featured client implementation
Demonstrates how to scan for, connect to, and communicate with a BLE server using NimBLEStreamClient. Pairs with the NimBLE_Stream_Server example.
Key Features:
- Automatic server discovery
- Connection management
- Reconnection on disconnect
- Bidirectional communication
- Serial passthrough (type in Serial monitor to send via BLE)
Use Case: Building BLE client applications, data collection from BLE devices
- Upload
NimBLE_Stream_Echoto your ESP32 - Open Serial monitor (115200 baud)
- Use a BLE app (like nRF Connect) to connect
- Find service UUID
0xc0de, characteristic0xfeed - Subscribe to notifications
- Write data to see it echoed back
- Upload
NimBLE_Stream_Serverto one ESP32 - Upload
NimBLE_Stream_Clientto another ESP32 - Open Serial monitors for both (115200 baud)
- Client will automatically find and connect to server
- Observe bidirectional communication
- Type in either Serial monitor to send data
- Wireless Serial Communication: Replace physical serial connections with BLE
- Data Logging: Stream sensor data to a mobile device or another microcontroller
- Remote Control: Send commands between devices using familiar print/println
- Debugging: Use BLE as a wireless alternative to USB serial debugging
- IoT Applications: Simple data exchange between ESP32 devices
The examples demonstrate these familiar methods:
Output (Sending Data):
print(value)- Print data without newlineprintln(value)- Print data with newlineprintf(format, ...)- Formatted outputwrite(data)- Write raw bytes
Input (Receiving Data):
available()- Check if data is availableread()- Read a single bytepeek()- Preview next byte without removing it
Status:
hasSubscriber()- Check if a client is connected (server only)ready()oroperator bool()- Check if stream is ready
Both server and client support configuration before calling begin():
bleStream.setTxBufSize(2048); // TX buffer size
bleStream.setRxBufSize(2048); // RX buffer size
bleStream.setTxTaskStackSize(4096); // Task stack size
bleStream.setTxTaskPriority(1); // Task priorityThese examples work with:
- ESP32 (all variants: ESP32, ESP32-C3, ESP32-S3, etc.)
- Nordic chips (with n-able Arduino core)
- Any BLE client supporting GATT characteristics with notifications
- Arduino Stream Reference
- NimBLE-Arduino Documentation
- Each example includes a detailed README.md file
Client can't find server:
- Check that both devices are powered on
- Verify UUIDs match between server and client
- Ensure server advertising is started
Data not received:
- Verify client has subscribed to notifications
- Check that buffers aren't full (increase buffer sizes)
- Ensure both
init()andbegin()were called
Connection drops:
- Check for interference
- Reduce connection interval if needed
- Ensure devices are within BLE range