-
Notifications
You must be signed in to change notification settings - Fork 17
tonyespy/bluez5-spp-example
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is an example Bluetooth Serial Port Profile client and server application which uses bluez 5.x to exercise the Bluetooth Serial Port Profile (1.2). To run as a server, just invoke from the command-line using 'sudo' and no arguements. To run as a client, adding any string after the command name will trigger this mode. First, the application registers itself to bluez using the ProfileManager1's RegisterProfile method. It will indicate to bluez what role it's playing (client or server). If run as server, this will cause the BT controller to list the Serial Port profile when the bluetoothctl 'show' command is run. Likewise, from a remote device, the bluetootctl 'info' command will also show the Serial Port profile listed for the device. When run a client, the Serial Port profile will not be listed on either side. When a connection is triggered on the client, bluez will call the NewConnection method and pass an active Bluetooth RFCOMM socket which then can be used to write data to the server. On the server side, if the client device is paired, but trusted, then the default agent needs to be configured (eg. agent on, default-agent), and if so, a prompt will be displayed asking an admin to confirm the incoming server request. If trusted, or an admin confirms the service request, then the server's NewConnection method will be called with a fd representing the other end of the BT socket. In the current implementation, the IO is done very simply with read/write calls. Also, the server explicitly sets the socket to blocking mode to simplify the code. When boths sides complete their IO, the application exits. To trigger the connection from client to server, the following dbus-send command can be used: $ sudo dbus-send --system --print-reply --dest=org.bluez \ /org/bluez/hciX/dev_XX_YY_ZZ_AA_BB_CC \ org.bluez.Device1.ConnectProfile \ string:"00001101-0000-1000-8000-00805f9b34fb" * hciX - replace X with controller index (eg. hci0) * dev_XX_YY_ZZ_AA_BB_CC - replace with server's BT control MAC address
About
Bluez5 Serial Port Profile example client/server
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published