Slide 1

Slide 1 text

Coffee.js How I Hacked a Coffee Machine Using JavaScript Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 2

Slide 2 text

Dominik Kundel | @dkundel | #wafflejs | console.log(` Hi! I’m Dominik Kundel `); dkundel.com @dkundel [email protected] github/dkundel Developer Evangelist !&& JavaScript Hacker #coffeejs #htcpcp

Slide 3

Slide 3 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp How I Hacked a Coffee Machine Using JavaScript

Slide 4

Slide 4 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 5

Slide 5 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 6

Slide 6 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp But Why?

Slide 7

Slide 7 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 1. It’s Interesting

Slide 8

Slide 8 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 2. “Alexa, make me a coffee”

Slide 9

Slide 9 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 3. APIs

Slide 10

Slide 10 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Why JavaScript?

Slide 11

Slide 11 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Why JavaScript?

Slide 12

Slide 12 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 1. The last time I wrote C++ was in university Why JavaScript?

Slide 13

Slide 13 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 1. The last time I wrote C++ was in university 2. I know JavaScript well === faster prototyping Why JavaScript?

Slide 14

Slide 14 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 1. The last time I wrote C++ was in university 2. I know JavaScript well === faster prototyping 3. Writing a web server is easy Why JavaScript?

Slide 15

Slide 15 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 1. The last time I wrote C++ was in university 2. I know JavaScript well === faster prototyping 3. Writing a web server is easy 4. It’s more of a challenge Why JavaScript?

Slide 16

Slide 16 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 1. The last time I wrote C++ was in university 2. I know JavaScript well === faster prototyping 3. Writing a web server is easy 4. It’s more of a challenge 5. Hardware === eventDriven && JS === eventDriven Why JavaScript?

Slide 17

Slide 17 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Options?

Slide 18

Slide 18 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 19

Slide 19 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Espruino

Slide 20

Slide 20 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Espruino Johnny-Five

Slide 21

Slide 21 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Espruino Johnny-Five Tessel

Slide 22

Slide 22 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp +

Slide 23

Slide 23 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp How?

Slide 24

Slide 24 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Disclaimer

Slide 25

Slide 25 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Disclaimer

Slide 26

Slide 26 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 27

Slide 27 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 28

Slide 28 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 29

Slide 29 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 30

Slide 30 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 31

Slide 31 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 32

Slide 32 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp The Facts • 8 cables • 6 switches • 7 LEDs

Slide 33

Slide 33 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp The Facts • 8 cables • 6 switches • 7 LEDs The Assumptions • One cable for power • At least 3 pins + power for buttons • At least 3 pins + power for LEDs

Slide 34

Slide 34 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp const five = require('johnny-five'); const Tessel = require('tessel-io'); const board = new five.Board({ io: new Tessel(), }); board.on('ready', () !=> { const p1 = new five.Pin({ pin: 'b0', mode: 2, }); !//!!... const p8 = new five.Pin({ pin: 'b7', mode: 2, }); const pins = [p1 !/* !!... !*/, , p8]; board.repl.inject({ pins: pins }); }); The Naive Approach

Slide 35

Slide 35 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp board.on('ready', () !=> { !// PIN declaration !!... const b2 = new five.Button('b1'); const b3 = new five.Button('b2'); const b7 = new five.Button('b6'); const b8 = new five.Button('b7'); const buttons = [b2, b3, b7, b8]; buttons.forEach(btn !=> { btn.on('press', () !=> console.log('Pressed button no.%d', btn.pin) ); btn.on('release', () !=> console.log('Released button no.%d', btn.pin) ); }); }); How about Buttons? const b2 = new five.Button('b1'); const b3 = new five.Button('b2'); const b7 = new five.Button('b6'); const b8 = new five.Button('b7'); const buttons = [b2, b3, b7, b8]; buttons.forEach(btn !=> { btn.on('press', () !=> console.log('Pressed button no.%d', btn.pin) ); btn.on('release', () !=> console.log('Released button no.%d', btn.pin) ); });

Slide 36

Slide 36 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 37

Slide 37 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 38

Slide 38 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 39

Slide 39 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp A Small Success • Pin 1 is power (turns LED 4,5,7) • Pin 4-6 control LEDs 4,5,7 • Pin 7-8 react on switches • Pin 2 manipulates switches 3 & 4 • Pin 3 manipulates switches 1 & 2

Slide 40

Slide 40 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Back to the Drawing Board

Slide 41

Slide 41 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 42

Slide 42 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 43

Slide 43 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 44

Slide 44 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Pin 1-3 = Pin 4-6 = Pin 7-8 = (???)

Slide 45

Slide 45 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Diodes!

Slide 46

Slide 46 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 47

Slide 47 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp • Switch 1 = P3 → P7 • Switch 2 = P3 → P8 • Switch 3 = P2 → P7 • Switch 4 = P2 → P8 • Switch 5 = P1 → P7 • Switch 6 = P1 → P8 • LED 7 = P1 → P6 • …

Slide 48

Slide 48 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 49

Slide 49 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 50

Slide 50 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Controlling Relays const espresso = new five.Relay({ pin: 'a4', type: 'NO', }); const grande = new five.Relay({ pin: 'a5', type: 'NO', }); const power = new five.Relay({ pin: 'a6', type: 'NO', }); espresso.close(); grande.close(); power.close(); board.repl.inject({ espresso, grande, power });

Slide 51

Slide 51 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 52

Slide 52 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 53

Slide 53 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 54

Slide 54 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp IoT Coffee Machine?

Slide 55

Slide 55 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 418 - I’m a teapot

Slide 56

Slide 56 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp IETF RFC 2324

Slide 57

Slide 57 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp HTCPCP

Slide 58

Slide 58 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Hyper Text Coffee Pot Control Protocol

Slide 59

Slide 59 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp • Built on top of HTTP • Adds BREW method • Safe and Accept-Additions Headers • HTTP code 418 • coffee:!// URI scheme • Many more things Hyper Text Coffee Pot Control Protocol

Slide 60

Slide 60 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 61

Slide 61 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp

Slide 62

Slide 62 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp Check out the Code github.com/dkundel/htcpcp-delongi

Slide 63

Slide 63 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp My Learnings

Slide 64

Slide 64 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 1. Reverse-engineering is a lot of fun

Slide 65

Slide 65 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 2. Reverse-engineering is frustrating

Slide 66

Slide 66 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 3. JS + Hardware !!===

Slide 67

Slide 67 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 4. Tessel 2 is great!

Slide 68

Slide 68 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp 5. Johnny-Five Is Super Useful

Slide 69

Slide 69 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp bit.ly/coffee-js

Slide 70

Slide 70 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp d-k.im/nodebots

Slide 71

Slide 71 text

Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp d-k.im/waffle-coffee

Slide 72

Slide 72 text

console.log(` Thank You! `); dkundel.com @dkundel [email protected] github/dkundel d-k.im/waffle-coffee Dominik Kundel | @dkundel | #wafflejs | #coffeejs #htcpcp