Linux Format - UK (2019-12)

(Antfer) #1
52 LXF256 December 2019 http://www.linuxformat.com

TUTORIALS Pi Bluetooth


basic network for supporting wireless devices using
Bluetooth technology is called a piconet. A piconet
contains a Master Device (MD) and Slave Devices (SD)
as well as devices that can be both either Master or
Slave (MS). The Bluetooth spec dictates that a piconet
can have a maximum of one Master and seven Slaves.
The MD is the main controlling device – all the SDs
get their direction from this master. In order to
communicate, each device is assigned a specific
time period by the MD. Once the frequency-hopping
sequence is established, each device takes turns
communicating in their predefined time slots. This
technique avoids network collisions – collision being
a networking term describing when two devices try to
transmit at the same time.
Bluetooth devices connect either using
Asynchronous Connectionless Link (ACL) or
Synchronous Connection Oriented (SCO) protocols.
ACL connections transport data in frames, and SCO
uses streaming communication. ACL frames transport
data that is not time-dependent. The protocol contains
error detection and correction. SCO protocol data units
are used for transporting audio to devices such as
headsets and speakers.
A Bluetooth MD looks for SDs in the piconet by
‘enquiring’ in Bluetooth terminology – in other words,
scanning for devices within range. The MD sends out an
enquiry message and SDs respond with their ID and
MAC address. Before an SD can be found, it must be in

his tutorial describes how to upgrade the
Bluetooth protocol stack from version 5.43 to
5.50 on Raspbian Stretch. Bluetooth operation
on the Pi has been less than stellar in reliability since it
was first introduced in 2016, and this protocol stack
upgrade resolved some of those issues. With the
introduction of Raspbian Buster – done while this
tutorial was being written – the Bluetooth protocol
stack is now version 5.50. An upgrade to the operating
system may now be the easier fix.
If you are faced with a existing Pi installation that has
Bluetooth issues, but you’re unwilling to upgrade to the
current release, this tutorial may offer you some insight
into fixing your Bluetooth issues. Bear in mind that the
protocol stack upgrade requires some effort and isn’t as
smooth as what is offered in the latest Buster.
We’ll start this tutorial with Bluetooth theory. After
identifying the Bluetooth protocol stack, we’ll see how
to replace the current version with the latest version
available from the Bluetooth development team. With
the protocol stack installed, the tutorial reinforces what
was covered in the theory, by using the command line
to get a Bluetooth device working on the Pi.

Bluetooth in theory
Bluetooth was designed for devices that are in close
proximity with one another to communicate. The
Bluetooth protocol is a standard for radio frequency
(RF) wireless operation in the congested 2.4GHz
microwave frequency band.
The Bluetooth protocol uses 79 radio frequency
channels of 1MHz to communicate, covering a
frequency range of 2,402MHz to 2,480MHz. Bluetooth
Low Energy (BLE), the standard designed for low power
consumption, communicates using 40 2MHz channels.
Not all channels are used in a Frequency Hopping
Spread Spectrum (FHSS) scheme for data
transmissions. Depending on local regulations in some
countries, not all channels are available for use. In
additional, radio interference in the frequency band
result in some channels being removed temporarily
from the frequency-hopping sequence to ensure
communication integrity.
Networks of devices in close proximity are called a
Personal Area Network (PAN). Within the PAN, the

Frequency hopping to avoid bad channels.

Replacing a protocol


stack in Raspbian


Sean D. Conway
Replacing things
was his stock-in-
trade while
employed: first
aviation electronic
systems, then
lottery systems
and finally
telecomms
systems. Now
retired, he writes
about technology.

Raspberry Pi
3 Model B
16GB
microSD card
5V DC, 2.5
amp power
supply
Raspbian
Stretch Lite
(2019-04-08)
BlueZ 5.50

T


BLUETOOTH


OUR
EXPERT

YOU NEED


Sean D. Conway guides you through the steps of upgrading the existing


Bluetooth infrastructure in Raspberry Pi’s Raspbian.


2402
MHz
Time

Channel

bandwidth

1 of 79
channels

Channel
skipped
interference

2480
MHz

Channel hop interval

52 LXF256 December 2019 http://www.linuxformat.com


TUTORIALS Pi Bluetooth


