SlideShare a Scribd company logo
1 of 51
Introduction to Bluetooth
Low Energy (BLE)
with
By: Yeo Kheng Meng (yeokm1@gmail.com)
https://github.com/yeokm1/intro-to-ble
SP Digital Tech Talk (8 June 2017)
iOS Dev Scout (23 June 2016)
Tech Talk Tuesdays @OMG (16 Feb 2016)
Friday Hacks #98 @NUS Hackers (2 Oct 2015)
Hackware v0.8 (9 June 2015)
Hackware v0.7 (13 May 2015)
Hackers and Painters (10 April 2015)
1
Demo
2
About Me
• Graduated from NUS Computer Science in 2015
• Worked in 2 BLE-related startups before
3
Where I started from?
• Innova Technology
• Anti-loss BLE tags with
companion phone app
• “Protags”
• Android Dev
• 2013 – 2014
• Era before Android
officially supported BLE
• Fragmentation like you
have never seen
4
Before SP?
• Algoaccess
• Med-tech startup: targeting at eye-professionals
• Help them to retrieve, manage and process the data
• Roles: many….
• 2014 - 2016
5
6
How things work?
OD, OS, CYL…
OD, OS, CYL…
Intro: Bluetooth Classic
• The “conventional” Bluetooth
• 2.4GHz
• Range: 1m - 100m (10m typical)
• Connection-oriented: audio, file transfer, networking
• Reasonably fast data rate: 2.1 Mbps
• Power consumption:
• Not satisfied with < Wifi < 3G
7
Intro: BLE
• Introduced in Bluetooth 4.0 specification (2010)
• Also known as
• Bluetooth SMART
• Single-Mode
• Dual-Mode = Classic + Single-Mode
• Target applications
• Wireless battery-powered sensors eg. heart rate, thermometer, fitness
• Location tracking and information serving eg. iBeacons
• Requirements for target applications
• Low-power
• Low-cost
• Low bandwidth: ~100 kbps
• Low latency: Connectionless (fast setup and teardown of connection in ~10ms)
• How?
• Radio chip off most of the time
• Small packets
• MTU: 20 bytes/packet for application
• Less time transmitting -> less heat -> no need compensatory circuits -> save more power
8
Bluetooth Classic vs SMART
• An actual battery-life comparison
• Innova’s anti-loss products
vs
Protag G1 (Classic)
Released: 2012
Battery Capacity: 3.7V, 270mAh
Battery Life: 1 - 2 weeks
Protag Elite (SMART)
Released: 2013
Battery Capacity: 3.7V, 150mAh
Battery Life: 6 months to 1 year9
Wireless constraint triangle
10
Power usage ↓
Range↑Speed↑
*Positions are for relative comparison only, they are not absolute
Other factors not mentioned
1. Cost
• Royalties
• Manufacturing
2. Adoption rate
3. Topology support
• Mesh
• Star
802.11 n/ac
5Ghz
802.11 b/g/n
2.4Ghz
BLE
RFID/NFC
3G/4G
BT Classic
Zigbee
SSN/Lora
What’s on the agenda?
1) BLE theoretical concepts*
a. Device Role 1: Broadcaster vs Observer
b. Device Role 2: Central vs Peripheral
c. OS/Device Compatibility
d. UUID, Attribute, GAP, GATT, Service, Characteristic, Descriptor
e. BLE connection procedure
2) Peripheral hardware design and software planning
a. Functional requirements
b. Hardware setup
c. Peripheral architecture plan
3) Execution
a. Arduino (C)
b. Central architecture plan (iOS and Android)
c. iOS (Swift)
d. Raspberry Pi (JavaScript)
e. Android (Java)
4) Issues and tips
a. General issues
b. iOS
c. Android (past, today, production app tips)
5) BLE layer model and packet concepts
6) BLE Sniffer
7) Further reading
8) Extra questions
* Exact definitions are not used to aid ease of explanation 11
1a. Device Role 1: Broadcaster vs Observer
Observer 1
Broadcaster 1
Advertises
12
aka Beacon-mode
One-way advertisement information transfer from broadcaster to observer(s)
Observer 2
Observer 3
Broadcaster 2
1b. Device Role 2: Central vs Peripheral
Central Peripheral
Advertises
Connects to
Platform Terms they prefer (generally mean the same thing)
iOS Central/Peripheral
Android Client/Server
Chipset manufacturers Master/Slave 13
1b. Device Role 2: Central vs Peripheral
Source: https://learn.adafruit.com/assets/13826
Central can connect to many peripherals at the same time
Peripheral can connect to only one central at any one time.
14
1c. OS/Device Compatibility
Observer/Central Broadcaster/Peripheral
1. iOS 5
2. Windows 8
3. Mac OS X 10.7 (Lion)
4. Linux kernel 3.5
• Bluez 5.0
5. Android 4.3 (Jelly Bean MR2)
• X - Nexus 7 (2012), 10*
• X - Galaxy Nexus*
6. Hardware chipsets
• CC2540
• CSR1010
• NRF51/52
1. iOS 6
2. Windows 10
3. Mac OS X 10.9 (Mavericks)
4. Linux kernel 3.5
• Bluez 5.0
5. Android 5.0 (Lollipop)
• X - Nexus 4, 5, 7 (2013)*
• ✔ - Nexus 6, 9, 5X, 6P, Pixel…
6. Hardware chipsets
• CC2540
• CSR1010
• NRF51/52
• NRF8001
*Hardware capable but not certified by Bluetooth SIG-> disabled in OS
, custom ROMs may enable these BLE features
15
1d. UUID, Attribute
• Universally Unique Identifier (UUID)
• 128-bit eg. “12345678-ABCD-EF90-1234-00805F9B34FB”
• To ensure practical uniqueness if randomised
• 2128 = 3.4 x 1038
• 16-bit for Bluetooth Special Interest Group (SIG) defined
services/characteristics/descriptors
• Combined inside Bluetooth Base UUID
• 0000xxxx-0000-1000-8000-00805F9B34FB
• Attribute
• Anything that has a UUID
• Refers to Services, Characteristics and Descriptors
16
1d. GAP, GATT
(defined by Peripheral)
• Generic Access Profile (GAP) or Advertising
• Information advertised to central before connection
• Name of peripheral
• Is it connectable?
• Supported features (services)
• Generic Attribute Profile (GATT)
• How to exchange data once connected
• Identifies Services, Characteristics and Descriptors
*Both GAP and GATT are theoretical concepts, you don’t usually see those terms in coding APIs.
17
1d. Service, characteristic, descriptor
(All these are part of a peripheral’s GATT)
• Service
• 16-bit SIG services: Battery, Heart rate, Immediate Alert, Tx Power
• 128-bit UUID for custom services
• Collection of characteristics
• Characteristic
• Holds a value: String, Int, Char…..
• Can take on multiple properties:
• Read: Central can read this value directly
• Write: Central can write/change this value and be notified if executed successfully
• WriteWithoutResponse: Central just “fire and forget”
• Notify: Central gets alerted if the value has changed
• Others: Broadcast, Indicate, SignedWrite, QueuedWrite, WritableAuxiliaries
• Collection of optional descriptors
• Descriptor: usually optional
• Holds a value
• Used to describe a characteristic (meta-data)
• Special case: Client Characteristic Configuration Descriptor (0x2902)
• Usually automatically created for characteristics with “notify” property 18
1d. Service, characteristic, descriptor
GATT
Service1 Service2
Characteristic1
Properties: Read, Notify
Characteristic1
Properties: Read, Write
Descriptor1
Characteristic2
Properties: WriteWithoutResponse
Descriptor1 Descriptor2
19
Observer Broadcaster
1e. BLE connection procedure
Central Peripheral
Broadcasts advertisement packets (GAP)
2.5. Connection attempt
Connect success
Discover services
Services data (GATT)
Discover characteristics
Characteristics data (GATT)
1. Scanning
Advertising
2. Received
advertisement packet
(Stop here for beacon devices)
Connected success,
stops advertising
3. Connect success,
now lets find out more
Send back services
info
4. Services discovered,
lets dig deeper
Send back
characteristics info
5. Discovery
completed, ready to
use peripheral
Discover descriptors (usually optional)
20
2a. Functional Requirements
• Connection Status
• Red LED to indicate no connection
• Green LED to indicate active connection with central
• Controllable via BLE
• Let central toggle blue LED
• Let central toggle yellow LED
• Button to trigger sending data back to central
21
2b. Hardware setup (Arduino)
Arduino Parts list
1. Arduino Uno R3
2. RedBearLab BLE (Single-Mode) Shield v.1.1
• (Not shown in schematic)
• NRF8001 chipset
3. Red LED
4. Green LED
5. Blue LED
6. Yellow LED
7. 4x 220ohm resistors
8. Push Button
22
2b. Hardware setup (Raspberry Pi)
Raspberry Pi Parts list
1. Raspberry Pi 3 Model B
2. IOGear GBU521 USB BLE (Dual-Mode) adapter
• BCM20702 chipset
3. Red LED
4. Green LED
5. Blue LED
6. Yellow LED
7. 4x 220ohm resistors
8. Push Button
9. 10k ohm pull-down resistor
23
2. Peripheral Architecture Plan
Service 1 (UUID : "12345678-9012-3456-7890-123456789012“)
Characteristic 1 (LED)
Value type: char (1-byte character)
UUID : “00000000-0000-0000-0000-000000000010”
Properties: Read, WriteWithoutResponse
Characteristic 2 (Button)
Value type: String
UUID : “00000000-0000-0000-0000-000000000020”
Properties: Read, Notify
LED characteristic
• Toggles blue LED if central writes “b”
• Toggles yellow LED if central writes “y”
Button characteristic
• Notifies central if button is pressed
• Sends back incrementing number
Generic Attribute Profile (GATT)
Generic Access Profile (GAP)
Field Value
Device name (general) YKM’s Arduino (Not accessible via Android APIs)
Local name (specific): Intro to Arduino BLE
isConnectable Yes
Services 1 service: UUID = "12345678-9012-3456-7890-123456789012“
24
3a. Arduino code
• Programming Language: C
• Arduino IDE 1.8.2
• Libraries Used
• ble-sdk-arduino for NRF8001 (By Nordic)
• https://github.com/NordicSemiconductor/ble-sdk-arduino
• arduino-BLEPeripheral (By Sandeepmistry)
• Abstraction over ble-sdk-arduino
• https://github.com/sandeepmistry/arduino-BLEPeripheral
25
3b. Central architecture plan
(iOS and Android)
MainActivity/ViewController
(UI)
BLEHandler
(Deals with platform’s BLE APIs)
BLEHandlerCallback**
Interface/Delegate
Calls functions
Returns results*
*BLE APIs are asynchronous in nature.
**Use BLEHandlerCallback to avoid tight coupling between UI and BLEHandler
implements
26
3c. iOS Code
• Platform
• Device: iPod Touch 6G
• iOS 10
• Programming Language: Swift 3
• Xcode 8
27
3b. Raspberry Pi code
• Platform
• Device: Pi 3 Model B*
• OS: Raspbian
• Programming Language: Javascript
• Framework used: Nodejs
• Nodejs BLE Library
• Bleno (by Sandeepmistry again)
• Abstraction over Linux’s Bluez stack/API
• Aggressive maintenance
• https://github.com/sandeepmistry/bleno
• Why not others, Python, Go or C?
• Bleno is more “mature” and “easier to use”
*Others will work too 28
3c. Android code
• Platform
• Device: Nexus 5
• Android 6 (maximum)
• Programming Language: Java
• Android Studio 2.3
29
4a. General Issues
• Limit data transfer to 20-byte chunks
• Peripheral
• Characteristics support UTF-8 values
• I use ASCII for Arduino compatibility, but UTF-8 is generally safe
• Central
• Must rescan upon Bluetooth/phone restart
• Existing CBPeripheral (iOS) and BluetoothDevice (Android)
references becomes invalid
• iOS/Android simulator cannot be used
30
4b. iOS issues
• Cannot retrieve Mac Address (without private APIs)
• Generated UUID specific to iOS device
• Identification issues across iOS devices /Android
• Solution: Peripheral embeds Mac Address in advertisement (GAP) data
• Manufacturer data field (Innova Technology)
• In device/local name fields (Algo Access/SP)
• Aggressive caching of GATT data
• Receive out-of-date GATT data during peripheral development
• Solution:
• Restart iOS’s Bluetooth after every change in peripheral software/firmware
• Max number of BLE connections
• ~20 (online anecdotes)
• Max theoretical speed = 2.67KiB/s
• 20 bytes MTU, 4 packets/connection interval, 30ms interval
• (20 bytes * 4 ) / 30ms = 2.67KiB/s
• Max theoretical speed for HID Devices = 7.1KiB/s
• 20 bytes MTU, 4 packets/connection interval, 11.25ms interval
• (20 bytes * 4 ) / 11.25ms = 7.1KiB/s
31
4c. Android issues (the past)
• Before Android 4.3 (July 2013)
• Fragmentation hell
• Proprietary Libraries by OEMs, Android <= 4.2
• Samsung (quite reliable)
• HTC – buggy, unreliable
• Motorola (reliable but conflicts with Android 4.3)
• Architecture issues
• Testing issues
32
4c. Android issues (today)
1. OS fragmentation
33
• 90.4% of Android devices support BLE
• Peripheral mode: 70.2% minus Nexus 4, 5, 7 (2012/2013)
• OS < 5.0 not considered reliable
4c. Android issues (today)
2. Max theoretical speed = 16KiB/s
• Nexus 4/6P
• 20 bytes MTU, 6 packets/connection interval, 7.5ms interval
• (20 bytes * 6 ) / 7.5ms = 16KiB/s
• Might be different for other phones
34
4c. Android issues (today)
3. All callbacks from BLE APIs are not on UI thread.
4. APIs considered new, some functions are buggy
5. Frequent connection drops (< 5.0)
6. Max BLE connections:
• Software cap in Bluedroid code: BTA_GATTC_CONN_MAX, GATT_MAX_PHY_CHANNEL
• Android 4.3: 4
• 4.4 - 5.0+: 7
7. No API callback to indicate scanning has stopped
• Scan supposed to be indefinite by API specification, but some phones stop scan after some time
• Known offender: Samsung???
• Solution: Restart scan at regular intervals
8. Different scan return result behaviours (See further reading)
• Some phones filter advertisement results, some phones do not. (usually on 4.3 and 4.4)
9. Bugs on (Samsung) phones at least < 5.0
• Scan using service UUID filtering does not work -> no results returned
• connectGatt() must be called from UI thread
10. Slow LE initial discovery and connection time
• HTC seems to have this issue???
9. A high-level view on issues collated by Anaren
• https://atmosphere.anaren.com/wiki/Android_Issues_With_Bluetooth_Low_Energy
10. A more comprehensive list of issues has been collated by iDevicesInc
• https://github.com/iDevicesInc/SweetBlue/wiki/Android-BLE-Issues
• May be able to overcome using: https://github.com/iDevicesInc/SweetBlue
• Free for non-commercial use 35
4c. Tips for production Android app
• Use Nexus/Pixel (reference phone) for initial development
• Get many models from differing manufacturers
36
5. BLE layer model
• Link-layer:
• Defines how two BLE devices communicate. Advertising, Scanning,
Connecting, Packet Format
• Convention is to use Master/Slave instead of Central/Peripheral
• L2CAP:
• Segmentation and reassembly of packets
• 4-byte header
• 23 bytes for MTU
• Protocol multiplexing
• 0x0004: ATT Channel (usually used)
• 0x0005: LE signalling
• 0x0006: Security Manager
• ATT
• Action to be taken (Read/Write/…)
• 1-byte instruction opcode
• 2-byte handle (ID of relevant service/characteristic/descriptor)
• 20-byte MTU for application
37
(L2CAP)
Source: https://developer.bluetooth.org/KnowledgeCenter/PublishingImages/GATT_stack.png
(ATT)
(Master/Slave)
(GAP)
(GATT)
5. BLE Data Link-layer Packet Structure
Field size (bits) 8 32 8 8 0-296 24
Field name Preamble
(Alternating
bits for receiver
calibration)
Advertising
/Data
Access Address
Header Length Payload CRC
38
• Only 1 packet structure
• Two types of packets
• Advertising
• Advertising Access Address: Always 0x8E89BED6
• Data
• Data Access Address: Random for every connection
• Allows Master/Slave to distinguish packets associated with a connection
• Mac Address no longer used for data packets
• Usually carries L2CAP/ATT payload
• PDU header format for Advertising != Data
Protocol/Packet Data Unit (PDU)
LSB
6. BLE Sniffer
• Adafruit Bluefruit LE Sniffer
• Based on Nordic nRF51822
• Required software:
• Nordic nRF Sniffer (Windows-only)
• Results piped to Wireshark
• Alternative: Ubertooth One
39
6. Sniffer: Advertising
• ADV packets’ payload contains GAP data:
• Mac Address
• Service UUID
• Supported Bluetooth features: Dual/Single mode
• TX Power (Optional)
• Name (Optional)
• PDU/Advertising Type:
• 4-bit field determines type of ADV Packet
• Slave is connectable
• 0000: ADV_IND (Undirected connectable mode)
• No need to connect in a hurry
• 0001: ADV_DIRECT_IND (Directed connectable mode)
• To indicate to master that slave wants to be connected quickly.
• Max 1.28s in this mode
• Slave is not connectable
• 0010: ADV_NONCONN_IND (Not scannable)
• Will not respond to scan (SCAN_REQ) requests for more info
• 0110: ADV_SCAN_IND
• Will response to SCAN_REQ with SCAN_RSP
40
Source: BLE: The Developer’s Handbook by Robin Heydon, pg82
Link layer format
0x8E89BED6
6. Sniffer: Scan
• ADV Packets may not hold all advertising info
• Central can issue SCAN_REQ to ask for more
• 0011: SCAN_REQ (Active Scan Request)
• Master -> Slave
• Ask peripheral for complete GAP data
• 0100: SCAN_RSP (Response)
• Slave -> Master
• Contains slave’s name, TX power, …
41
6. Sniffer: Connection
• PDU Type:
• 0101: Connect_REQ (Connect Request)
• Master -> Slave
• Master selects and sends a random data access address
• Link-layer data -> Access address field
• 0110: Empty PDU (Keep-alive packet)
• Sent at connection interval between Master <-> Slave
• Filter "not btle.data_header.llid==0001” to ignore in
Wireshark
42
6. Sniffer: Data Packets
• Payload usually contains L2CAP/ATT data
• Link-layer identifier (LLID) – 2 bits
• 11 : Control Packet
• 10 : Start/Full Packet
• 01: Continuation of fragmented packet
• If LLID == 11 (Control Packet)
• Header format changes to have control and error fields
• Does not contain L2CAP/ATT payload data
• 0x0c: LL_VERSION_IND: Negotiate supported Bluetooth Spec
• 0x01: LL_CHANNEL_MAP_REQ: Channel hop (Master -> Slave)
• 0x02: LL_TERMINATE_IND: Terminate connection
43
Source: BLE: The Developer’s Handbook by Robin Heydon, pg83
Link layer format
6. Sniffer: Discover services/characteristics
• ATT opcodes
• 0x10: Read by Group Type Request (Discover Services)
• Master -> Slave
• 0x11: Read by Group Type Response
• Slave -> Master
• Returns Services Requested
• 0x08: Read by Type Request (Discover Characteristics)
• Master -> Slave
• 0x09: Read by Type Response
• Slave -> Master
• Returns Characteristics Requested
44
You may notice some “hidden” services during sniffing
• Generic Access Service: 0x1800 (Contains generic info, name, type etc about peripheral)
• Generic Attribute Service: 0x1801 (I don’t know what this is)
6. Sniffer: Data transfer
• 0x52: Write Command (Write to Characteristic)
• Master -> Slave
• 0x1b: Handle Value Notification (Notify Characteristic Changed)
• Slave -> Master
45
7. Further reading
• BLE 4.0-4.1 Security (Passive) Weaknesses (19:58 to 23:14)
• Video: https://www.usenix.org/conference/woot13/workshop-program/presentation/ryan
• Paper: https://lacklustre.net/bluetooth/Ryan_Bluetooth_Low_Energy_USENIX_WOOT.pdf
• In-depth introduction by Nordic Semiconductor
• https://www.youtube.com/watch?v=BZwOrQ6zkzE
• Acceptable types of Characteristic values
• https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
• BLE Sniffer (by Adafruit)
• https://learn.adafruit.com/introducing-the-adafruit-bluefruit-le-sniffer
• Android 4.3 BLE unstable
• http://stackoverflow.com/questions/17870189/android-4-3-bluetooth-low-energy-unstable
• Android different scan results behaviour
• http://stackoverflow.com/questions/19502853/android-4-3-ble-filtering-behaviour-of-startlescan
• Android 5.0 BLE APIs improvement vs 4.3
• https://www.youtube.com/watch?v=qx55Sa8UZAQ
• High-level Android Issues collated by Anaren
• https://atmosphere.anaren.com/wiki/Android_Issues_With_Bluetooth_Low_Energy
• Lower-level Android issues collated by iDevicesInc
• https://github.com/iDevicesInc/SweetBlue/wiki/Android-BLE-Issues
• BLE Advertising Packet Format
• http://j2abro.blogspot.sg/2014/06/understanding-bluetooth-advertising.html
• Bluetooth Core (Adopted) Specification
• https://www.bluetooth.org/en-us/specification/adopted-specifications
• Raspberry Pi 3 UART/Bluetooth issues
• http://yeokhengmeng.com/2016/03/raspberry-pi-3-uartbluetooth-issues/
46
Questions?
47
By: Yeo Kheng Meng (yeokm1@gmail.com)
https://github.com/yeokm1/intro-to-ble
8a. Can Peripheral prevent unwanted
connections from unknown Central?
• Not possible to block connection attempt
• But peripheral can disconnect the central after connected
• Wait for key-exchange
• Mac address whitelist
• Disconnect APIs
• arduino-BLEPeripheral
• blePeripheral.disconnect();
• Bleno
• bleno.disconnect();
48
8b. Who defines the attributes?
• Peripheral always defines the attributes
• Services, characteristics and descriptors
• Then why did I do this on the Central?
• Android:
• iOS:
• Reason:
• I hardcoded the characteristic UUIDs to address the
characteristics directly since I already know their purpose
49
8c. BLE Security?
• Bluetooth pairing
• < Bluetooth 4.2:
• Strongly discouraged to use native BLE security features Key-
exchange protocol weakness
• See video in Further Reading
• Security issues fixed in 4.2 (Dec 2014)
• But many devices/SDK in the market have not adopted this
50
8d. Data loss from using
writeWithoutResponse instead of
write property?
• Possibility exists but unlikely to happen in practice
• Rough Analogy:
• write vs writeWithoutResponse -> TCP vs UDP
• Possible to lose data if central sends faster than
peripheral can process
51

More Related Content

What's hot

Introduction to Bluetooth technology
Introduction to Bluetooth technologyIntroduction to Bluetooth technology
Introduction to Bluetooth technology
David Livingston J
 
Bluetooth low energy(ble) wireless technology
Bluetooth low energy(ble) wireless technologyBluetooth low energy(ble) wireless technology
Bluetooth low energy(ble) wireless technology
Lin Steven
 

What's hot (20)

Bluetooth Low Energy - A Case Study
Bluetooth Low Energy - A Case StudyBluetooth Low Energy - A Case Study
Bluetooth Low Energy - A Case Study
 
Developing for the Connected Car
Developing for the Connected CarDeveloping for the Connected Car
Developing for the Connected Car
 
Introduction to Bluetooth technology
Introduction to Bluetooth technologyIntroduction to Bluetooth technology
Introduction to Bluetooth technology
 
Ultra wide band technology
Ultra wide band technology Ultra wide band technology
Ultra wide band technology
 
Bluetooth low energy(ble) wireless technology
Bluetooth low energy(ble) wireless technologyBluetooth low energy(ble) wireless technology
Bluetooth low energy(ble) wireless technology
 
ULTRA WIDE BAND TECHNOLOGY
ULTRA WIDE BAND TECHNOLOGYULTRA WIDE BAND TECHNOLOGY
ULTRA WIDE BAND TECHNOLOGY
 
Bluetooth technology
Bluetooth technologyBluetooth technology
Bluetooth technology
 
Bluetooth
BluetoothBluetooth
Bluetooth
 
Bluetooth
BluetoothBluetooth
Bluetooth
 
Bluetooth security
Bluetooth securityBluetooth security
Bluetooth security
 
The Bluetooth technology
The Bluetooth technologyThe Bluetooth technology
The Bluetooth technology
 
Wireless sensor network
Wireless sensor networkWireless sensor network
Wireless sensor network
 
6lowpan
6lowpan6lowpan
6lowpan
 
Everything You Need to Know Abut Bluetooth Mesh for Industrial IoT
Everything You Need to Know Abut Bluetooth Mesh for Industrial IoTEverything You Need to Know Abut Bluetooth Mesh for Industrial IoT
Everything You Need to Know Abut Bluetooth Mesh for Industrial IoT
 
Blue1
Blue1Blue1
Blue1
 
BLUETOOTH SECURITY
BLUETOOTH SECURITYBLUETOOTH SECURITY
BLUETOOTH SECURITY
 
Ultra Wide Band (UWB)
Ultra Wide Band (UWB)Ultra Wide Band (UWB)
Ultra Wide Band (UWB)
 
An Introduction to BLUETOOTH TECHNOLOGY
An Introduction to BLUETOOTH TECHNOLOGYAn Introduction to BLUETOOTH TECHNOLOGY
An Introduction to BLUETOOTH TECHNOLOGY
 
How to dimension user traffic in LTE
How to dimension user traffic in LTEHow to dimension user traffic in LTE
How to dimension user traffic in LTE
 
Wireless pan technologies ieee 802.15.x
Wireless pan technologies ieee 802.15.xWireless pan technologies ieee 802.15.x
Wireless pan technologies ieee 802.15.x
 

Similar to Introduction to Bluetooth Low Energy

Similar to Introduction to Bluetooth Low Energy (20)

Android Things in action
Android Things in actionAndroid Things in action
Android Things in action
 
Intels presentation at blue line industrial computer seminar
Intels presentation at blue line industrial computer seminarIntels presentation at blue line industrial computer seminar
Intels presentation at blue line industrial computer seminar
 
Presentation for IoT workshop at Sinhagad University (Feb 4, 2016) - 2/2
Presentation for IoT workshop at Sinhagad University (Feb 4, 2016) - 2/2Presentation for IoT workshop at Sinhagad University (Feb 4, 2016) - 2/2
Presentation for IoT workshop at Sinhagad University (Feb 4, 2016) - 2/2
 
Bluetooth technology introduction and ecosystem
Bluetooth technology introduction and ecosystem Bluetooth technology introduction and ecosystem
Bluetooth technology introduction and ecosystem
 
Da Arduino ad Android_ illumina il Natale con il BLE
Da Arduino ad Android_ illumina il Natale con il BLEDa Arduino ad Android_ illumina il Natale con il BLE
Da Arduino ad Android_ illumina il Natale con il BLE
 
Bsides Puerto Rico-2017
Bsides Puerto Rico-2017Bsides Puerto Rico-2017
Bsides Puerto Rico-2017
 
Virtual Twins: Modeling Trends and Challenges Ahead
Virtual Twins: Modeling Trends and Challenges AheadVirtual Twins: Modeling Trends and Challenges Ahead
Virtual Twins: Modeling Trends and Challenges Ahead
 
Albin profile
Albin profileAlbin profile
Albin profile
 
Industrial IoT with Azure and Open Source
Industrial IoT with Azure and Open SourceIndustrial IoT with Azure and Open Source
Industrial IoT with Azure and Open Source
 
Presentation_BTBox_2012
Presentation_BTBox_2012Presentation_BTBox_2012
Presentation_BTBox_2012
 
TULIPP overview
TULIPP overviewTULIPP overview
TULIPP overview
 
Track 2 session 3 - st dev con 2016 - simplifying cloud connectivity
Track 2   session 3 - st dev con 2016 - simplifying cloud connectivityTrack 2   session 3 - st dev con 2016 - simplifying cloud connectivity
Track 2 session 3 - st dev con 2016 - simplifying cloud connectivity
 
IT Solution through IoT Development
IT Solution through IoT DevelopmentIT Solution through IoT Development
IT Solution through IoT Development
 
TestowanieIoT2016
TestowanieIoT2016TestowanieIoT2016
TestowanieIoT2016
 
BLE Talk
BLE TalkBLE Talk
BLE Talk
 
Practical introduction to IoT
Practical introduction to IoTPractical introduction to IoT
Practical introduction to IoT
 
The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017The Considerations for Internet of Things @ 2017
The Considerations for Internet of Things @ 2017
 
Embedded. What Why How
Embedded. What Why HowEmbedded. What Why How
Embedded. What Why How
 
Pre meetup intel® roadshow london
Pre meetup intel® roadshow londonPre meetup intel® roadshow london
Pre meetup intel® roadshow london
 
2015 01 24 Coding4Fun at Tajamar
2015 01 24 Coding4Fun at Tajamar2015 01 24 Coding4Fun at Tajamar
2015 01 24 Coding4Fun at Tajamar
 

More from yeokm1

More from yeokm1 (20)

I became a Private Pilot and this is my story
I became a Private Pilot and this is my storyI became a Private Pilot and this is my story
I became a Private Pilot and this is my story
 
What's inside a Cessna 172 and flying a light plane
What's inside a Cessna 172 and flying a light planeWhat's inside a Cessna 172 and flying a light plane
What's inside a Cessna 172 and flying a light plane
 
Speaking at Tech meetups/conferences for Junior Devs
Speaking at Tech meetups/conferences for Junior DevsSpeaking at Tech meetups/conferences for Junior Devs
Speaking at Tech meetups/conferences for Junior Devs
 
Reflections on Trusting Trust for Go
Reflections on Trusting Trust for GoReflections on Trusting Trust for Go
Reflections on Trusting Trust for Go
 
Meltdown and Spectre
Meltdown and SpectreMeltdown and Spectre
Meltdown and Spectre
 
Gentoo on a 486
Gentoo on a 486Gentoo on a 486
Gentoo on a 486
 
BLE Localiser (Full) for iOS Dev Scout
BLE Localiser (Full) for iOS Dev ScoutBLE Localiser (Full) for iOS Dev Scout
BLE Localiser (Full) for iOS Dev Scout
 
BLE Localiser for iOS Conf SG 2017
BLE Localiser for iOS Conf SG 2017BLE Localiser for iOS Conf SG 2017
BLE Localiser for iOS Conf SG 2017
 
Repair Kopitiam Specialty Tools (Part 2): Short Circuit Limiter
 Repair Kopitiam Specialty Tools (Part 2): Short Circuit Limiter Repair Kopitiam Specialty Tools (Part 2): Short Circuit Limiter
Repair Kopitiam Specialty Tools (Part 2): Short Circuit Limiter
 
PCB Business Card (Singapore Power)
PCB Business Card (Singapore Power)PCB Business Card (Singapore Power)
PCB Business Card (Singapore Power)
 
SP Auto Door Unlocker
SP Auto Door UnlockerSP Auto Door Unlocker
SP Auto Door Unlocker
 
SP IoT Doorbell
SP IoT DoorbellSP IoT Doorbell
SP IoT Doorbell
 
Distance Machine Locker
Distance Machine LockerDistance Machine Locker
Distance Machine Locker
 
A Science Project: Building a sound card based on the Covox Speech Thing
A Science Project: Building a sound card based on the Covox Speech ThingA Science Project: Building a sound card based on the Covox Speech Thing
A Science Project: Building a sound card based on the Covox Speech Thing
 
A Science Project: Swift Serial Chat
A Science Project: Swift Serial ChatA Science Project: Swift Serial Chat
A Science Project: Swift Serial Chat
 
The slide rule
The slide ruleThe slide rule
The slide rule
 
Windows 3.1 (WFW) on vintage and modern hardware
Windows 3.1 (WFW) on vintage and modern hardwareWindows 3.1 (WFW) on vintage and modern hardware
Windows 3.1 (WFW) on vintage and modern hardware
 
Repair Kopitiam Circuit Breaker Training
Repair Kopitiam Circuit Breaker TrainingRepair Kopitiam Circuit Breaker Training
Repair Kopitiam Circuit Breaker Training
 
A2: Analog Malicious Hardware
A2: Analog Malicious HardwareA2: Analog Malicious Hardware
A2: Analog Malicious Hardware
 
Getting Started with Raspberry Pi
Getting Started with Raspberry PiGetting Started with Raspberry Pi
Getting Started with Raspberry Pi
 

Recently uploaded

怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
ehyxf
 
CRISIS COMMUNICATION presentation=-Rishabh(11195)-group ppt (4).pptx
CRISIS COMMUNICATION presentation=-Rishabh(11195)-group ppt (4).pptxCRISIS COMMUNICATION presentation=-Rishabh(11195)-group ppt (4).pptx
CRISIS COMMUNICATION presentation=-Rishabh(11195)-group ppt (4).pptx
Rishabh332761
 
在线制作(UQ毕业证书)昆士兰大学毕业证成绩单原版一比一
在线制作(UQ毕业证书)昆士兰大学毕业证成绩单原版一比一在线制作(UQ毕业证书)昆士兰大学毕业证成绩单原版一比一
在线制作(UQ毕业证书)昆士兰大学毕业证成绩单原版一比一
uodye
 
Top profile Call Girls In Palghar [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Palghar [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Palghar [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Palghar [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 
一比一定(购)国立南方理工学院毕业证(Southern毕业证)成绩单学位证
一比一定(购)国立南方理工学院毕业证(Southern毕业证)成绩单学位证一比一定(购)国立南方理工学院毕业证(Southern毕业证)成绩单学位证
一比一定(购)国立南方理工学院毕业证(Southern毕业证)成绩单学位证
wpkuukw
 
一比一原版(USYD毕业证书)澳洲悉尼大学毕业证如何办理
一比一原版(USYD毕业证书)澳洲悉尼大学毕业证如何办理一比一原版(USYD毕业证书)澳洲悉尼大学毕业证如何办理
一比一原版(USYD毕业证书)澳洲悉尼大学毕业证如何办理
uodye
 
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
uodye
 
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
wpkuukw
 
Abortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Jeddah |+966572737505 | Get CytotecAbortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
ehyxf
 
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
tufbav
 
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
oopacde
 
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
drmarathore
 
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
tufbav
 
在线制作(ANU毕业证书)澳大利亚国立大学毕业证成绩单原版一比一
在线制作(ANU毕业证书)澳大利亚国立大学毕业证成绩单原版一比一在线制作(ANU毕业证书)澳大利亚国立大学毕业证成绩单原版一比一
在线制作(ANU毕业证书)澳大利亚国立大学毕业证成绩单原版一比一
ougvy
 

Recently uploaded (20)

怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
 
CRISIS COMMUNICATION presentation=-Rishabh(11195)-group ppt (4).pptx
CRISIS COMMUNICATION presentation=-Rishabh(11195)-group ppt (4).pptxCRISIS COMMUNICATION presentation=-Rishabh(11195)-group ppt (4).pptx
CRISIS COMMUNICATION presentation=-Rishabh(11195)-group ppt (4).pptx
 
在线制作(UQ毕业证书)昆士兰大学毕业证成绩单原版一比一
在线制作(UQ毕业证书)昆士兰大学毕业证成绩单原版一比一在线制作(UQ毕业证书)昆士兰大学毕业证成绩单原版一比一
在线制作(UQ毕业证书)昆士兰大学毕业证成绩单原版一比一
 
LANDSLIDE MONITORING AND ALERT SYSTEM FINAL YEAR PROJECT BROCHURE
LANDSLIDE MONITORING AND ALERT SYSTEM FINAL YEAR PROJECT BROCHURELANDSLIDE MONITORING AND ALERT SYSTEM FINAL YEAR PROJECT BROCHURE
LANDSLIDE MONITORING AND ALERT SYSTEM FINAL YEAR PROJECT BROCHURE
 
Top profile Call Girls In Palghar [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Palghar [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Palghar [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Palghar [ 7014168258 ] Call Me For Genuine Models W...
 
一比一定(购)国立南方理工学院毕业证(Southern毕业证)成绩单学位证
一比一定(购)国立南方理工学院毕业证(Southern毕业证)成绩单学位证一比一定(购)国立南方理工学院毕业证(Southern毕业证)成绩单学位证
一比一定(购)国立南方理工学院毕业证(Southern毕业证)成绩单学位证
 
一比一原版(USYD毕业证书)澳洲悉尼大学毕业证如何办理
一比一原版(USYD毕业证书)澳洲悉尼大学毕业证如何办理一比一原版(USYD毕业证书)澳洲悉尼大学毕业证如何办理
一比一原版(USYD毕业证书)澳洲悉尼大学毕业证如何办理
 
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
 
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
 
Hilti's Latest Battery - Hire Depot.pptx
Hilti's Latest Battery - Hire Depot.pptxHilti's Latest Battery - Hire Depot.pptx
Hilti's Latest Battery - Hire Depot.pptx
 
Abortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Jeddah |+966572737505 | Get CytotecAbortion pills in Jeddah |+966572737505 | Get Cytotec
Abortion pills in Jeddah |+966572737505 | Get Cytotec
 
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
 
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
 
Point of Care Testing in clinical laboratory
Point of Care Testing in clinical laboratoryPoint of Care Testing in clinical laboratory
Point of Care Testing in clinical laboratory
 
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
 
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
 
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
 
Guwahati Escorts Service Girl ^ 9332606886, WhatsApp Anytime Guwahati
Guwahati Escorts Service Girl ^ 9332606886, WhatsApp Anytime GuwahatiGuwahati Escorts Service Girl ^ 9332606886, WhatsApp Anytime Guwahati
Guwahati Escorts Service Girl ^ 9332606886, WhatsApp Anytime Guwahati
 
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
 
在线制作(ANU毕业证书)澳大利亚国立大学毕业证成绩单原版一比一
在线制作(ANU毕业证书)澳大利亚国立大学毕业证成绩单原版一比一在线制作(ANU毕业证书)澳大利亚国立大学毕业证成绩单原版一比一
在线制作(ANU毕业证书)澳大利亚国立大学毕业证成绩单原版一比一
 

Introduction to Bluetooth Low Energy

  • 1. Introduction to Bluetooth Low Energy (BLE) with By: Yeo Kheng Meng (yeokm1@gmail.com) https://github.com/yeokm1/intro-to-ble SP Digital Tech Talk (8 June 2017) iOS Dev Scout (23 June 2016) Tech Talk Tuesdays @OMG (16 Feb 2016) Friday Hacks #98 @NUS Hackers (2 Oct 2015) Hackware v0.8 (9 June 2015) Hackware v0.7 (13 May 2015) Hackers and Painters (10 April 2015) 1
  • 3. About Me • Graduated from NUS Computer Science in 2015 • Worked in 2 BLE-related startups before 3
  • 4. Where I started from? • Innova Technology • Anti-loss BLE tags with companion phone app • “Protags” • Android Dev • 2013 – 2014 • Era before Android officially supported BLE • Fragmentation like you have never seen 4
  • 5. Before SP? • Algoaccess • Med-tech startup: targeting at eye-professionals • Help them to retrieve, manage and process the data • Roles: many…. • 2014 - 2016 5
  • 6. 6 How things work? OD, OS, CYL… OD, OS, CYL…
  • 7. Intro: Bluetooth Classic • The “conventional” Bluetooth • 2.4GHz • Range: 1m - 100m (10m typical) • Connection-oriented: audio, file transfer, networking • Reasonably fast data rate: 2.1 Mbps • Power consumption: • Not satisfied with < Wifi < 3G 7
  • 8. Intro: BLE • Introduced in Bluetooth 4.0 specification (2010) • Also known as • Bluetooth SMART • Single-Mode • Dual-Mode = Classic + Single-Mode • Target applications • Wireless battery-powered sensors eg. heart rate, thermometer, fitness • Location tracking and information serving eg. iBeacons • Requirements for target applications • Low-power • Low-cost • Low bandwidth: ~100 kbps • Low latency: Connectionless (fast setup and teardown of connection in ~10ms) • How? • Radio chip off most of the time • Small packets • MTU: 20 bytes/packet for application • Less time transmitting -> less heat -> no need compensatory circuits -> save more power 8
  • 9. Bluetooth Classic vs SMART • An actual battery-life comparison • Innova’s anti-loss products vs Protag G1 (Classic) Released: 2012 Battery Capacity: 3.7V, 270mAh Battery Life: 1 - 2 weeks Protag Elite (SMART) Released: 2013 Battery Capacity: 3.7V, 150mAh Battery Life: 6 months to 1 year9
  • 10. Wireless constraint triangle 10 Power usage ↓ Range↑Speed↑ *Positions are for relative comparison only, they are not absolute Other factors not mentioned 1. Cost • Royalties • Manufacturing 2. Adoption rate 3. Topology support • Mesh • Star 802.11 n/ac 5Ghz 802.11 b/g/n 2.4Ghz BLE RFID/NFC 3G/4G BT Classic Zigbee SSN/Lora
  • 11. What’s on the agenda? 1) BLE theoretical concepts* a. Device Role 1: Broadcaster vs Observer b. Device Role 2: Central vs Peripheral c. OS/Device Compatibility d. UUID, Attribute, GAP, GATT, Service, Characteristic, Descriptor e. BLE connection procedure 2) Peripheral hardware design and software planning a. Functional requirements b. Hardware setup c. Peripheral architecture plan 3) Execution a. Arduino (C) b. Central architecture plan (iOS and Android) c. iOS (Swift) d. Raspberry Pi (JavaScript) e. Android (Java) 4) Issues and tips a. General issues b. iOS c. Android (past, today, production app tips) 5) BLE layer model and packet concepts 6) BLE Sniffer 7) Further reading 8) Extra questions * Exact definitions are not used to aid ease of explanation 11
  • 12. 1a. Device Role 1: Broadcaster vs Observer Observer 1 Broadcaster 1 Advertises 12 aka Beacon-mode One-way advertisement information transfer from broadcaster to observer(s) Observer 2 Observer 3 Broadcaster 2
  • 13. 1b. Device Role 2: Central vs Peripheral Central Peripheral Advertises Connects to Platform Terms they prefer (generally mean the same thing) iOS Central/Peripheral Android Client/Server Chipset manufacturers Master/Slave 13
  • 14. 1b. Device Role 2: Central vs Peripheral Source: https://learn.adafruit.com/assets/13826 Central can connect to many peripherals at the same time Peripheral can connect to only one central at any one time. 14
  • 15. 1c. OS/Device Compatibility Observer/Central Broadcaster/Peripheral 1. iOS 5 2. Windows 8 3. Mac OS X 10.7 (Lion) 4. Linux kernel 3.5 • Bluez 5.0 5. Android 4.3 (Jelly Bean MR2) • X - Nexus 7 (2012), 10* • X - Galaxy Nexus* 6. Hardware chipsets • CC2540 • CSR1010 • NRF51/52 1. iOS 6 2. Windows 10 3. Mac OS X 10.9 (Mavericks) 4. Linux kernel 3.5 • Bluez 5.0 5. Android 5.0 (Lollipop) • X - Nexus 4, 5, 7 (2013)* • ✔ - Nexus 6, 9, 5X, 6P, Pixel… 6. Hardware chipsets • CC2540 • CSR1010 • NRF51/52 • NRF8001 *Hardware capable but not certified by Bluetooth SIG-> disabled in OS , custom ROMs may enable these BLE features 15
  • 16. 1d. UUID, Attribute • Universally Unique Identifier (UUID) • 128-bit eg. “12345678-ABCD-EF90-1234-00805F9B34FB” • To ensure practical uniqueness if randomised • 2128 = 3.4 x 1038 • 16-bit for Bluetooth Special Interest Group (SIG) defined services/characteristics/descriptors • Combined inside Bluetooth Base UUID • 0000xxxx-0000-1000-8000-00805F9B34FB • Attribute • Anything that has a UUID • Refers to Services, Characteristics and Descriptors 16
  • 17. 1d. GAP, GATT (defined by Peripheral) • Generic Access Profile (GAP) or Advertising • Information advertised to central before connection • Name of peripheral • Is it connectable? • Supported features (services) • Generic Attribute Profile (GATT) • How to exchange data once connected • Identifies Services, Characteristics and Descriptors *Both GAP and GATT are theoretical concepts, you don’t usually see those terms in coding APIs. 17
  • 18. 1d. Service, characteristic, descriptor (All these are part of a peripheral’s GATT) • Service • 16-bit SIG services: Battery, Heart rate, Immediate Alert, Tx Power • 128-bit UUID for custom services • Collection of characteristics • Characteristic • Holds a value: String, Int, Char….. • Can take on multiple properties: • Read: Central can read this value directly • Write: Central can write/change this value and be notified if executed successfully • WriteWithoutResponse: Central just “fire and forget” • Notify: Central gets alerted if the value has changed • Others: Broadcast, Indicate, SignedWrite, QueuedWrite, WritableAuxiliaries • Collection of optional descriptors • Descriptor: usually optional • Holds a value • Used to describe a characteristic (meta-data) • Special case: Client Characteristic Configuration Descriptor (0x2902) • Usually automatically created for characteristics with “notify” property 18
  • 19. 1d. Service, characteristic, descriptor GATT Service1 Service2 Characteristic1 Properties: Read, Notify Characteristic1 Properties: Read, Write Descriptor1 Characteristic2 Properties: WriteWithoutResponse Descriptor1 Descriptor2 19
  • 20. Observer Broadcaster 1e. BLE connection procedure Central Peripheral Broadcasts advertisement packets (GAP) 2.5. Connection attempt Connect success Discover services Services data (GATT) Discover characteristics Characteristics data (GATT) 1. Scanning Advertising 2. Received advertisement packet (Stop here for beacon devices) Connected success, stops advertising 3. Connect success, now lets find out more Send back services info 4. Services discovered, lets dig deeper Send back characteristics info 5. Discovery completed, ready to use peripheral Discover descriptors (usually optional) 20
  • 21. 2a. Functional Requirements • Connection Status • Red LED to indicate no connection • Green LED to indicate active connection with central • Controllable via BLE • Let central toggle blue LED • Let central toggle yellow LED • Button to trigger sending data back to central 21
  • 22. 2b. Hardware setup (Arduino) Arduino Parts list 1. Arduino Uno R3 2. RedBearLab BLE (Single-Mode) Shield v.1.1 • (Not shown in schematic) • NRF8001 chipset 3. Red LED 4. Green LED 5. Blue LED 6. Yellow LED 7. 4x 220ohm resistors 8. Push Button 22
  • 23. 2b. Hardware setup (Raspberry Pi) Raspberry Pi Parts list 1. Raspberry Pi 3 Model B 2. IOGear GBU521 USB BLE (Dual-Mode) adapter • BCM20702 chipset 3. Red LED 4. Green LED 5. Blue LED 6. Yellow LED 7. 4x 220ohm resistors 8. Push Button 9. 10k ohm pull-down resistor 23
  • 24. 2. Peripheral Architecture Plan Service 1 (UUID : "12345678-9012-3456-7890-123456789012“) Characteristic 1 (LED) Value type: char (1-byte character) UUID : “00000000-0000-0000-0000-000000000010” Properties: Read, WriteWithoutResponse Characteristic 2 (Button) Value type: String UUID : “00000000-0000-0000-0000-000000000020” Properties: Read, Notify LED characteristic • Toggles blue LED if central writes “b” • Toggles yellow LED if central writes “y” Button characteristic • Notifies central if button is pressed • Sends back incrementing number Generic Attribute Profile (GATT) Generic Access Profile (GAP) Field Value Device name (general) YKM’s Arduino (Not accessible via Android APIs) Local name (specific): Intro to Arduino BLE isConnectable Yes Services 1 service: UUID = "12345678-9012-3456-7890-123456789012“ 24
  • 25. 3a. Arduino code • Programming Language: C • Arduino IDE 1.8.2 • Libraries Used • ble-sdk-arduino for NRF8001 (By Nordic) • https://github.com/NordicSemiconductor/ble-sdk-arduino • arduino-BLEPeripheral (By Sandeepmistry) • Abstraction over ble-sdk-arduino • https://github.com/sandeepmistry/arduino-BLEPeripheral 25
  • 26. 3b. Central architecture plan (iOS and Android) MainActivity/ViewController (UI) BLEHandler (Deals with platform’s BLE APIs) BLEHandlerCallback** Interface/Delegate Calls functions Returns results* *BLE APIs are asynchronous in nature. **Use BLEHandlerCallback to avoid tight coupling between UI and BLEHandler implements 26
  • 27. 3c. iOS Code • Platform • Device: iPod Touch 6G • iOS 10 • Programming Language: Swift 3 • Xcode 8 27
  • 28. 3b. Raspberry Pi code • Platform • Device: Pi 3 Model B* • OS: Raspbian • Programming Language: Javascript • Framework used: Nodejs • Nodejs BLE Library • Bleno (by Sandeepmistry again) • Abstraction over Linux’s Bluez stack/API • Aggressive maintenance • https://github.com/sandeepmistry/bleno • Why not others, Python, Go or C? • Bleno is more “mature” and “easier to use” *Others will work too 28
  • 29. 3c. Android code • Platform • Device: Nexus 5 • Android 6 (maximum) • Programming Language: Java • Android Studio 2.3 29
  • 30. 4a. General Issues • Limit data transfer to 20-byte chunks • Peripheral • Characteristics support UTF-8 values • I use ASCII for Arduino compatibility, but UTF-8 is generally safe • Central • Must rescan upon Bluetooth/phone restart • Existing CBPeripheral (iOS) and BluetoothDevice (Android) references becomes invalid • iOS/Android simulator cannot be used 30
  • 31. 4b. iOS issues • Cannot retrieve Mac Address (without private APIs) • Generated UUID specific to iOS device • Identification issues across iOS devices /Android • Solution: Peripheral embeds Mac Address in advertisement (GAP) data • Manufacturer data field (Innova Technology) • In device/local name fields (Algo Access/SP) • Aggressive caching of GATT data • Receive out-of-date GATT data during peripheral development • Solution: • Restart iOS’s Bluetooth after every change in peripheral software/firmware • Max number of BLE connections • ~20 (online anecdotes) • Max theoretical speed = 2.67KiB/s • 20 bytes MTU, 4 packets/connection interval, 30ms interval • (20 bytes * 4 ) / 30ms = 2.67KiB/s • Max theoretical speed for HID Devices = 7.1KiB/s • 20 bytes MTU, 4 packets/connection interval, 11.25ms interval • (20 bytes * 4 ) / 11.25ms = 7.1KiB/s 31
  • 32. 4c. Android issues (the past) • Before Android 4.3 (July 2013) • Fragmentation hell • Proprietary Libraries by OEMs, Android <= 4.2 • Samsung (quite reliable) • HTC – buggy, unreliable • Motorola (reliable but conflicts with Android 4.3) • Architecture issues • Testing issues 32
  • 33. 4c. Android issues (today) 1. OS fragmentation 33 • 90.4% of Android devices support BLE • Peripheral mode: 70.2% minus Nexus 4, 5, 7 (2012/2013) • OS < 5.0 not considered reliable
  • 34. 4c. Android issues (today) 2. Max theoretical speed = 16KiB/s • Nexus 4/6P • 20 bytes MTU, 6 packets/connection interval, 7.5ms interval • (20 bytes * 6 ) / 7.5ms = 16KiB/s • Might be different for other phones 34
  • 35. 4c. Android issues (today) 3. All callbacks from BLE APIs are not on UI thread. 4. APIs considered new, some functions are buggy 5. Frequent connection drops (< 5.0) 6. Max BLE connections: • Software cap in Bluedroid code: BTA_GATTC_CONN_MAX, GATT_MAX_PHY_CHANNEL • Android 4.3: 4 • 4.4 - 5.0+: 7 7. No API callback to indicate scanning has stopped • Scan supposed to be indefinite by API specification, but some phones stop scan after some time • Known offender: Samsung??? • Solution: Restart scan at regular intervals 8. Different scan return result behaviours (See further reading) • Some phones filter advertisement results, some phones do not. (usually on 4.3 and 4.4) 9. Bugs on (Samsung) phones at least < 5.0 • Scan using service UUID filtering does not work -> no results returned • connectGatt() must be called from UI thread 10. Slow LE initial discovery and connection time • HTC seems to have this issue??? 9. A high-level view on issues collated by Anaren • https://atmosphere.anaren.com/wiki/Android_Issues_With_Bluetooth_Low_Energy 10. A more comprehensive list of issues has been collated by iDevicesInc • https://github.com/iDevicesInc/SweetBlue/wiki/Android-BLE-Issues • May be able to overcome using: https://github.com/iDevicesInc/SweetBlue • Free for non-commercial use 35
  • 36. 4c. Tips for production Android app • Use Nexus/Pixel (reference phone) for initial development • Get many models from differing manufacturers 36
  • 37. 5. BLE layer model • Link-layer: • Defines how two BLE devices communicate. Advertising, Scanning, Connecting, Packet Format • Convention is to use Master/Slave instead of Central/Peripheral • L2CAP: • Segmentation and reassembly of packets • 4-byte header • 23 bytes for MTU • Protocol multiplexing • 0x0004: ATT Channel (usually used) • 0x0005: LE signalling • 0x0006: Security Manager • ATT • Action to be taken (Read/Write/…) • 1-byte instruction opcode • 2-byte handle (ID of relevant service/characteristic/descriptor) • 20-byte MTU for application 37 (L2CAP) Source: https://developer.bluetooth.org/KnowledgeCenter/PublishingImages/GATT_stack.png (ATT) (Master/Slave) (GAP) (GATT)
  • 38. 5. BLE Data Link-layer Packet Structure Field size (bits) 8 32 8 8 0-296 24 Field name Preamble (Alternating bits for receiver calibration) Advertising /Data Access Address Header Length Payload CRC 38 • Only 1 packet structure • Two types of packets • Advertising • Advertising Access Address: Always 0x8E89BED6 • Data • Data Access Address: Random for every connection • Allows Master/Slave to distinguish packets associated with a connection • Mac Address no longer used for data packets • Usually carries L2CAP/ATT payload • PDU header format for Advertising != Data Protocol/Packet Data Unit (PDU) LSB
  • 39. 6. BLE Sniffer • Adafruit Bluefruit LE Sniffer • Based on Nordic nRF51822 • Required software: • Nordic nRF Sniffer (Windows-only) • Results piped to Wireshark • Alternative: Ubertooth One 39
  • 40. 6. Sniffer: Advertising • ADV packets’ payload contains GAP data: • Mac Address • Service UUID • Supported Bluetooth features: Dual/Single mode • TX Power (Optional) • Name (Optional) • PDU/Advertising Type: • 4-bit field determines type of ADV Packet • Slave is connectable • 0000: ADV_IND (Undirected connectable mode) • No need to connect in a hurry • 0001: ADV_DIRECT_IND (Directed connectable mode) • To indicate to master that slave wants to be connected quickly. • Max 1.28s in this mode • Slave is not connectable • 0010: ADV_NONCONN_IND (Not scannable) • Will not respond to scan (SCAN_REQ) requests for more info • 0110: ADV_SCAN_IND • Will response to SCAN_REQ with SCAN_RSP 40 Source: BLE: The Developer’s Handbook by Robin Heydon, pg82 Link layer format 0x8E89BED6
  • 41. 6. Sniffer: Scan • ADV Packets may not hold all advertising info • Central can issue SCAN_REQ to ask for more • 0011: SCAN_REQ (Active Scan Request) • Master -> Slave • Ask peripheral for complete GAP data • 0100: SCAN_RSP (Response) • Slave -> Master • Contains slave’s name, TX power, … 41
  • 42. 6. Sniffer: Connection • PDU Type: • 0101: Connect_REQ (Connect Request) • Master -> Slave • Master selects and sends a random data access address • Link-layer data -> Access address field • 0110: Empty PDU (Keep-alive packet) • Sent at connection interval between Master <-> Slave • Filter "not btle.data_header.llid==0001” to ignore in Wireshark 42
  • 43. 6. Sniffer: Data Packets • Payload usually contains L2CAP/ATT data • Link-layer identifier (LLID) – 2 bits • 11 : Control Packet • 10 : Start/Full Packet • 01: Continuation of fragmented packet • If LLID == 11 (Control Packet) • Header format changes to have control and error fields • Does not contain L2CAP/ATT payload data • 0x0c: LL_VERSION_IND: Negotiate supported Bluetooth Spec • 0x01: LL_CHANNEL_MAP_REQ: Channel hop (Master -> Slave) • 0x02: LL_TERMINATE_IND: Terminate connection 43 Source: BLE: The Developer’s Handbook by Robin Heydon, pg83 Link layer format
  • 44. 6. Sniffer: Discover services/characteristics • ATT opcodes • 0x10: Read by Group Type Request (Discover Services) • Master -> Slave • 0x11: Read by Group Type Response • Slave -> Master • Returns Services Requested • 0x08: Read by Type Request (Discover Characteristics) • Master -> Slave • 0x09: Read by Type Response • Slave -> Master • Returns Characteristics Requested 44 You may notice some “hidden” services during sniffing • Generic Access Service: 0x1800 (Contains generic info, name, type etc about peripheral) • Generic Attribute Service: 0x1801 (I don’t know what this is)
  • 45. 6. Sniffer: Data transfer • 0x52: Write Command (Write to Characteristic) • Master -> Slave • 0x1b: Handle Value Notification (Notify Characteristic Changed) • Slave -> Master 45
  • 46. 7. Further reading • BLE 4.0-4.1 Security (Passive) Weaknesses (19:58 to 23:14) • Video: https://www.usenix.org/conference/woot13/workshop-program/presentation/ryan • Paper: https://lacklustre.net/bluetooth/Ryan_Bluetooth_Low_Energy_USENIX_WOOT.pdf • In-depth introduction by Nordic Semiconductor • https://www.youtube.com/watch?v=BZwOrQ6zkzE • Acceptable types of Characteristic values • https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml • BLE Sniffer (by Adafruit) • https://learn.adafruit.com/introducing-the-adafruit-bluefruit-le-sniffer • Android 4.3 BLE unstable • http://stackoverflow.com/questions/17870189/android-4-3-bluetooth-low-energy-unstable • Android different scan results behaviour • http://stackoverflow.com/questions/19502853/android-4-3-ble-filtering-behaviour-of-startlescan • Android 5.0 BLE APIs improvement vs 4.3 • https://www.youtube.com/watch?v=qx55Sa8UZAQ • High-level Android Issues collated by Anaren • https://atmosphere.anaren.com/wiki/Android_Issues_With_Bluetooth_Low_Energy • Lower-level Android issues collated by iDevicesInc • https://github.com/iDevicesInc/SweetBlue/wiki/Android-BLE-Issues • BLE Advertising Packet Format • http://j2abro.blogspot.sg/2014/06/understanding-bluetooth-advertising.html • Bluetooth Core (Adopted) Specification • https://www.bluetooth.org/en-us/specification/adopted-specifications • Raspberry Pi 3 UART/Bluetooth issues • http://yeokhengmeng.com/2016/03/raspberry-pi-3-uartbluetooth-issues/ 46
  • 47. Questions? 47 By: Yeo Kheng Meng (yeokm1@gmail.com) https://github.com/yeokm1/intro-to-ble
  • 48. 8a. Can Peripheral prevent unwanted connections from unknown Central? • Not possible to block connection attempt • But peripheral can disconnect the central after connected • Wait for key-exchange • Mac address whitelist • Disconnect APIs • arduino-BLEPeripheral • blePeripheral.disconnect(); • Bleno • bleno.disconnect(); 48
  • 49. 8b. Who defines the attributes? • Peripheral always defines the attributes • Services, characteristics and descriptors • Then why did I do this on the Central? • Android: • iOS: • Reason: • I hardcoded the characteristic UUIDs to address the characteristics directly since I already know their purpose 49
  • 50. 8c. BLE Security? • Bluetooth pairing • < Bluetooth 4.2: • Strongly discouraged to use native BLE security features Key- exchange protocol weakness • See video in Further Reading • Security issues fixed in 4.2 (Dec 2014) • But many devices/SDK in the market have not adopted this 50
  • 51. 8d. Data loss from using writeWithoutResponse instead of write property? • Possibility exists but unlikely to happen in practice • Rough Analogy: • write vs writeWithoutResponse -> TCP vs UDP • Possible to lose data if central sends faster than peripheral can process 51