This section provides a description
on how to use the demo application to connect two or more configured boards and
communicate over bluetooth (BR/EDR and LE). We will setup one of the boards as a
central device over LE and Master over BR/EDR and the other board as a peripheral
device over LE and Slave over BR/EDR. We will then initiate the connections from the
first device to the other. Once connected, we will show how to use the new features
over the connection.
Establish ConnectionConnection over LEPeripheral device initialization and
advertising
- We will setup the first board as
a Peripheral device. Note the bluetooth address of the server; we will later use
this to initiate a connection from the client
- The first command we need is
RegisterSPPDMMULTI, this command will register the SPP-LE service and initiate
the Server, type RegisterSPPDMMULTI.
Note: The following steps
describe how to configure the Advertising operation, you can change any
value that you want and jump to step g to start advertising with the changed
values or the default values for the values that weren't changed and follow
the instructions.
The default values are:
- Discoverability
Mode
- General Discover-able
Connectability Mode
- Connectable Own Address
Type
- Public address
Advertising Intervals
- Minimum interval = 100,
Maximum interval - 200
- In order to configure the
Discoverability mode, we need to use the SetDiscoverabilityMode command and the
mode that can be:
0 = Non
Discoverable, 1 = Limited Discoverable, 2 = General Discoverable
For this example we will use
General Discoverable mode (The same as in the default values).
- In order to configure the
Connectability mode, we need to use the SetConnectabilityMode command and the
mode that can be:
0 = Non
Conectable, 1 = Connectable, 2 = Direct Connectable, 3 = Low Duty Cycle
Direct Connectable.
For
this example we will use Low Duty Cycle Direct Connectable which is a new
feature from specification 4.1.
- In order to configure the
Advertising Intervals, we need to use the SetAdvertisingInterval command and the
minimum and maximum intervals that their range can be between 20..10240 in
ms
Note: When using High Duty
Cycle Direct Connectable this command won't have any affect.
- In order to configure the Own
Address Type, we need to use the SetRandomAddress command and the type that can
be:
0 = Static, 1 =
Resolvable, 2 = Non-Resolvable
For this example we will use
Static random address type.
- Now, after we configured the
different values we can use the AdvertiseLE command in order to start
advertising.
The
AdvertiseLE command has multiple options to advertise:
- Option 1: Disable advertising
AdvertiseLE 0
- Option 2: Advertising without any
Direct Connectable mode and with own address type public
AdvertiseLE 1 or AdvertiseLE
1 0
- Option 3: Advertising without any
Direct Connectable mode and with own address type Random
AdvertiseLE 1 1 [Own Random
BD_ADDR]
- Option 4: Advertising with any
Direct Connectable mode and with own address type public and peer type public
AdvertiseLE 1 0 0 0 [Peer
Public BD_ADDR]
- Option 5: Advertising with any
Direct Connectable mode and with own address type Random and peer type public
AdvertiseLE 1 1 [Own Random
BD_ADDR] 0 [Peer Public BD_ADDR]
- Option 6: Advertising with any
Direct Connectable mode and with own address type Random and peer type public
AdvertiseLE 1 1 [Own Random
BD_ADDR] 1 [Peer Random BD_ADDR]
For this example we will use
option 5, The device is on Low Duty Cycle Direct Connectable, Own Address type -
Random address and the peer device use Public address.
Now the peripheral is
advertising and waiting for connection request from the central
device.
Central device connection creation and configurationThe Central can initiate the
connection request and when the peripheral will advertise the connection will be
created.
[Steps 1 and 2 are
optional if you already know the Bluetooth address of the device that you want to
connect to]
- The Central device can try to
find which LE devices are in the vicinity using the command: StartScanning 0.
Note: When using Public
address as Own address type, you can only use StartScanning 0
- Once you have found the device,
you can stop scanning by using the command: StopScanning
- Retrieve the Bluetooth address of
the first board that was configured as a peripheral.
- Issue a ConnectLE command in the
central terminal in order to start the connection procedure.
The ConnectLE command has
multiple options to connect:
- Option 1: Connect to Remote
device using public address type and own address type is also public.
ConnectLE [Peer Public
BD_ADDR]
ConnectLE
[Peer Public BD_ADDR] 0
ConnectLE [Peer Public BD_ADDR] 0 0
- Option 2: Connect to Remote
device using random address type and own address type is public.
ConnectLE [Peer Random
BD_ADDR] 1
ConnectLE
[Peer Random BD_ADDR] 1
- Option 3: Connect to Remote
device using random address type and own address type is random.
ConnectLE [Peer Random
BD_ADDR] 1 1
- Option 4: Connect to Remote
device using public address type and own address type is random.
ConnectLE [Peer Public
BD_ADDR] 1 1
For this example we will use
option 2, The peripheral using Random address type and the central device using
Public address type.
- When a central successfully
connects to the peripheral , both the central and peripheral will output
LE_Connection_Complete and information about the current connection.
Note: The Supported
features may change according to the Bluetooth device. For this example we
used CC2564C for both sides.
Now we have a connection
established and both devices are ready to send data to each other. Before
the information can be sent we must first discover and configure the service
in the Central terminal.
- In order to discover the service
handles we use the DiscoverLEService Command, type DiscoverLEService [BD_ADDR or
Connection ID] [UUID Type] [0 when using BD_ADDR (optional) or 1 when using
Connection ID (Mandatory)]. The handles that are discovered will be displayed in
the terminal.
The
DiscoverLEServicecommand has multiple options to discover:
- Option 1: Discover
SPPDMMulti service which is using custom 32bit UUIDs a new feature from
specification 4.1.
This option will store the SPPDMMulti handles.
DiscoverLEServicecommand [Peer BD_ADDR] [1]
DiscoverLEServicecommand [Peer BD_ADDR] [1] [0]
DiscoverLEServicecommand [Connection ID] [1] [1]
- Option 2: Discover SPPLE
service which is using custom 128bit UUIDs.
This option will
store the SPPLE handles.
DiscoverLEServicecommand [Peer BD_ADDR] [2]
DiscoverLEServicecommand [Peer BD_ADDR] [2] [0]
DiscoverLEServicecommand [Connection ID] [2] [1]
- Option 3 - Discover
Generic services which are using 16/32/128bit UUIDs.
This option will
only print the handles.
DiscoverLEServicecommand [Peer BD_ADDR] [16 or 32 or 128]
DiscoverLEServicecommand [Peer BD_ADDR] [16 or 32 or 128] [0]
DiscoverLEServicecommand [Peer BD_ADDR] [16 or 32 or 128] [1]
For this example we will
use option 1, The peripheral is advertising with SPPDMMulti Handles so we
need to store them and we will use the Connection ID method.
- In order to configure the service
we use the ConfigureLEService Command, type ConfigureLEService [BD_ADDR or
Connection ID] [0 when using BD_ADDR (optional) or 1 when using Connection ID
(Mandatory)].
- After the LE connection is
complete and configured we can use the ConnectedDevices command in order to
receive a list of connected LE and/or BR/EDR devices (More information on this
command can be found in paragraph 2.5.1.1b).
Note: The list above is
from the Central side.
Connection over BR/EDRSlave device
initializationWe will setup
the one of the boards (In our example, the one that we are running as a Peripheral
device) as a slave so we need to open a SPP port on this device.
- In order to open a SPP port, use
OpenServer command with the port number that you want to open.
For this example we will use
port number 10.
Note: Although the Server
port number that was opened is 10, the Serial Port ID that will be used is
1. We allow only one BR/EDR connection so if you will open more than one
ports, when the device will connect to a SPP port all the opened ports will
close automatically
Master device connection creationNow that the Slave device opened the
SPP port, the Master can initiate the connection.
[Step 1 is optional if you already
know the Bluetooth address of the device that you want to connect to]
- The Master device can try to find
which BR/EDR devices are in the vicinity using the command: Inquiry.
-
- Retrieve the Bluetooth
address of the first board that was configured as a slave.
- In order to start the
connection procedure type in the slave terminal OpenClient [Inquiry
Index or BD_ADDR] [Server Port Number] [0 when using Inquiry Index
(optional) or 1 when using BD_ADDR (Mandatory)].
- When a master
successfully connects to the slave , both the master and slave will
output the information about the current connection and will try to
initiate role switch
Now we have a
connection established and both devices are ready to send data to
each other.
- After the BR/EDR
connection is complete also we can use the ConnectedDevices command in
order to receive a list of connected LE and/or BR/EDR devices (More
information on this command can be found in paragraph 2.5.1.1b).
Note: The list
above is from the LE Central terminal, the BR/EDR role is slave and
not master because of the role switch. You can see 2 devices because
the LE connection was to Random address type and the BR/EDR
connections was to public address type if both connections were to
the same address type you will see only 1 device.
Disconnect ConnectionDisconnect over
LE
- In order to disconnect the
connection, we use the DisconnectLE Command, type DisconnectLE [BD_ADDR or
Connection ID] [0 when using BD_ADDR (optional) or 1 when using Connection ID
(Mandatory)].
Disconnect over BR/EDR
- In order to disconnect the
connection, in this case close the RFCOMM that was opened there are two
options:
Option 1, we use
the CloseServer command from the slave , type CloseServer [Serial Port ID],
if no Serial Port ID will be entered all opened ports will be closed.
Option 2, we use the
CloseClient command from the slave , type CloseClient Server [Serial Port
ID], if no Serial Port ID will be entered all opened ports will be
closed.
For this
example we will use option 2.
Pairing devicesLE PairingNote: The following steps describe how to
configure the LE pairing operation, you can change any value that you want and jump
to step c to start the LE pairing procedure with the changed values or the default
values for the values that weren't changed and follow the instructions.
The default values are:
Pairability Mode - Pairable
I/O Capability - No
Input/Output
Bonding Type -
Bonding
MITM Requirement -
Yes
SC Enable - Yes
P256 debug - No
- In order to configure the
Pairability mode, we need to use the SetPairabilityMode command and the mode
that can be:
0 = Non Pairable,
1 = Pairable
For this
example we will use Pairable mode (The same as in the default
values).
Note: After changing the
pairability mode you will be able to see that default values.
- In order to change the pairing
parameters we can use the ChangePairingParameters Command, type
ChangePairingParameters [I/O Capability] [Bonding Type] [MITM Requirement] [SC
Enable] [P256 debug] where the options for this parameters are:
I/O Capability (0 = Display
Only, 1 = Display Yes/No, 2 = Keyboard Only, 3 = No Input/Output, 4 =
Keyboard/Display)
Bonding Type (0 = No Bonding, 1 = Bonding)
MITM Requirement (0 = No, 1 =
Yes)
SC Enable (0 = No,
1 = Yes)
P256 debug (0
= No, 1 = Yes)
For this example we will
use the default values.
The LE Pairing procedure
require an active LE connection, so after running the instructions in
paragraph 2.1.1 you can start the LE pairing procedure.
- In order to start the LE pairing
procedure we need to use the PairLE command, so type PairLE [BD_ADDR or
Connection ID] [0 when using BD_ADDR (optional) or 1 when using Connection ID
(Mandatory)].
- When a central successfully
paired to the peripheral , both the central and peripheral will output
LE_Authentication and information about the current connection.
SPPDMMulti Demo Secure Connection and BondingNote: The following steps describe how to
configure the BR/EDR pairing operation, you can change any value that you want and
jump to steps c to start the BR/EDR pairing procedure with the changed values or the
default values for the values that weren't changed and follow the
instructions.
The default
values are:
Pairability Mode -
Pairable
I/O Capability - No
Input/Output
MITM Requirement
- Yes
- In order to configure the
Pairability mode, we need to use the SetCBPairabilityMode command and the mode
that can be:
0 = Non Pairable,
1 = Pairable, 2 = Pairable (Secure Simple Pairing
For this example we will use
Pairable mode (The same as in the default values).
- In order to change the pairing
parameters we can use the ChangeSimplePairingParameters Command, type
ChangeSimplePairingParameters [I/O Capability] [MITM Requirement] where the
options for this parameters are:
I/O Capability (0 = Display
Only, 1 = Display Yes/No, 2 = Keyboard Only, 3 = No Input/Output)
MITM Requirement (0 = No, 1
= Yes)
For this example we will
use the default values.
The BR/EDR Pairing
procedure require a non-active BR/EDR connection, so after running this
instructions, run the instructions in paragraph 2.1.2.
- In order to start the BR/EDR
pairing procedure we need to use the Pair command, so type Pair [BD_ADDR or
Connection ID] [Pairing type (0 = Dedicated - (Default), 1 = General)] [0 when
using BD_ADDR (optional) or 1 when using Connection ID (Mandatory)].
For this example we will
use BD_ADDR and General pairing type.
- When a central successfully
paired to the peripheral , both the central and peripheral will output
GAP_Authentication_Response and information about the current connection.
Note: if your devices weren't
paired before, you may need to do additional steps - in this example we need
to enter PINCodeResponse in both devices.
Un-Pairing devicesLE Un-Pairing
- When there is no need any longer
for the LTK stored in the device, you can delete it with the UnPairLE command
with the following parameters [BD_ADDR or Connection ID] [0 when using BD_ADDR
(optional) or 1 when using Connection ID (Mandatory)].
Note: Connection ID can be used
only when the devices are connected, the LTK will be deleted but the
connection will stay paired until disconnection procedure is
requested.
BR/EDR Un-Pairing
- When there is no need any longer
for the Link Key stored in the device, you can delete it with the EndPairing
command with the following parameters [Inquiry Index or BD_ADDR] [Server Port
Number] [0 when using Inquiry Index (optional) or 1 when using BD_ADDR
(Mandatory)].
Note: Using the
EndPairing command will cancel the bonding between the devices and delete
the Link Key, when using only Pair command with General method, the
connection that was created will be disconnected, but if you had additional
connection like RFCOMM port connected, the EndPairing command will not
disconnect you.
Send and read DataLE Data
- In order to send data over LE, we
need to use the LESend command with the following parameters [BD_ADDR or
Connection ID] [Number of bytes to send] [0 when using BD_ADDR (optional) or 1
when using Connection ID (Mandatory)].For this example we will send 100 bytes and we will use the connection ID
option.
- In order to read the data that
was sent, we need to use the LERead command with the following parameters
[BD_ADDR or Connection ID] [0 when using BD_ADDR (optional) or 1 when using
Connection ID (Mandatory)].
Note: The connection ID can be found easily in the Data Indication
Event.
BR/EDR Data
- In order to send data over
BR/EDR, there are two options to send the data.
Option 1: Write command, This
command will send only 10 bytes every use. To use this command type, Write
[Serial Port ID].
Option 2: CBSend
command, This command will send the user input amount of bytes, This
function can also disable or enable the sniff mode. To use this command
type, CBSend [Number of Bytes to send] [Serial Port ID] [0 - Enable
Automatic Sniff (Default) or 1 - Disable Automatic Sniff].
For this example we will
use option 1 and send 10 bytes.
- In order to read the data that
was sent, we need to use the Read command with the following parameter [Serial
Port ID].
Note: The Serial Port ID
can be found easily in the SPP Data Indication event.
Additional CommandNote: The
following paragraphs describe how to specific functions and are optional to
use.
Generic featuresLE
CommandsNote: The following step
describe how to change the connection parameters, you can change the values in the
valid range or use the default parameters.
The default values are:
Connection_Interval_Min - 50ms
(Range: 8..4000 in ms)
Connection_Interval_Max - 200ms (Range: 8..4000 in ms)
Minimum_Connection_Length - 0ms
(Range: 0..65535 in ms)
Maximum_Connection_Length - 10000ms (Range: 0..65535 in ms)
Slave_Latency - 0ms (Range:
0..500 in ms)
Supervision_Timeout - 20000ms (Range: 100..32000 in ms)
ScanInterval - 100ms (Range:
3..10240 in ms)
ScanWindow
- 100ms (Range: 3..10240 in ms)
- In order to configure the
connection parameters, we need to use the SetConnectionParameters command and
fill the following parameters [Connection_Interval_Min]
[Connection_Interval_Max] [Minimum_Connection_Length]
[Maximum_Connection_Length] [Slave_Latency] (Range: 0..500 in
ms)[Supervision_Timeout] [ScanInterval] [ScanWindow]
Note: This command only
stores the new connection parameters, in order to change the connection
parameters you need to use additional command. ConnectLE when you want to
create new connection (Paragraph 2.1.1) or LEUpdateConnectionParameters for
existing connection (Paragraph 2.6.2a).
- When the device is connected to
multiple devices you can use ConnectedDevices in order to see the details of
each connection.
This command
has two options to work.
Option 1: List the contains
only connected devices, For this option type ConnectedDevices with or
without the parameter 0.
In the Image below you can see that we are
connected to three devices: To the first we are connected as a Master in LE
(Central) and Slave in BR/EDR (Because of the role switch). To the second we are
connected as a Master in LE (Central). To the third we are connected as a Slave
in LE (Peripheral).Option 2: List of all
devices in the list, that means devices that was previously LE paired or
opened SPP server ports.
In the Image below you can see the difference
between option 1 and option 2. Option 1 shows that we are connected only to one
device (Connection ID 2). Option 2 shows the full list. The green color shows
devices that are not connected but we are paired with them (LTK is stored). The
yellow color shows the device that is connected (Connection ID 2). The light
blue color shows the opened SPP Server ports that are waiting to be connected.
Note: We allow only one BR/EDR connection so if you will open more than one
ports, when the device will connect to a SPP port all the opened ports will
close automatically.
BR/EDR CommandsThis sample
application has Sniff mechanism that is used to free the baseband when BR/EDR
connection is being used.
when
using our sample and enabling this mode, when reading and writing over BR/EDR the
device will exit and enter sniff automatically.
Note: The following step describe how to
change the sniff parameters, you can change the values or use the default
parameters.
The default values
are:
MaxInterval -
600ms
MinInterval -
400ms
Attempts - 4
Timeout - 1
- In order to configure the sniff
parameters, we need to use the SetSniffParameters command and fill the following
parameters [SerialPortID] [MaxInterval (ms)] [MinInterval (ms)] [Attempt]
[Timeout].
Note: This command
only stores the new sniff parameters for a specific Serial Port ID, that
means that the device must be connected over BR/EDR (Paragraph
2.1.2).
Note: This parameters that
are stored, are stored only in the device that run this command and are not
stored on the other device, you will need to run this command again on the
other device as well or you can jump to step b if you want to initiate the
sniff mode from the second device and enter the parameters
directly.
- In order to enter to sniff mode,
we need to use the SniffMode command with the parameter [SerialPortID] all the
following parameters are optional [MaxInterval (ms)] [MinInterval (ms)]
[Attempt] [Timeout].
Note: If you
set the optional parameters in step a they will be sent automatically when
you will you Sniffmode [SerialPortID], if not and if you didn't filled them
the default values will be sent.
Note: The Interval in HCI
Mode Change Event is in baseband units and will displayed on both
devices.
- In order to exit the sniff mode,
we need to use the ExitSniffMode command with the parameter [SerialPortID].
Note: The HCI Mode Change
Event will displayed on both devices.
New 4.1 and 4.2 Features
- Until Bluetooth specification 4.1
only the central could send update connection parameters, in specification 4.1
the peripheral can request update connection parameters. While the connection is
active, the central or the peripheral can ask to change the connection
parameters after changing them in paragraph 2.6.1.1a. In order to send this
request, use the LEUpdateConnectionParameters command with the following
parameters [BD_ADDR or Connection ID] [0 when using BD_ADDR (optional) or 1 when
using Connection ID (Mandatory)].
Note: In the image you can
see that the Central return status accepted to the peripheral and changed
the parameters.
Both
following command need the devices to be paired over LE, see paragraph 2.3.1
for instructions.
- The
SetAuthenticatedPayloadTimeout allows us to change the Authenticated Payload
Timeout parameter from the default value that is 30 seconds to the user input
value. In order to change it, type SetAuthenticatedPayloadTimeout with the
following parameters [BD_ADDR or Connection ID] [Authenticated Payload Timeout]
[0 when using BD_ADDR (optional) or 1 when using Connection ID (Mandatory)].
The value Authenticated
Payload Timeout is in ms units.
- The
QueryAuthenticatedPayloadTimeout allows us to query the Authenticated Payload
Timeout parameter of the connection. In order to query it, type
QueryAuthenticatedPayloadTimeout with the following parameters [BD_ADDR or
Connection ID] [0 when using BD_ADDR (optional) or 1 when using Connection ID
(Mandatory)].