C++ application to use BlueZ over D-Bus to scan for Bluetooth devices, connect to them, and manage GATT characteristics with notifications.
- Scan for Bluetooth devices using BlueZ over D-Bus
- Filter devices by desired service UUIDs
- Connect/disconnect to/from Bluetooth devices
- Discover GATT characteristics
- Enable/disable notifications on characteristics
- Read from and write to characteristics
- Real-time notification processing with terminal output
- Linux system with BlueZ installed
- D-Bus development libraries (
libdbus-1-dev
) - CMake (3.10 or higher)
- C++17 compatible compiler
# Install dependencies (Ubuntu/Debian)
sudo apt install libdbus-1-dev build-essential cmake
# Build the application
mkdir build
cd build
cmake ..
make
Run the application as root or with appropriate D-Bus permissions for BlueZ:
sudo ./bscm-bluetooth-manager
- Scan for devices - Discover nearby Bluetooth devices
- Set service filter - Filter devices by service UUIDs (optional)
- List devices with desired services - Show filtered devices
- Connect to device - Establish connection to a selected device
- Disconnect from device - Disconnect from a connected device
- Manage characteristics - Work with GATT characteristics
- Process notifications - Listen for notifications for 10 seconds
You can filter devices by service UUIDs. Enter UUIDs comma-separated:
- Example:
0000180f-0000-1000-8000-00805f9b34fb, 0000180a-0000-1000-8000-00805f9b34fb
- Enter
none
to clear the filter and show all devices
Once connected to a device, you can:
- Enable/disable notifications on characteristics
- Read characteristic values
- Write data to characteristics (in hex format)
- View characteristic UUIDs and properties
When notifications are enabled and received, they are displayed in the terminal with:
- The characteristic path that sent the notification
- Raw data in hexadecimal format
- ASCII representation (printable characters only)
- Start the application and scan for devices
- Set a service filter (e.g., Battery Service:
0000180f-0000-1000-8000-00805f9b34fb
) - List filtered devices and select one to connect
- Explore characteristics and enable notifications on desired ones
- Write commands to control characteristics
- Monitor notifications in real-time
dbus_helper.cpp/h
- Low-level D-Bus communication wrapperbluetooth_manager.cpp/h
- High-level BlueZ interface and device managementmain.cpp
- CLI interface and main application logic
- Ensure BlueZ is running:
sudo systemctl status bluetooth
- Check D-Bus permissions for BlueZ access
- Run as root if experiencing permission issues
- Verify Bluetooth adapter is available:
hciconfig