Lecture 12 Bluetooth LE Topics BLE Basics code

Lecture 12: Bluetooth LE Topics: BLE Basics, code example

What is BLE? • A wireless protocol for connecting two devices. • Direct connection between two devices; e. g. phones and health trackers. • A lightweight subset of classic Bluetooth. • Introduced by Nokia; Became a part of the Bluetooth 4. 0 core specification.

BLE vs. Classic BT Spec. BLE BT Classic Topology Star Scatternet Throughput 0. 7 – 2. 1 Mbps 0. 3 Mbps Message 8 – 47 bytes 358 bytes Power < 15 m. A < 30 m. A Cost Low High Range 50 – 150 m < 30 m Latency 3 ms 100 ms

Devices: Two Roles • Peripheral Device (Server) Small Low power Resource constrained Connects to a more powerful (central) device • e. g. , heart rate monitors, BLE proximity tags • • • Central Device (Client) • More processing power • More memory • e. g. Smartphone and tablets

Advertising: Two Kinds of Payloads • Advertising Data Payload (Mandatory) – constantly transmitted out of the peripheral to let the central know its existence. • Scan Response Payload (optional) – only if a central device requests for this.

Advertising Process •

Advertisement-based Communication • Typically, peripherals would advertise, establish a connection, and start exchanging data. • Using advertisement packets, peripherals can broadcast data to any central in its listening range.

Generic Access Profile (GAP) • Controls connection and advertising processes. • Makes a device visible to the world. • Determines how two devices can/cannot interact. • Defines the role of a device.

Generic Attribute Profile (GATT) • Defines how two BLE devices transfer data back and forth using concepts like Services and Characteristics. • GATT works only after a dedicated connection between two devices has been established. • Connections are exclusive, i. e. a peripheral can only connect to one central device. • Communication is two-way.

Connected Network Topology • One central and many peripherals. • For two peripherals to talk, all messages have to pass through a central.

So, see the difference? • Advertisement-based vs. Connection-based: Connection-less Broadcast Communication Connection-oriented Two-way Communication

GATT (once they are connected) •

Again, see the difference? • Advertisement-based vs. Connection-based: Connection-less, broadcast communication Connection-oriented, two-way communication

GATT Transaction • All transactions are started by a GATT Client, which receives a response from the GATT Server. • When establishing a connection, a peripheral suggests a connection interval. • A central device tries to connect to the peripheral at every connection interval to check for new data. Connection-oriented, two-way communication

GATT Transaction • Profiles, services, and characteristics: Profile: Predefined collection of Services, compiled by either Bluetooth SIG or a peripheral designer. Service: • A collection of characteristics. • Unique ID called UUID (16 bit – 128 bit) Characteristic: • Encapsulates a single data point. • Can be used for sending data back to a peripheral as we can write into a characteristic.

Programming BLE in Android • Scanning and Listing BLE Devices Class Useful Methods Bluetooth. Manager get. Adapter() Bluetooth. Adapter get. Bluetooth. Le. Scanner() Bluetooth. Le. Scanner start. Scan() stop. Scan() Scan. Callback on. Scan. Result() BLUETOOTH and LOCATION permissions are required (manifest. xml) Red colored methods are async – do not call more than one at the same time.

Programming BLE in Android • Getting Connected and Listing Services: Class Useful Methods Bluetooth. Device connect. Gatt() Bluetooth. Gatt discover. Services() get. Services() Bluetooth. Gatt. Services get. Characteristics() Bluetooth. Gatt. Characteristics get. Descriptors() Bluetooth. Gatt. Descriptor Bluetooth. Gatt. Callback on. Connection. State. Change() on. Services. Discovered() Red colored methods are async – do not call more than one at the same time.

Programming BLE in Android • Reading Characteristics (i. e. data): Class Useful Methods Bluetooth. Device Bluetooth. Gatt set. Characteristics. Notification() write. Descriptor() Bluetooth. Gatt. Services Bluetooth. Gatt. Characteristics get. Value() Bluetooth. Gatt. Descriptor set. Value() Bluetooth. Gatt. Callback on. Characteristic. Read() on. Characteristic. Changed() on. Descriptor. Write() Red colored methods are async – do not call more than one at the same time.

References • https: //en. wikipedia. org/wiki/Bluetooth_low_energy • https: //learn. adafruit. com/introduction-to-bluetooth-low-energy/introduction • https: //developer. android. com/guide/topics/connectivity/bluetooth-le. html • http: //www. rfwireless-world. com/Terminology/Bluetooth-vs-BLE. html • https: //www. link-labs. com/blog/bluetooth-vs-bluetooth-low-energy
- Slides: 19