SlideShare a Scribd company logo

Introduction to Bluetooth Low Energy

Y
yeokm1

A talk I gave to Hackware v0.7, v0.8, Hackers & Painters, NUS Hackers, One Maker Group and iOS Dev Scout to introduce the audience to basic Bluetooth Low Energy concepts followed by code explanations. Part 1 of my presentation at Hackware v0.7 (Arduino and Android only) can be seen here. https://www.youtube.com/watch?v=pNnwXPatzjc Part 2 (Raspberry Pi, iOS and BLE Sniffer) can be seen here. https://www.youtube.com/watch?v=UDNkrlfW9Sg The code is available here. https://github.com/yeokm1/intro-to-ble

1 of 51
Download to read offline
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…

Recommended

Bluetooth low energy
Bluetooth low energyBluetooth low energy
Bluetooth low energySaptadeep Pal
 
Introduction to Bluetooth low energy
Introduction to Bluetooth low energyIntroduction to Bluetooth low energy
Introduction to Bluetooth low energyNEEVEE Technologies
 
Bluetooth Low Energy - A Case Study
Bluetooth Low Energy - A Case StudyBluetooth Low Energy - A Case Study
Bluetooth Low Energy - A Case StudyFReeze FRancis
 
Ble overview and_implementation
Ble overview and_implementationBle overview and_implementation
Ble overview and_implementationStanley Chang
 
Iot ble and_beacons_2015_nov28
Iot ble and_beacons_2015_nov28Iot ble and_beacons_2015_nov28
Iot ble and_beacons_2015_nov28Ravikiran HV
 
BLE GATT Database
BLE GATT DatabaseBLE GATT Database
BLE GATT Databasewinfred lu
 
Bluetooth & Bluetooth Low Energy internals
Bluetooth & Bluetooth Low Energy internalsBluetooth & Bluetooth Low Energy internals
Bluetooth & Bluetooth Low Energy internalsDavy Jacops
 

More Related Content

What's hot

Wi fi 6 (802.11ax) presentation
Wi fi 6 (802.11ax) presentationWi fi 6 (802.11ax) presentation
Wi fi 6 (802.11ax) presentationBryan Slayman
 
BTLE (Bluetooth Low Energy) and CoreBluetooth
BTLE (Bluetooth Low Energy) and CoreBluetooth BTLE (Bluetooth Low Energy) and CoreBluetooth
BTLE (Bluetooth Low Energy) and CoreBluetooth Zach Dennis
 
Bts installation & commisioning
Bts installation & commisioningBts installation & commisioning
Bts installation & commisioningAIRTEL
 
Wi-Fi Architecture
Wi-Fi ArchitectureWi-Fi Architecture
Wi-Fi ArchitectureArnab Ghosal
 
5G Network Architecture Options
5G Network Architecture Options5G Network Architecture Options
5G Network Architecture Options3G4G
 
Overview Of Gsm Cellular Network & Operations
Overview Of Gsm Cellular Network & OperationsOverview Of Gsm Cellular Network & Operations
Overview Of Gsm Cellular Network & OperationsDeepak Sharma
 
Mobile Networks Architecture and Security (2G to 5G)
Mobile Networks Architecture and Security (2G to 5G)Mobile Networks Architecture and Security (2G to 5G)
Mobile Networks Architecture and Security (2G to 5G)Hamidreza Bolhasani
 
Introduction to zigbee
Introduction to zigbeeIntroduction to zigbee
Introduction to zigbeeAmit Dixit
 
Core Network Optimization: The Control Plane, Data Plane & Beyond
Core Network Optimization: The Control Plane, Data Plane & BeyondCore Network Optimization: The Control Plane, Data Plane & Beyond
Core Network Optimization: The Control Plane, Data Plane & BeyondRadisys Corporation
 
Huawei hss9860 v900 r008c20 production description
Huawei hss9860 v900 r008c20 production descriptionHuawei hss9860 v900 r008c20 production description
Huawei hss9860 v900 r008c20 production descriptionRabih Kanaan,PMP
 
zigbee technology
zigbee technologyzigbee technology
zigbee technologyDeep Hundal
 

What's hot (20)

Wi fi 6 (802.11ax) presentation
Wi fi 6 (802.11ax) presentationWi fi 6 (802.11ax) presentation
Wi fi 6 (802.11ax) presentation
 
BTLE (Bluetooth Low Energy) and CoreBluetooth
BTLE (Bluetooth Low Energy) and CoreBluetooth BTLE (Bluetooth Low Energy) and CoreBluetooth
BTLE (Bluetooth Low Energy) and CoreBluetooth
 
Designing 5G NR (New Radio)
Designing 5G NR (New Radio)Designing 5G NR (New Radio)
Designing 5G NR (New Radio)
 
Bts installation & commisioning
Bts installation & commisioningBts installation & commisioning
Bts installation & commisioning
 
Nb iot presentation
Nb iot presentationNb iot presentation
Nb iot presentation
 
Zigbee Presentation
Zigbee PresentationZigbee Presentation
Zigbee Presentation
 
Wi-Fi Architecture
Wi-Fi ArchitectureWi-Fi Architecture
Wi-Fi Architecture
 
5g introduction_NR
5g introduction_NR5g introduction_NR
5g introduction_NR
 
5G Network Architecture Options
5G Network Architecture Options5G Network Architecture Options
5G Network Architecture Options
 
Bluetooth - Overview
Bluetooth - OverviewBluetooth - Overview
Bluetooth - Overview
 
