Building Bluetooth Apps with Ionic

Ionic Philadelphia - December 7, 2017

Don Coleman - @doncoleman

Based on Figure 3.1 from “Bluetooth Low Energy” by Robin Heydon

Lightbulb Service

  • Light Switch
  • Dimmer Setting
  • Power Consumption

Lightbulb Service - FF10

16 bit UUIDs

0000FF10-0000-1000-8000-00805F9B34FB

0000FF11-0000-1000-8000-00805F9B34FB

0000FF12-0000-1000-8000-00805F9B34FB

0000FF16-0000-1000-8000-00805F9B34FB

Lightbulb Service - FF10

Advertising

Advertising

  • MAC Address: AA:BB:CC:DD:EE:FF
  • Services: [ 0x180A, 0xFF10, 0XFF20, …]
  • Manufacturer Data: <00007465 6d70>
  • Connectable: True
  • TX Power Level: 4
  • RSSI: -80
  • Name: Smart Lightbulb

Advertising

  • 5425B44A-024A-4D39-88D2-D9F016199B29
  • Services: [ 0x180A, 0xFF10, 0XFF20, …]
  • Manufacturer Data: <00007465 6d70>
  • Connectable: True
  • TX Power Level: 4
  • RSSI: -80
  • Name: Smart Lightbulb

After Connecting...

  • Get a list of services
  • For each service, get a list of characteristics
  • For each characteristic, get properties
  • Save handle to read or write later
  • Subscribe to be notified on changes

Read Value

Write Value

Write Command

Heart Rate Service -180d

org.bluetooth.service.heart_rate.xml
org.bluetooth.characteristic.heart_rate_measurement.xml

Notification

Indication

Peripheral

Provides services

Central

Uses services on a peripheral

Lightbulb Service - FF10

cordova-plugin-ble-central

github.com/don/cordova-plugin-ble-central

Ionic Native

ionicframework.com/docs/native/ble

Scanning for BLE devices

Create a project

  • $ ionic start scan blank -n Scan
  • $ cd ./scan

Install the Bluetooth plugin

  • $ ionic cordova plugin add cordova-plugin-ble-central
  • $ npm install --save @ionic-native/ble

Scan API

  • scan(services: string[], seconds: number): Observable

src/pages/home/home.ts

src/pages/home/home.ts

src/pages/home/home.ts

NgZone

src/pages/home/home.html

src/pages/home/home.html

Run the App

  • $ ionic cordova run android --device

NOTE: must run on real hardware

Connect API

  • connect(deviceId: string): Observable

src/pages/home/home.html

$ ionic generate page detail

src/pages/home/home.ts

src/pages/detail/detail.ts

src/pages/detail/detail.ts

src/pages/detail/detail.ts

Lightbulb Service - FF10

Write API

write(
    deviceId: string,
    serviceUUID: string,
    characteristicUUID: string,
    value: ArrayBuffer
): Promise

src/pages/home/home.ts

src/pages/detail/detail.html

src/pages/detail/detail.ts

src/pages/detail/detail.html

src/pages/detail/detail.ts

Read API

read(
    deviceId: string,
    serviceUUID: string,
    characteristicUUID: string
): Promise

src/pages/detail/detail.ts

src/pages/detail/detail.ts

Simple Key Service - FFE0

Notification API

startNotification(
    deviceId: string,
    serviceUUID: string,
    characteristicUUID: string
): Observable

src/pages/detail/detail.ts

src/pages/detail/detail.ts

src/pages/detail/detail.ts

Thermometer Service - bbb0

src/pages/detail/detail.ts

src/pages/detail/detail.ts

src/pages/detail/detail.html

src/pipes/format-temperature-c/format-temperature-c.ts

src/pipes/format-temperature-f/format-temperature-f.ts


makebluetooth.com

Thank You

Don Coleman - Chariot Solutions

@doncoleman

don@chariotsolutions.com

Slides http://don.github.io/slides/

Code http://github.com/don/ionic-ble-examples

 

Creative Commons License
Building Bluetooth Apps with Ionic by Don Coleman is licensed under a Creative Commons Attribution 4.0 International License.