fun with bluetooth

n e b k i o l l ha t s e t 5 l m t @h

fun with bluetooth

waarom?

progressive web apps

pwa’s zijn geweldig !

maar…

bluetooth

bluetooth t g i zu

classic bluetooth vs. m o r a t a a w a h n e h d t e r o o e d bluet n e e r e d ie bedien dro n es en ande bluetooth low energy re coole sh i t

bluetooth low energy ook bekend als B l Bluetooth Smar t uetooth LE B l u e t o o t h 4 BLE

bluetooth low energy ook bekend als B l Bluetooth Smar t uetooth LE B l u e t o o t h 4 and 5 BLE

10 miljoen apparaten met bluetooth worden elke dag gemaakt

n o o f e l e t e l e i b o m

computer

r e t e m e s o c glu iem d n a h s d an

spor thorloge

u b y a pl s lb e r e h p b l u b y a l p

8 b b o i r e h p s

e n o r d i n parrot mi

r e n n i p s t fidge

de saaie theorie

central peripheral

central

generic attribute profile

generic attribute profile ?

generic attribute profile m o , t gat n i l a p a g dat s a w k i u r geb

central peripheral client server

§ i device information light e s e r e d r e e m t a a r a p p a r e p s rvice

i device information battery flight control

i device information battery steering control

i device information battery heart rate

i device information battery heart rate

i device information battery heart rate

i device information manufacturer model number serial number hardware revision firmware revision software revision … s c i t s i r e t c a r a h c e r e e c i d v r r e s r mee e p

server service characteristic value array of objects object property value

services en characteristics hebben altijd een uuid 16 bit of 12 8 bit

i device information 16 bit 128 bit 0x180A 0000180A-0000-1000-8000-00805F9B34FB

battery 16 bit 128 bit 0x180F 0000180F-0000-1000-8000-00805F9B34FB

steering control light maar iede flight c reen doet h 16 bit 128 bit et toch wordt afgeraden elke UUID behalve de reeks xxxxxxxx-0000-1000-8000-00805F9B34FB

i device information manufacturer model number serial number hardware revision firmware revision software revision …

i 0x180A 0x2A29 0x2A24 0x2A25 0x2A27 0x2A26 0x2A28 … s l e c goed vo ht voor de or het b duidelij esparen kheid, van dat a

d n u e t s r e d n o c i t e s i z r e e d t c n a r a a v le ke ch een of meer lezen schrijven schrijven zonder bevestiging notificatie

elke waarde is een array van bytes p y t a t a n e ge d e r e g o h e e l l a es, s e t y b n

pfew…

n e t i e f e i a a s r e v o fun with bluetooth

fun with bluetooth

web bluetooth nog steed s niet het leuke ged eelte :-( api

verbinden met een apparaat

navigator.bluetooth.requestDevice({ filters: [ { namePrefix: ‘PLAYBULB’ } ], optionalServices: [ 0xff0f ] }) .then(device => device.gatt.connect()) .then(server => server.getPrimaryService(0xff0f)) .then(service => service.getCharacteristic(0xfffc)) t a w r e s w o r b e d n e l l e we ver t n e l l i w e w t a a r a p p a voor soor t .then(characteristic => { return characteristic.writeValue( new Uint8Array([ 0x00, r, g, b ); }) ])

r e k i u r b de ge ecteer t sel aat r a p p a t e h

navigator.bluetooth.requestDevice({ filters: [ { namePrefix: ‘PLAYBULB’ } ], optionalServices: [ 0xff0f ] }) .then(device => { …. }) .then(device => device.gatt.connect()) .then(server => server.getPrimaryService(0xff0f)) .then(service => service.getCharacteristic(0xfffc)) z s e s i m o r p 7 1 0 2 o ij z .then(characteristic => { return characteristic.writeValue( new Uint8Array([ 0x00, r, g, b ); ])

let device = await navigator.bluetooth.requestDevice({ filters: [ { namePrefix: ‘PLAYBULB’ } ], optionalServices: [ 0xff0f ] }); .then(device => device.gatt.connect()) .then(server => server.getPrimaryService(0xff0f)) .then(service => service.getCharacteristic(0xfffc)) .then(characteristic => { return characteristic.writeValue( new Uint8Array([ 0x00, r, g, b ); }) ])

let device = await navigator.bluetooth.requestDevice({ filters: [ { namePrefix: ‘PLAYBULB’ } ], optionalServices: [ 0xff0f ] }); r e v r e s e d t e nd m verbi let server = await device.gatt.connect()); let service = await server.getPrimaryService(0xff0f)); let characteristic = await service.getCharacteristic(0xfffc)); e c i v r e s e haal d .then(characteristic => { return characteristic.writeValue( new Uint8Array([ 0x00, r, g, b ); }) ]) c i t s i r e t c a r a h c e d haal

