SHA2017 - Coffee Machines && JavaScript - Intro to Nodebots

SHA2017 - Coffee Machines && JavaScript - Intro to Nodebots

These are the slides for a workshop given at SHA 2017

0722ad084c65f6177d80cf793cfbd013?s=128

Dominik Kundel

August 06, 2017
Tweet

Transcript

  1. Coffee Machines && JS Intro Workshop to Nodebots Dominik Kundel

    | @dkundel | #sha2017 #coffeejs
  2. HI! ! I'm Dominik! ! Dominik Kundel | @dkundel |

    #sha2017 #coffeejs
  3. About me Developer Evangelist at Get in touch with me!

    ! @dkundel " dkundel@twilio.com # github/dkundel Dominik Kundel | @dkundel | #sha2017 #coffeejs
  4. How I hacked my ☕ Machine Dominik Kundel | @dkundel

    | #sha2017 #coffeejs
  5. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  6. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  7. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  8. Why? Dominik Kundel | @dkundel | #sha2017 #coffeejs

  9. 1. It's interes,ng Dominik Kundel | @dkundel | #sha2017 #coffeejs

  10. 2. "Alexa, make me a coffee" Dominik Kundel | @dkundel

    | #sha2017 #coffeejs
  11. 3. API all the things! Dominik Kundel | @dkundel |

    #sha2017 #coffeejs
  12. Why JS? Dominik Kundel | @dkundel | #sha2017 #coffeejs

  13. Why JS? 1. The last +me I wrote C++ was

    in university 2. I know JavaScript well which makes coding faster 3. Wri+ng a web server is easy 4. It's more challenging 5. Hardware === eventDriven && JS === eventDriven Dominik Kundel | @dkundel | #sha2017 #coffeejs
  14. Op#ons? Dominik Kundel | @dkundel | #sha2017 #coffeejs

  15. Op#on 1: Espruino www.espruino.com Dominik Kundel | @dkundel | #sha2017

    #coffeejs
  16. Op#on 1: Espruino Dominik Kundel | @dkundel | #sha2017 #coffeejs

  17. Op#on 2: Tessel tessel.io Dominik Kundel | @dkundel | #sha2017

    #coffeejs
  18. Op#on 2: Tessel Dominik Kundel | @dkundel | #sha2017 #coffeejs

  19. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  20. Op#on 3: Johnny-Five johnny-five.io Dominik Kundel | @dkundel | #sha2017

    #coffeejs
  21. Op#on 3: Johnny-Five Dominik Kundel | @dkundel | #sha2017 #coffeejs

  22. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  23. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  24. How? Dominik Kundel | @dkundel | #sha2017 #coffeejs

  25. Disclaimer Dominik Kundel | @dkundel | #sha2017 #coffeejs

  26. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  27. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  28. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  29. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  30. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  31. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  32. What We Knew • 8 cables/pins • 6 switches •

    7 LEDs Dominik Kundel | @dkundel | #sha2017 #coffeejs
  33. Assump&ons 1. One cable is ⚡ 2. We need at

    least 3 pins + power controlling the " 3. We need at least 3 pins + power controlling the # 4. What is the 8th cable for? Dominik Kundel | @dkundel | #sha2017 #coffeejs
  34. The Naive Approach 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 }); }); Dominik Kundel | @dkundel | #sha2017 #coffeejs
  35. The Naive Approach II const five = require('johnny-five'); const Tessel

    = require('tessel-io'); const board = new five.Board({ io: new Tessel() }); board.on('ready', () => { const p2 = new five.Pin({ pin: 'b1' /*, mode: 2 */ }); //... const p8 = new five.Pin({ pin: 'b7'/*, mode: 2 */ }); const pins = [p2, /* ... */, p8]; board.repl.inject({ pins: pins }); }); Dominik Kundel | @dkundel | #sha2017 #coffeejs
  36. Bu#ons? How About Bu#ons! 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)); }); }); Dominik Kundel | @dkundel | #sha2017 #coffeejs
  37. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  38. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  39. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  40. We Are On To Something ! • Pin 1 is

    ⚡ (turns on LED4, LED5, LED7) • Pin 4-6 can turn off " LED4, " LED5, " LED7 • Pin 7-8 react on # • Pin 2 can manipulate # S3 && # S4 • Pin 3 can manipulate # S1 && # S2 Dominik Kundel | @dkundel | #sha2017 #coffeejs
  41. Back To The Drawing Board Dominik Kundel | @dkundel |

    #sha2017 #coffeejs
  42. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  43. To The Rescue! Dominik Kundel | @dkundel | #sha2017 #coffeejs

  44. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  45. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  46. ! Progress! ! Pin 1-3 === ⚡ Pin 4-6 ===

    ! Pin 7-8 === !??? Dominik Kundel | @dkundel | #sha2017 #coffeejs
  47. Diodes! Dominik Kundel | @dkundel | #sha2017 #coffeejs

  48. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  49. It All Makes Sense! ! S1 = P3 ➡ P7

    ! S2 = P3 ➡ P8 ! S3 = P2 ➡ P7 ! S4 = P2 ➡ P8 ! S5 = P1 ➡ P7 ! S6 = P1 ➡ P8 " LED7 (Power) = P1 ➡ P6 Dominik Kundel | @dkundel | #sha2017 #coffeejs
  50. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  51. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  52. 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 }); Dominik Kundel | @dkundel | #sha2017 #coffeejs
  53. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  54. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  55. IoT Coffee Machine? Dominik Kundel | @dkundel | #sha2017 #coffeejs

  56. 418 - I'm a teapot Dominik Kundel | @dkundel |

    #sha2017 #coffeejs
  57. IETF RFC 2324 HTCPCP Dominik Kundel | @dkundel | #sha2017

    #coffeejs
  58. Hyper Text Coffee Pot Control Protocol Dominik Kundel | @dkundel

    | #sha2017 #coffeejs
  59. Hyper Text Coffee Pot Control Protocol • Built on top

    of HTTP • Adds BREW method • Safe and Accept-Additions Headers • HTTP code 418 • coffee:// URI scheme • many more things Dominik Kundel | @dkundel | #sha2017 #coffeejs
  60. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  61. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  62. ! It's Alive!! ! Dominik Kundel | @dkundel | #sha2017

    #coffeejs
  63. ! github.com/dkundel/htcpcp-delonghi Dominik Kundel | @dkundel | #sha2017 #coffeejs

  64. Dominik Kundel | @dkundel | #sha2017 #coffeejs

  65. ! github.com/dkundel/nodebots-workshop Dominik Kundel | @dkundel | #sha2017 #coffeejs

  66. What I learned: Dominik Kundel | @dkundel | #sha2017 #coffeejs

  67. ! Reverse-engineering is a lot of fun Dominik Kundel |

    @dkundel | #sha2017 #coffeejs
  68. ! Reverse-engineering is frustra/ng Dominik Kundel | @dkundel | #sha2017

    #coffeejs
  69. JS ❤ Hardware Dominik Kundel | @dkundel | #sha2017 #coffeejs

  70. ! Tessel 2 is great! Dominik Kundel | @dkundel |

    #sha2017 #coffeejs
  71. ! Johnny-Five is super useful! Dominik Kundel | @dkundel |

    #sha2017 #coffeejs
  72. What's Next? ! • Programma(cally determine state • Add more

    relays • Sugges(ons??? Dominik Kundel | @dkundel | #sha2017 #coffeejs
  73. ! bit.ly/coffee-js Dominik Kundel | @dkundel | #sha2017 #coffeejs

  74. ! bit.ly/sha2017-nodebots Dominik Kundel | @dkundel | #sha2017 #coffeejs

  75. Any Ques)ons? Get in touch with me! ! Dominik Kundel

    " @dkundel # dkundel@twilio.com $ github/dkundel Dominik Kundel | @dkundel | #sha2017 #coffeejs