Code Monkey home page Code Monkey logo

bluez5-spp-example's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.