basicnetworkforsupportingwirelessdevicesusing
Bluetoothtechnologyiscalleda piconet.A piconet
containsa MasterDevice(MD)andSlaveDevices (SD)
aswellasdevicesthatcanbebotheitherMaster or
Slave(MS).TheBluetoothspecdictatesthata piconet
canhavea maximumofoneMasterandseven Slaves.
TheMDisthemaincontrollingdevice– allthe SDs
get their direction from this master. In order to
communicate, each device is assigned a specific
time period by the MD. Once the frequency-hopping
sequence is established, each device takes turns
communicating in their predefined time slots. This
technique avoids network collisions – collision being
a networking term describing when two devices try to
transmit at the same time.
Bluetooth devices connect either using
Asynchronous Connectionless Link (ACL) or
Synchronous Connection Oriented (SCO) protocols.
ACL connections transport data in frames, and SCO
uses streaming communication. ACL frames transport
data that is not time-dependent. The protocol contains
error detection and correction. SCO protocol data units
are used for transporting audio to devices such as
headsets and speakers.
A Bluetooth MD looks for SDs in the piconet by
‘enquiring’ in Bluetooth terminology – in other words,
scanning for devices within range. The MD sends out an
enquiry message and SDs respond with their ID and
MAC address. Before an SD can be found, it must be in

histutorialdescribeshowtoupgradethe
Bluetoothprotocolstackfromversion5.43to
5.50onRaspbianStretch.Bluetoothoperation
onthePihasbeenlessthanstellarinreliabilitysinceit
wasfirstintroducedin2016,andthisprotocolstack
upgraderesolvedsomeofthoseissues.Withthe
introductionofRaspbianBuster– donewhilethis
tutorialwasbeingwritten– theBluetoothprotocol
stackisnowversion5.50.Anupgradetotheoperating
systemmaynowbetheeasierfix.
If youarefacedwitha existingPiinstallationthathas
Bluetoothissues,butyou’reunwillingtoupgradetothe
currentrelease,thistutorialmayofferyousomeinsight
intofixingyourBluetoothissues.Bearinmindthatthe
protocolstackupgraderequiressomeeffortandisn’tas
smoothaswhatisofferedinthelatestBuster.
We’llstartthistutorialwithBluetooththeory.After
identifyingtheBluetoothprotocolstack,we’llseehow
toreplacethecurrentversionwiththelatestversion
availablefromtheBluetoothdevelopmentteam.With
theprotocolstackinstalled,thetutorialreinforceswhat
wascoveredinthetheory,byusingthecommandline
togeta BluetoothdeviceworkingonthePi.

Bluetooth in theory
Bluetooth was designed for devices that are in close
proximity with one another to communicate. The
Bluetooth protocol is a standard for radio frequency
(RF) wireless operation in the congested 2.4GHz
microwave frequency band.
The Bluetooth protocol uses 79 radio frequency
channels of 1MHz to communicate, covering a
frequency range of 2,402MHz to 2,480MHz. Bluetooth
Low Energy (BLE), the standard designed for low power
consumption, communicates using 40 2MHz channels.
Not all channels are used in a Frequency Hopping
Spread Spectrum (FHSS) scheme for data
transmissions. Depending on local regulations in some
countries, not all channels are available for use. In
additional, radio interference in the frequency band
result in some channels being removed temporarily
from the frequency-hopping sequence to ensure
communication integrity.
Networks of devices in close proximity are called a
Personal Area Network (PAN). Within the PAN, the

Frequencyhoppingtoavoidbadchannels.

Replacing a protocol


stack in Raspbian


SeanD.Conway
Replacingthings
washisstock-in-
tradewhile
employed:first
aviationelectronic
systems,then
lotterysystems
andfinally
telecomms
systems.Now
retired,hewrites
abouttechnology.


RaspberryPi
3 ModelB
16GB
microSDcard
5V DC, 2.5
amppower
supply
Raspbian
StretchLite
(2019-04-08)
BlueZ 5.50

T


BLUETOOTH


OUR
EXPERT

YOU NEED


Sean D. Conway guides you through the steps of upgrading the existing


Bluetooth infrastructure in Raspberry Pi’s Raspbian.


2402
MHz
Time

Channel

bandwidth

1 of 79
channels

Channel
skipped
interference

2480
MHz

Channel hop interval
Free download pdf