Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Lecture 12: Bluetooth LE Topics: BLE Basics, code example."— Presentation transcript:

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

2 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. Power manage: wake lock, reboot.

3 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 mA < 30 mA Cost Low High Range 50 – 150 m < 30 m Latency 3 ms 100 ms Power manage: wake lock, reboot.

4 Devices: Two Roles Peripheral Device (Server) Central Device (Client)
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 Power manage: wake lock, reboot.

5 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. Power manage: wake lock, reboot.

6 Advertising Process A peripheral periodically transmits an advertising packet at a specific advertising interval. Longer interval ≡ longer battery life, less responsive. If a listening device (central) is interested in a scan response payload, it can request for it, and the peripheral will respond with additional data. Power manage: wake lock, reboot.

7 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. Power manage: wake lock, reboot.

8 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. Power manage: wake lock, reboot.

9 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. Power manage: wake lock, reboot.

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

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

12 GATT (once they are connected)
GATT ≈ a client-server relationship. A peripheral is a GATT Server which holds service and characteristic definitions. A central is a GATT Client which sends requests to the server (peripheral).

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

14 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

15 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.

16 Programming BLE in Android
1. Scanning and Listing BLE Devices Class Useful Methods BluetoothManager getAdapter() BluetoothAdapter getBluetoothLeScanner() BluetoothLeScanner startScan() stopScan() ScanCallback onScanResult() 1 2 3 5 4 BLUETOOTH and LOCATION permissions are required (manifest.xml) Red colored methods are async – do not call more than one at the same time.

17 Programming BLE in Android
2. Getting Connected and Listing Services: Class Useful Methods BluetoothDevice connectGatt() BluetoothGatt discoverServices() getServices() BluetoothGattServices getCharacteristics() BluetoothGattCharacteristics getDescriptors() BluetoothGattDescriptor BluetoothGattCallback onConnectionStateChange() onServicesDiscovered() 1 3 5 6 7 2 4 Red colored methods are async – do not call more than one at the same time.

18 Programming BLE in Android
3. Reading Characteristics (i.e. data): Class Useful Methods BluetoothDevice BluetoothGatt setCharacteristicsNotification() writeDescriptor() BluetoothGattServices BluetoothGattCharacteristics BluetoothGattDescriptor setValue() BluetoothGattCallback onCharacteristicChanged() onDescriptorWrite() 1 3 2 5 4 Red colored methods are async – do not call more than one at the same time.

19 Programming BLE in Android
4(a). Advertising – acting as a Peripheral Class Useful Methods BluetoothManager getAdapter() BluetoothAdapter getBluetoothLeAdvertiser() isMultipleAdvertisementSupported() BluetoothLeAdvertiser startAdvertising() stopAdvertising() AdvertiseSettings Builder().setX().build() AdvertiseData Builder().addX().setX().build() AdvertiseCallback onStartSuccess() onStartFailure() 1 2 5 3 4 6 Generate and provide a 128-bit Service UUID inside the Advertise Data

20 Programming BLE in Android
4(b). Scanning to Receive Specific Advertisements Class Useful Methods BluetoothManager getAdapter() BluetoothAdapter getBluetoothLeScanner() BluetoothLeScanner startScan() stopScan() ScanCallback onScanResult() ScanSettings.Builder setScanmode().build() ScanFilter.Builder setServiceUUID().build() 1 2 5 7 6 3 4

21 References https://en.wikipedia.org/wiki/Bluetooth_low_energy
Power manage: wake lock, reboot.


Download ppt "Lecture 12: Bluetooth LE Topics: BLE Basics, code example."

Similar presentations


Ads by Google