Professional Documents
Culture Documents
Bluetooth
Bluetooth
Platform
Bluetooth
f
The Bluetooth Core Specification
EDR - enhanced data rate
HS high speed
IEEE 802!" is a #or$ing group of the Institute of Electrical and
Electronics Engineers %IEEE& IEEE 802 standards co''ittee
#hich specifies #ireless personal area net#or$ %()*+&
standards
Bluetooth versions comparison. Whats the
difference between the versions?(Part 1)
Bluetooth v1.2
)he use of low power consumption and coin cell batter operation also has its limitations.
$ata transfer rates with 8lassic Bluetooth technolo# usin# enhanced data rate (Bluetooth
v&.1 9 ($!) can e.ceed & +b's (actual paload), but practical transfer rates for Bluetooth low
ener# technolo# are below 100 kb's (actual paload of rou#hl 1'&0). )herefore, streamin#
Bluetooth low ener# connections will lose a #reat deal of the hu#e potential power savin#s
as the utili:ation approaches continuous transmission.
5n other words, some applications are better served with a Bluetooth low ener# connection
than others. )he use varies dependin# on the tpe of device a sensor is connected to.
Bluetooth Low Energy vs. Classic Bluetooth(Part 2)
$ifferences in Bluetooth Profile -upport
6 #ood e.ample of the differences is seen in serial port emulation. 8lassic Bluetooth
technolo# provides the serial port profile (-PP) for emulation of serial data connections.
Bluetooth low ener# technolo# provides no such support in the standard -pecification v1.0<
althou#h suppliers like connectBlue can provide a #ood level of support.
+an other profiles are not offered for Bluetooth low ener# technolo# because of the
differences in the connection models. )he 8lassic Bluetooth scenarios that are not part of
Bluetooth low ener# technolo# include headset (=-P), ob3ect e.chan#e (>B(?), audio
distribution (6&$P), video distribution (@$P), and file transfer (2)P).
Bluetooth Low Energy vs. Classic Bluetooth(Part 3)
Single!ode and "ual!ode#$hat "oes %hat !ean&
Because the two technolo#ies are fundamentall different, there are the two followin# options
for implementationsA
-in#le/mode $evices. )hese devices are stand/alone Bluetooth low ener# devices (also
known as B-martC devices) optimi:ed for small batter/operated devices with low cost
and low power consumption in focus. 6 tpical sin#le/mode device is a heart rate sensor.
$ual/mode $evices. )hese devices (also known as B-mart !eadC devices) include both
Bluetooth low ener# technolo# and 8lassic Bluetooth technolo#. $ual/mode devices
will rarel #ain in power savin# because the need to support both technolo#
implementations< the power savin#s will onl be achieved with the sin#le/mode option.
6 tpical dual/mode device is a mobile phone or P8.
Bluetooth Low Energy vs. Classic Bluetooth(Part 3)
Bluetooth .2 Core Specification
:a,ers
Bluetooth low ener# / Profile developmentB
What is a profile?
codec)
!28>++)
0 to G1& octets
5dentified b ,,5$s
8haracteristics specifications
)ransactionsA
!e"uest /H !esponse
8ommand
Fotification
5ndication /H 8onfirmation
-ome ke classesA
android.permission.B7,()>>)=
android.permission.B7,()>>)=Q6$+5F
-et up Bluetooth
2ind devices
alread paired or
available in the
local area
8onnect devices
via a
Bluetooth-ocket
)ransfer data
BluetoothAda(ter
Bluetooth6dapter.#et$efault6dapter()<
A
!eturns null if Bluetooth is not available
Bluetooth6dapter.is(nabled()
A
!eturns true if Bluetooth is on< false otherwise
BluetoothAda(ter 3*ont.4
Bluetooth6dapter.68)5>FQ!(R,(-)Q(F6B7(
Bluetooth6dapter.#etBonded$evices()<
Bluetooth6dapter.start$iscover()<
Bluetooth6dapter.cancel$iscover()
8ind 9 Sele*t "evi*e
private void select-erver() S
-etPBluetooth$eviceH paired$evices U
mBluetooth6dapter.#etBonded$evices()<
6rra7istP-trin#H paired$evice-trin#s U new 6rra7istP-trin#H()<
if (paired$evices.si:e() H 0) S
for (Bluetooth$evice device A paired$evices) S
paired$evice-trin#s.add(device.#etFame() 9 WXnC 9 device.#et6ddress())<
V
V
5ntent show$evices5ntent U new 5ntent(this, -how$evices.class)<
show$evices5ntent.put-trin#6rra7ist(.tra(WdevicesW, paired$evice-trin#s)<
start6ctivit2or!esult(show$evices5ntent, -(7(8)Q-(!@(!)<
V
8ind 9 Sele*t "evi*e 3*ont.4
public class -how$evices e.tends 7ist6ctivit S
T
protected void on8reate(Bundle saved5nstance-tate) S
T
'' search for more devices
mBluetooth6dapter.start$iscover()<
T
'' user selects one device
Bluetooth$evice device U
mBluetooth6dapter.#et!emote$evice('Y mac addr -trin# Y')<
5ntent data U new 5ntent()<
data.put(.tra(Bluetooth$evice.(?)!6Q$(@58(, device)<
set!esult(!(-,7)Q>N, data)<
finish()<
T
"evi*e "is*overy
Bluetooth$evice.68)5>FQ2>,F$
intent.#etParcelable(.tra(
Bluetooth$evice.(?)!6Q$(@58()
"evi*e "is*overy 3*ont.4
final Broadcast!eceiver m!eceiver U new Broadcast!eceiver() S
public void on!eceive(8onte.t conte.t, 5ntent intent) S
-trin# action U intent.#et6ction()<
if (Bluetooth$evice.68)5>FQ2>,F$.e"uals(action)) S
Bluetooth$evice device U intent
.#etParcelable(.tra(Bluetooth$evice.(?)!6Q$(@58()<
'' update displa
V
V
V<
1onne*ting "evi*es
8lient creates
BluetoothServerSo*6et
Bluetooth6dapter
.listen,sin#!fcommWith-ervice!ecord(name, uuid)
Bluetooth$evice
.create!fcomm-ocket)o-ervice!ecord(uuid)
Bluetooth-ocket.connect()
BluetoothSo*6et 3*ont.4
public class 8onnect)hread e.tends )hread S
T
public 8onnect)hread(-trin# device5$, =andler handler) S
m$evice U mBluetooth6dapter.#et!emote$evice(device5$)<
tr S
mBluetooth-ocket U m$evice
.create!fcomm-ocket)o-ervice!ecord($ata)ransfer6ctivit.6PPQ,,5$)<
V catch (5>(.ception e) S T V
V
T
BluetoothSo*6et 3*ont.4
public void run() S
mBluetooth6dapter.cancel$iscover()<
tr S
mBluetooth-ocket.connect()<
mana#e8onnected-ocket()<
V catch (5>(.ception connect(.ception) S T V
V
"ata %ransfer
private void mana#e8onnected-ocket() S
8onnection)hread conn U
new 8onnection)hread(mBluetooth-ocket, m=andler)<
m=andler.obtain+essa#e(
$ata)ransfer6ctivit.->8N()Q8>FF(8)($, conn)
.send)o)ar#et()<
conn.start()<
V
"ata %ransfer 3*ont.4
public class 8onnection)hread e.tends )hread S
T
8onnection)hread(Bluetooth-ocket socket, =andler handler)S
super()<
mBluetooth-ocket U socket<
m=andler U handler<
tr S
m5n-tream U mBluetooth-ocket.#et5nput-tream()<
m>ut-tream U mBluetooth-ocket.#et>utput-tream()<
V catch (5>(.ception e) S T V
V
T
"ata %ransfer 3*ont.4
T
public void run() S
bteZ[ buffer U new bteZ10&1[<
int btes<
while (true) S
tr S
btes U m5n-tream.read(buffer)<
-trin# data U new -trin#(buffer, 0, btes)<
m=andler.obtain+essa#e(
$ata)ransfer6ctivit.$6)6Q!(8(5@($,data).send)o)ar#et()<
V catch (5>(.ception e) S break< V
V
V
T
"ata %ransfer 3*ont.4
T
public void write(bteZ[ btes) S
tr S
m>ut-tream.write(btes)<
V catch (5>(.ception e) S T V
V
V
"ata %ransfer 3*ont.4
'' =andler in $ata)ransfer6ctivit
public =andler m=andler U new =andler() S
public void handle+essa#e(+essa#e ms#) S
switch (ms#.what) S
case SOCKET_CONNECTED: {
mBluetooth8onnection U (8onnection)hread) ms#.ob3<
if (Mm-erver+ode)
mBluetooth8onnection.write(Wthis is a messa#eW.#etBtes())<
break<
V
case DATA_RECEIVED: {
data U (-trin#) ms#.ob3<
tv.set)e.t(data)<
if (m-erver+ode)
mBluetooth8onnection.write(data.#etBtes())<
V
T