Overview Of Gsm Cellular Network & Operations
Overview Of Gsm Cellular Network & OperationsOverview Of Gsm Cellular Network & Operations
Overview Of Gsm Cellular Network & Operations
 
Huawei ipran solution
Huawei ipran solutionHuawei ipran solution
Huawei ipran solution
 
Mobile Networks Architecture and Security (2G to 5G)
Mobile Networks Architecture and Security (2G to 5G)Mobile Networks Architecture and Security (2G to 5G)
Mobile Networks Architecture and Security (2G to 5G)
 
Introduction to zigbee
Introduction to zigbeeIntroduction to zigbee
Introduction to zigbee
 
Core Network Optimization: The Control Plane, Data Plane & Beyond
Core Network Optimization: The Control Plane, Data Plane & BeyondCore Network Optimization: The Control Plane, Data Plane & Beyond
Core Network Optimization: The Control Plane, Data Plane & Beyond
 
Huawei hss9860 v900 r008c20 production description
Huawei hss9860 v900 r008c20 production descriptionHuawei hss9860 v900 r008c20 production description
Huawei hss9860 v900 r008c20 production description
 
Zigbee
 Zigbee    Zigbee
Zigbee
 
GSM Presentation
GSM PresentationGSM Presentation
GSM Presentation
 
zigbee technology
zigbee technologyzigbee technology
zigbee technology
 
Zigbee
ZigbeeZigbee
Zigbee
 

Similar to Introduction to Bluetooth Low Energy

Android Things in action
Android Things in actionAndroid Things in action
Android Things in actionStefano Sanna
 
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 seminarBlue Line
 
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/2Bhavin Chandarana
 
Bluetooth technology introduction and ecosystem
Bluetooth technology introduction and ecosystem Bluetooth technology introduction and ecosystem
Bluetooth technology introduction and ecosystem NiclasGranqvist
 
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 BLEinfogdgmi
 
Bsides Puerto Rico-2017
Bsides Puerto Rico-2017Bsides Puerto Rico-2017
Bsides Puerto Rico-2017Price McDonald
 
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 AheadBrain IoT Project
 
Albin profile
Albin profileAlbin profile
Albin profileAlbin B
 
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 SourceIvo Andreev
 
Presentation_BTBox_2012
Presentation_BTBox_2012Presentation_BTBox_2012
Presentation_BTBox_2012valdo3333
 
TULIPP overview
TULIPP overviewTULIPP overview
TULIPP overviewTulipp. Eu
 
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 connectivityST_World
 
IT Solution through IoT Development
IT Solution through IoT DevelopmentIT Solution through IoT Development
IT Solution through IoT DevelopmentAndri Yadi
 
TestowanieIoT2016
TestowanieIoT2016TestowanieIoT2016
TestowanieIoT2016kraqa
 
Practical introduction to IoT
Practical introduction to IoTPractical introduction to IoT
Practical introduction to IoTpekkanikander
 
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 @ 2017Jian-Hong Pan
 
Pre meetup intel® roadshow london
Pre meetup intel® roadshow londonPre meetup intel® roadshow london
Pre meetup intel® roadshow londonHugo Espinosa
 
2015 01 24 Coding4Fun at Tajamar
2015 01 24 Coding4Fun at Tajamar2015 01 24 Coding4Fun at Tajamar
2015 01 24 Coding4Fun at TajamarBruno Capuano
 

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
 
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
 
Tos tutorial
Tos tutorialTos tutorial
Tos tutorial
 

More from yeokm1

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 storyyeokm1
 
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 planeyeokm1
 
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 Devsyeokm1
 
Reflections on Trusting Trust for Go
Reflections on Trusting Trust for GoReflections on Trusting Trust for Go
Reflections on Trusting Trust for Goyeokm1
 
Meltdown and Spectre
Meltdown and SpectreMeltdown and Spectre
Meltdown and Spectreyeokm1
 
Gentoo on a 486
Gentoo on a 486Gentoo on a 486
Gentoo on a 486yeokm1
 
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 Scoutyeokm1
 
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 2017yeokm1
 
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 Limiteryeokm1
 
PCB Business Card (Singapore Power)
PCB Business Card (Singapore Power)PCB Business Card (Singapore Power)
PCB Business Card (Singapore Power)yeokm1
 
SP Auto Door Unlocker
SP Auto Door UnlockerSP Auto Door Unlocker
SP Auto Door Unlockeryeokm1
 
SP IoT Doorbell
SP IoT DoorbellSP IoT Doorbell
SP IoT Doorbellyeokm1
 
Distance Machine Locker
Distance Machine LockerDistance Machine Locker
Distance Machine Lockeryeokm1
 
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 Thingyeokm1
 
A Science Project: Swift Serial Chat
A Science Project: Swift Serial ChatA Science Project: Swift Serial Chat
A Science Project: Swift Serial Chatyeokm1
 
The slide rule
The slide ruleThe slide rule
The slide ruleyeokm1
 
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 hardwareyeokm1
 
Repair Kopitiam Circuit Breaker Training
Repair Kopitiam Circuit Breaker TrainingRepair Kopitiam Circuit Breaker Training
Repair Kopitiam Circuit Breaker Trainingyeokm1
 
A2: Analog Malicious Hardware
A2: Analog Malicious HardwareA2: Analog Malicious Hardware
A2: Analog Malicious Hardwareyeokm1
 
Getting Started with Raspberry Pi
Getting Started with Raspberry PiGetting Started with Raspberry Pi
Getting Started with Raspberry Piyeokm1
 

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
 

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