data schrijven

n e e f j i r sch bytes r a pa let let let let device = await navigator.bluetooth.requestDevice({ … }); server = await device.gatt.connect()); service = await server.getPrimaryService(0xff0f)); characteristic = await service.getCharacteristic(0xfffc)); characteristic.writeValue( new Uint8Array([ 0x00, r, g, b ); ])

data lezen

s e le n e e r a pa s e t by let let let let device = await navigator.bluetooth.requestDevice({ … }); server = await device.gatt.connect()); service = await server.getPrimaryService(0xff0f)); characteristic = await service.getCharacteristic(0xfffc)); let value = await characteristic.readValue(); let r = value.getUint8(1); let g = value.getUint8(2); let b = value.getUint8(3);

krijg bericht van wijzigingen

r e n e t s i l t n e v e d d a let let let let device = await navigator.bluetooth.requestDevice({ … }); server = await device.gatt.connect()); service = await server.getPrimaryService(0xff0f)); characteristic = await service.getCharacteristic(0xfffc)); characteristic.addEventListener( ‘characteristicvaluechanged’, e => { let r = e.target.value.getUint8(1); let g = e.target.value.getUint8(2); let b = e.target.value.getUint8(3); } ); vergeet niet characteristic.startNotifications(); om te luister en

dingen die je moet weten: • de webbluetooth api • promises (of async await) • typed arrays d ! h u

browser support Chrome Edge (soon) Samsung Servo (soon)

browser support Chrome Edge (soon) Samsung Servo (soon) iOS

browser support Chrome Edge (soon) Samsung Servo (soon) iOS

browser support a d kin Chrome Edge (soon) Samsung s k r o w Servo WebBLE (soon) for iOS

en…

en… npm install node-web-bluetooth

en… npm install cordova-plugin-webbluetooth

en… espruino m m 8 2 x 8 1

custom characteristics. wtf!

writing a value: function(r, g, b) { return new Uint8Array([ 0x00, r, g, b } ]); reading a value: function(buffer) { return { r: buffer.getUint8(1), g: buffer.getUint8(2), b: buffer.getUint8(3) } } fro g n i d a e r d n a o t g writin c i t s i r e t c a r a h c e m a s e h t m

writing a value: function(r, g, b) { return new Uint8Array([ 0x01, g, 0x01, 0x00, 0x01, b, 0x01, r, 0x01, 0x00 ]); } t n e r r u c e h t g n i read e l b i s s o p t o n s i r colo

writing a value: function(r, g, b) { var buffer = new Uint8Array([ 0xaa, 0x0a, 0xfc, 0x3a, 0x86, 0x01, 0x0d, 0x06, 0x01, r, g, b, 0x00, 0x00, (Math.random() * 1000) & 0xff, 0x55, 0x0d ]); for (var i = 1; i < buffer.length - 2; i++) { buffer[15] += buffer[i]; } } return buffer; t n e r r u c e h t g n i read e l b i s s o p t o n s i r colo

writing a value: function(r, g, b, position) { let buffer = new Uint8Array([ 0x07, 0x02, position + 1, r, g, b ]); } return buffer;

writing a value: function(r, g, b, position) { let buffer = new Uint8Array([ 0x58, r, g, b, 0x01, position ]); …

writing a value: function(r, g, b, position) { let buffer = new Uint8Array([ 0x58, r, g, b, 0x01, position ]); let payload = new Uint8Array(buffer.length + 4); payload[0] = payload.length - 2; payload[1] = payload.length - 2 >>> 8; payload.set(buffer, 2); let checksum = payload.reduce((a, b) => a + b, 0); payload[payload.length - 2] = checksum; payload[payload.length - 1] = checksum >>> 8; let extra = payload.filter(value => {

message[m] = 0x03; message[m + 1] = 0x05; m += 2; } } else if (payload[i] === 0x03) { message[m] = 0x03; message[m + 1] = 0x06; m += 2; } else { message[m] = payload[i]; m++; } message[0] = 0x01; message[message.length - 1] = 0x02; } return message;

adafruit bluetooth sniffer

log alle bluetooth packets op jouw telefoon b d a k i u r r e b v e o g en om ze etten z e t

m o k r a n h e s e k j r i i k w e b k i e u t r a b ge de dat

de apk decompilen nie l k r e tv ! n e p ap

eindelijk demo het leuk e gedeelt e

waarschuwing experimentele technologie n i t h c a w r e v lage n e p p e h c s gen

waarschuwing wifi interferentie ! r e g a l t a w r a a m g o n t a l e d t e z

fun with bluetooth !

vragen? @htm l5test