Using Bluetooth

Bluetooth defines a master/slave architecture. A Bluetooth enabled device may act as either a master or a slave in a Bluetooth network. A master can connect to multiple slaves; a slave is usually only connected to one master.

To communicate with a Bluetooth app on another device, an app must follow relevant Bluetooth profiles. You can find profiles that have been adopted by the Bluetooth Special Interest Group (SIG) on the Bluetooth website.

Profiles
Profiles are specifications that define the behaviors of Bluetooth enabled devices when connecting and communicating with each other. For example, the Serial Port Profile (SPP) describes how to set up virtual serial ports to connect two Bluetooth enabled devices. You can create an app that allows its users to chat over an SPP connection between two devices.
Device discovery
Because a Bluetooth device doesn't know about other devices before they come into range, it needs to find other devices through a process called device discovery. In this process, a device that has services to offer makes itself discoverable by advertising itself; a device that needs a service scans for devices in range that may provide the service it's looking for. Any Bluetooth device can scan for other devices or be discoverable by other devices.
Pairing and connecting
When a scanner device finds a service it needs, it pairs with the remote device that provides the service before attempting to connect with it. This process is known as pairing. Pairing is an authentication process between the two devices and usually involves some method of confirmation by the user. When pairing succeeds, a link key is stored at both devices to indicate the paired status. Now the client device may initiate a connection to the server device.
Paired devices remain paired until either device decides to remove the pairing.
UUID
Universally Unique Identifiers (UUIDs) are globally unique, 128-bit numbers, and are used to identify Bluetooth services and other features. UUIDs defined by the Bluetooth SIG have a short form of either 16 or 32 bits, which are guaranteed to be unique within Bluetooth. You can find these UUIDs on the Bluetooth website. For example, short UUIDs for the Generic Attribute Profile (GATT) are listed here. However, if you develop a new Bluetooth service, you must obtain a unique 128-bit UUID for your service. You can do this using UUID generators that are available online. There are no short forms for a developer-generated UUID.

You can access the Bluetooth classic capabilities on BlackBerry 10 devices using either the QtConnectivity API or the Bluetooth C API. The BlackBerry 10 Native SDK supports Qt 4.8. The Qt Mobility website provides examples to demonstrate how the QtConnectivity API may be used in mobile apps.

The BlackBerry 10 C API supports Bluetooth capabilities through the following header files:
  • btdevice.h: APIs that allow a BlackBerry 10 device to discover and pair with another Bluetooth enabled device, as well as to retrieve services and other device information.
  • btgatt.h, , btgattsrv.h: APIs that support the Generic Attribute Profile (GATT), which can be used with both LE and classic devices
  • bthid.h: APIs that support the Human Interface Device (HID) profile
  • btopp.h: APIs that support the Object Push Profile (OPP)
  • btspp.h: APIs that support the Serial Port Profile (SPP)

Each header file has its own initialization function. To use the functions in any of these files, you must call the initialization function of that file first.

Last modified: 2015-07-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus