JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

67
How I Got Back my Coding Mojo! Mark West

Transcript of JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Page 1: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

How  I  Got  Back  my  Coding  Mojo!  

Mark  West  

Page 2: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Safe  Harbour  

Page 3: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

What  is  Mojo?  

Page 4: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 5: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 6: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 7: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

    “Any  applica+on  that  can  be  

wri3en  in  JavaScript,  will  eventually  be  wri3en  in  

JavaScript”  

James  Atwood  (founder,    stackoverflow.com)  

Page 8: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 9: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 10: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

NodeBot  Rover  

Page 11: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

NodeBot  Rover  Demo  

Page 12: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

NodeBot  Rover  Component  Overview  Hardware  

Computer  

Micro  Controller  

Camera  

Chassis  

Pan  &  Tilt  

SoAware  

Speech  

Robot  Control  

Web  Server  

IntegraFon  

Other  

Page 13: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

The  Arduino  Ecosystem  •  MicroController  plaLorm.  

•  Many  different  Arduino  models.  

•  Open  Source  design.  

•  MicroControllers  extensible  via  “Shields”.  

Page 14: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

PuSng  the  Hardware  Together  

Page 15: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 16: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 17: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 18: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Two  Servos  for  Camera  Pan  &  Tilt  

Servos  wired  to  Arduino  Chassis  

Raspberry  PI    In  PlasFc  Case  

WIFI  Dongle  

Page 19: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Raspberry  PI  Camera  

Wired  directly  to  the  

Raspberry  PI  

Page 20: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

     

     

Actuators  

Sensors  

Nervous  System  

Raspberry  PI  2  Raspberry  PI  Cam  

Arduberry  Microcontroller   Arduino  Chassis   Servo  

Servo  

Brain  

NodeBot  Rover  Hardware  

Page 21: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Combining  the  Raspberry  PI  &  Arduino  Raspberry  PI  

•  Linux  PC.  

•  Supports  USB  peripherals.  

•  Programming.  

Arduino  PlaNorm  •  MicroController.  

•  Robust.  

•  Flexibility  (input/output).  

The  whole  is  greater  than  the  sum  of  parts!  

Page 22: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

     

     

Actuators  

Sensors  

Nervous  System  

Raspberry  PI  2  Raspberry  PI  Cam  

Arduberry  Microcontroller   Arduino  Chassis   Servo  

Servo  

Brain  

NodeBot  Rover  Hardware  

Page 23: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

NodeBot  Rover  Component  Overview  Hardware  

Raspberry    PI  

Arduberry  (Arduino)  

Pi  Cam  

Zumo  Chassis  

Servos  

SoAware  

Speech  

Robot  Control  

Web  Server  

IntegraFon  

Other  

Page 24: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

     

     

Raspberry  PI  2  

Arduberry  

Servo  

So\ware  Communica]on  across  Hardware  Layers  

Servo  

Raspberry  PI     Chassis  

JavaScriptPI     Binary  (Compiled  C  /  C++)    

Page 25: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

The  NodeBots  Movement  

Source  :  nodebots.io  

Page 26: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 27: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

1.  Maturity  2.  Community  3.  DSL  4.  Portability  5.  Open  Source  6.  Node.js  ecosystem  7.  REPL  

 

Benefits  of  using  Johnny-­‐Five  

Page 28: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

var five = require("johnny-five");

var myBoard = new five.Board();

myBoard.on("ready", function() {

var myLed = new five.Led(13);

myLed.blink(500);

this.repl.inject({ replLed: myLed });});

Imports  J5  Dependancy  

Adds  LED  instance  to  REPL  

Declares  LED  as  connected  to  UNO  Pin  13  

Blinks  LED  every  500  milliseconds  

Code  block  triggered  by  UNO  ”Ready”  Event  

Ini]alises  UNO  

Johnny-­‐Five  Code  Example  

Page 29: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

hhps://vimeo.com/134953425    

Page 30: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

     

     

Arduberry  

Servo  

Bridging  the  gap  with  Firmata  

Servo  

Raspberry  PI     Chassis  

Johnny-­‐Five  (Firmata  Client)  

Std.  Firmata  (Firmata  Server)  

JavaScriptPI     Binary  (Compiled  C  /  C++)      

Page 31: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 32: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

GeSng  Started  with  Johnny-­‐Five  1.  Buy  an  Arduino  Experimenters  Kit.  

2.  Follow  the  tutorials  at  hSp://node-­‐ardx.org.  

3.  Visit  hSp://johnny-­‐five.io  for  more  informa]on  and  inspira]on.  

Page 33: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

NodeBot  Rover  Component  Overview  Hardware  

Raspberry    PI  

Arduberry  (Arduino)  

Pi  Cam  

Zumo  Chassis  

Servos  

SoAware  

Speech  

Johnny-­‐Five  

Web  Server  

IntegraFon  

Other  

Page 34: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Speech  Recogni]on  Requirements  

Need  to  have    

•  Quality  and  speed  of  speech  recogni]on.  

•  Free,  no  restric]ons.  •  So\ware  based.  •  JavaScript.  

Nice  to  have  

•  Speech  to  text.  •  One  stop  service.  •  Bahle  tested.  

Page 35: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 36: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 37: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Web  Speech  API  

(limited  to  Google  Chrome)  

Page 38: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Web  Speech  API  :  Configura]on  

Page 39: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Web  Speech  API  :  Events  

Page 40: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Web  Speech  API  :  Control  

Page 41: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Speech  Demo  

Page 42: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Buhon  press  and  release  connected  to  Web  Speech  API  start  and  stop  Control  

methods.  

Con+nuous  dicta+on  switched  on,  to  avoid  cuSng  commands  short.    

Interim  results  switched  on  –  shown  in  green  text  (final  results  in  white).  

Each  set  of  results  checked  for  uniqueness  to  avoid  sending  duplicate  commands  to  

the  Robot.  

Web  Speech  API  :  Robot  

Page 43: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

NodeBot  Rover  Component  Overview  Hardware  

Raspberry    PI  

Arduberry  (Arduino)  

Pi  Cam  

Zumo  Chassis  

Servos  

SoAware  

HTML5  Speech  

Johnny-­‐Five  

Web    Server  

IntegraFon  

Other  

Page 44: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 45: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Node.js  Express  Web  

Server  (17  lines  of  code)  

Page 46: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

NodeBot  Rover  Component  Overview  Hardware  

Raspberry    PI  

Arduberry  (Arduino)  

Pi  Cam  

Zumo  Chassis  

Servos  

SoAware  

Speech  

Johnny-­‐Five  

Express  

IntegraFon  

Other  

Page 47: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Johnny-­‐Five    Process  

Express    Process  

Raspberry  PI  2  

WE  

Browser  

HTTPS  

NodeBot  Rover  

Hardware  

 Firmata    

 

Page 48: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Johnny-­‐Five    Process  

Express    Process  

Raspberry  PI  2  

WE  

Browser  

HTTPS  

NodeBot  Rover  

Hardware  

 Firmata    

 

MQTT  Message  Broker  

MQTT  

MQTT  over  WebSockets  

Commands  

Acknowledgements  

MQTT.js  Client  

MQTT.js  Client  

Page 49: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Why  Add  a  Message  Broker?  

•  Sepera]on  of  concerns.  

•  Isolate  main  components  for  easier  tes]ng.  

Page 50: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

MQTT  –  MQ  Telemetry  Transport    

•  Internet  of  Things  connec]vity  protocol.  

•  Designed  to  be  lightweight  with  a  small  footprint  and  lihle  overhead.  

•  Is  a  protocol  and  a  Pub-­‐Sub  Message  Broker.  

•  Used  by  Facebook  for  pushing  updates  to  mobile  clients.  

Page 51: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Adding  MQTT  to  the  NodeBot  Rover  Broker  

•  Public  MQTT  Broker  

–  Many  Public  Brokers  exist.  –  One  less  process  to  run  on  

Raspberry  PI.  

Client  

•  MQTT.js  

–  Provides  an  MQTT  client  library  for  Node.js.  

–  Extremely  simple  to  use.  –  Integrates  seamlessly  with  

Johnny-­‐Five.  

 

Page 52: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

MQTT.js  (Node.js)  Client  Example  

Page 53: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

MQTT  Over  WebSockets  with  MQTT.js  •  MQTT.js  is  a  Node.js  package  and  is  

meant  for  use  on  the  Server  Side.  

•  To  allow  MQTT.js  to  run  from  the  Browser,  we  first  needed  to  ”Browserify”  the  MQTT  library.  

•  We  could  then  access  the  ”Browserified”  MQTT  client  library  from  the  Browser.  

•  This  solu]on  requires  that  your  MQTT  Broker  has  a  WebSocket  endpoint.  

Page 54: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

MQTT  Over  WebSockets  Demo  

Page 55: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

NodeBot  Rover  Component  Overview  Hardware  

Raspberry    PI  

Arduberry  (Arduino)  

Pi  Cam  

Zumo  Chassis  

Servos  

SoAware  

HTML5  Speech  

Johnny-­‐Five  

Express  

MQTT  &  WebSocket  

Other  

Page 56: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Node.js  Twiher  Client  •  Fully  fledged  Twiher  Client:  – Asynchronous.  –  Supports  REST  API  (write  and  write)  –  Supports  Streaming  API  (events  and  tweets).  

•  Requires  developer  creden]als  from  Twiher:  –  Trivial  to  get  hold  of.  

Page 57: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Node.js  Twiher  Client  REST  Example  

Page 58: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Video  Streaming  via  Mo]on  •  MoFon:  So\ware  Mo]on  Detector.  

•  Provides  streaming  video  with  possibility  to  create  snapshots.  

•  Good  performance  on  the  Raspberry  PI.    •  PotenFal  side  project:  get  Robot  to  follow  moving  objects?  

Page 59: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Other  things  I  picked  up  •  Git  /  GitHub  

•  HTML5  

•  CSS  

•  Linux  

Page 60: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 61: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

NodeBot  Rover  Component  Overview  Hardware  

Raspberry    PI  

Arduberry  (Arduino)  

Pi  Cam  

Zumo  Chassis  

Servos  

SoAware  

HTML5  Speech  

Johnny-­‐Five  

Express  

MQTT  &  WebSocket  

TwiSer/MoFon/

Git/GitHub/CSS/Linux  

Page 62: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

So  Did  I  Get  My  Coding  Mojo  

Back?  

Page 63: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 64: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

Land   Turn  

Take-­‐off  

Page 65: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 66: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype
Page 67: JavaOne 2015 : How I Rediscovered My Coding Mojo by Building an IoT/Robotics Prototype

@markawest