66
Building a robot army with Angular and Nativescript @sebawita

Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Building a robot army with Angular and Nativescript@sebawita

Page 2: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Sebastian Witalec

@sebawita

Jack of all AngularMaster of Robots

Page 3: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Squirrels are cute

Page 4: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

But are they?

Page 5: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Modern squirrel warfare

Page 6: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Stormtroopers cameto the rescue

Page 7: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Trying to subduethe rebellion

Page 8: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

… and failed miserably

Page 9: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native
Page 10: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Robots answered the call

Page 11: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

But they spoke a different language

0x48, 0x69

TERVETULOA

Page 12: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

But they spoke a different language

0x48, 0x69 “Hi” in ASCII

TERVETULOA

Page 13: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Bluetooth

Page 14: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Functionality is grouped into Services

Serv

ices

Dashboard(fa00)

Speed Indicator

Fuel indicator

Weapons (fb00)

Main Cannon

Laser

Drive Control (fd00)

Steering wheel

Accelerator

Break

Page 15: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Services contain characteristicsCharacteristics

Serv

ices

Dashboard (fa00)

Speed Indicator(fa06)

Fuel indicator(fa1c)

Weapons (fb00)

Cute Ray(fb0c)

Laser(fb11)

Drive Control (fd00)

Steering wheel(fd01)

Accelerator(fd02)

Brake(fd03)

Page 16: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Characteristics interactionsCharacteristics

Serv

ices

Dashboard (fa00) [read]

Speed Indicator(fa06)

Fuel indicator(fa1c)

Weapons (fb00) [write]

Cute Ray(fb0c)

Laser(fb11)

Drive Control (fd00) [write]

Steering wheel(fd01)

Accelerator(fd02)

Break(fd03)

Page 17: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Wea

pons

(fb00

)Cute Ray

(fb0c)Reload(0x02)

Charge %(0x32)

Ray Type(0xFF)

Sending commands

const command ={service: 'fb00'characteristic: 'fb0c'instruction: [0x02, 0x32, 0xFF]

}

Page 18: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Run Bluetooth from

WebMobile

Page 19: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Web Bluetooth

Page 20: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Web bluetooth in 5 easy steps

0. Add web-bluetooth Typing1. Scan for device2. Connect to it3. Get the Service you need4. Get the Characteristic you need5. Read / Write from the Characteristic

Page 21: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 0 – Add web-bluetooth

npm install --save @types/web-bluetooth

Page 22: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 1 - Find a matching Device

/// <reference types="web-bluetooth" />

let device =await navigator.bluetooth.requestDevice({filters: [{ namePrefix: 'Mambo' }],optionalServices: [serviceUUID]

})

Page 23: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Steps 2-4 - Connect and get characteristiclet server =

await device.gatt.connect();

let service = await server.getPrimaryService(serviceUUID);

let characteristic =await service.getCharacteristic(characteristicUUID);

Page 24: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 5 - Read

const value =await characteristic.readValue();

console.log('val:' + value.getUint8(0));

Page 25: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 5 - Write

const instructions = new Int8Array([0x02, 0x32, 0xFF]);

characteristic.writeValue(instructions);

Page 26: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native
Page 27: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

https://www.npmjs.com/package/mambo-angular-service

Page 28: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Time to send the drone to scout on the enemy

Page 29: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

What about going beyond Chrome?

Page 30: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Bluetooth from a mobile app with NativeScript

+ =

Page 31: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

an open source framework for building truly native mobile apps with JavaScript. Use web skills, like TypeScript, Angular and CSS, and get native UI and performance on iOS and Android.

NativeScript is…

Page 32: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

NativeScript Bluetoothin 4 easy steps

0. Add nativescript-bluetooth1. Request permissions2. Scan for device3. Connect to it4. Read / Write from the Characteristic

Page 33: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 0 – Add nativescript-bluetooth

tns plugin add nativescript-bluetooth

Page 34: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 1 – Request permissions

import bluetooth = require('nativescript-bluetooth');

bluetooth.requestCoarseLocationPermission().then(() => console.log('Location permission requested'));

Page 35: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 2 - Find a matching Device

bluetooth.startScanning({seconds: 3,

})

Page 36: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 2 - Find a matching Device

bluetooth.startScanning({seconds: 3,onDiscovered: (peripheral: Peripheral) => {console.log('Device UUID: ' + peripheral.UUID);console.log('Device name: ' + peripheral.name);

}})

Page 37: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 3 - Connect to the Device

bluetooth.connect({UUID: deviceUUID,

});

Page 38: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 3 - Connect to the Device

bluetooth.connect({UUID: deviceUUID,onConnected: ((peripheral: Peripheral) => {console.log('Device connected: ' + peripheral.UUID);

}),

});

Page 39: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 3 - Connect to the Device

bluetooth.connect({UUID: deviceUUID,onConnected: ((peripheral: Peripheral) => {console.log('Device connected: ' + peripheral.UUID);

}),onDisconnected: ((peripheral: Peripheral) => {console.log('Device disconnected');

})});

Page 40: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 4 - Read

bluetooth.read({peripheralUUID: deviceUUID,serviceUUID: serviceUUID,characteristicUUID: characteristicUUID

})

Page 41: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 4 - Read

bluetooth.read({peripheralUUID: deviceUUID,serviceUUID: serviceUUID,characteristicUUID: characteristicUUID

}).then((result: ReadResult) => {

const data = new Uint8Array(result.value);});

Page 42: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 4 - Write

const bluetoothOptions: WriteOptions = {peripheralUUID: deviceUUID,serviceUUID: serviceUUID,characteristicUUID: characteristicUUID,value: '0x02, 0x32, 0xFF'

}

Page 43: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Step 4 - Write

const bluetoothOptions: WriteOptions = {peripheralUUID: deviceUUID,serviceUUID: serviceUUID,characteristicUUID: characteristicUUID,value: '0x02, 0x32, 0xFF'

}bluetooth.writeWithoutResponse(bluetoothOptions);

Page 44: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native
Page 45: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

https://www.npmjs.com/package/nativescript-mip-ble

Page 46: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native
Page 47: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Reverse Engineering

Page 48: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Android Developer Tools

Page 49: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Wireshark

Page 50: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Looking for the bullet:Test instructions1. Fire2. Fire3. TakeOff4. Land5. Fire6. Fire7. Fire8. TakeOff9. Land

Page 51: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Looking for the bullet:Test instructions

TakeOff: [ 4, step, 2, 0, 1, 0 ]

Land: [ 4, step, 2, 0, 3, 0 ]

Page 52: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Looking for the bullet:Test instructions

prefixTakeOff: [ 4, step, 2, 0, 1, 0 ]

Land: [ 4, step, 2, 0, 3, 0 ]

Page 53: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Looking for the bullet:Test instructions

prefix commandTakeOff: [ 4, step, 2, 0, 1, 0 ]

Land: [ 4, step, 2, 0, 3, 0 ]

Page 54: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native
Page 55: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native
Page 56: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native
Page 57: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Take OffLand

Take OffLand

Page 58: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Take OffLand

Take OffLand

Page 59: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native
Page 60: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Fire Instruction

04 xx 02 10 02 00 00 00 00 00 00

Page 61: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

The result of the battlefor the unnamed woods

Page 62: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Unconditional surrendered

Page 63: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Summary

Bluetooth is fun and easy to usenpm examples to get started:- mambo-angular-service- nativescript-mambo-ble- nativescript-mip-ble

Page 64: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Summary

Use NativeScript:- for Android and iOS apps support- up to 10 devices connected

Use Web Bluetooth:- to run in Chrome on Mac and Windows and Android- only one device connection

For WB with Observables use:- @manekinekko/angular-web-bluetooth

Page 65: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native

Summary

Reverse engineering can be tricky, use:- Android HCI Snoop log- Together with WireShark

Advanced options:- Pattern matching tools – group by command value- Replay tool

Page 66: Building a Robo-Army with Angular€¦ · enemy. What about going beyond Chrome? Bluetooth from a mobile app with NativeScript + = an open source framework for building truly native