IoT Tech Day Coding Mojo slides. Utrecht, April 2016

65
HOW I GOT BACK MY CODING MOJO! Mark West #iottechday

Transcript of IoT Tech Day Coding Mojo slides. Utrecht, April 2016

HOW I GOT BACK MY CODING MOJO!

Mark West#iottechday

WhatisMojo?

“AnyapplicationthatcanbewritteninJavaScript,willeventuallybewrittenin

JavaScript”

JamesAtwood(founder, stackoverflow.com)

NodeBot Rover

NodeBot RoverDemo

https://vimeo.com/162426456

NodeBot RoverComponentOverviewHardware

Computer

MicroController

Camera

Chassis

Pan&Tilt

Software

Speech

RobotControl

WebServer

Integration

Other

TheArduino Ecosystem• MicroController platform.

• ManydifferentArduinomodels.

• OpenSourcedesign.

• MicroControllers extensiblevia“Shields”.

Puttingthe HardwareTogether

Two ServosforCameraPan&Tilt

Servos wiredtoArduinoChassis

Raspberry PIInPlastic Case

WIFIDongle

Raspberry PICamera

Wired directlytothe

Raspberry PI

Actuators

Sensors

Nervous System

RaspberryPI2RaspberryPICam

ArduberryMicrocontroller Arduino Chassis Servo

Servo

Brain

NodeBot RoverHardware

Combining the Raspberry PI&ArduinoRaspberry PI

• LinuxPC.

• SupportsUSBperipherals.

• Programming.

ArduinoPlatform• MicroController.

• Robust.

• Nativeanalogue support.

Thewhole isgreater than the sumof parts!

Actuators

Sensors

Nervous System

RaspberryPI2RaspberryPICam

ArduberryMicrocontroller Arduino Chassis Servo

Servo

Brain

NodeBot RoverHardware

NodeBot RoverComponentOverviewHardware

RaspberryPI

Arduberry(Arduino)

PiCam

ZumoChassis

Servos

Software

Speech

RobotControl

WebServer

Integration

Other

RaspberryPI2

Arduberry

Servo

SoftwareCommunicationacrossHardwareLayers

Servo

Raspberry PI Chassis

JavaScriptPI Binary (Compiled C/C++)

TheNodeBots Movement

Source:nodebots.io

1. Maturity2. Community3. DSL4. Portability5. OpenSource6. Node.js ecosystem7. REPL

BenefitsofusingJohnny-Five

ImportsJ5Dependancy

Adds LEDinstance toREPL

Declares LEDasconnected toUNOPin13

BlinksLEDevery 500milliseconds

Codeblock triggered byUNO”Ready”Event

Initialises UNO

Johnny-FiveCodeExamplevar 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

});});

Johnny-FiveREPLDemo

https://vimeo.com/134953425

Arduberry

Servo

BridgingthegapwithFirmata

Servo

Raspberry PI Chassis

Johnny-Five(Firmata Client)

Std.Firmata(Firmata Server)

JavaScriptPI Binary (Compiled C/C++)

GettingStartedwithJohnny-Five1. BuyanArduino ExperimentersKit.

2. Followthetutorialsathttp://node-ardx.org.

3. Visithttp://johnny-five.io formoreinformationandinspiration.

NodeBot RoverComponentOverviewHardware

RaspberryPI

Arduberry(Arduino)

PiCam

ZumoChassis

Servos

Software

Speech

Johnny-Five

WebServer

Integration

Other

SpeechRecognitionRequirements

Needtohave

• Qualityandspeedofspeechrecognition.

• Free,norestrictions.• Softwarebased.• JavaScript.

Nicetohave

• Speechtotext.• Onestopservice.• Battletested.

WebSpeechAPI

(limitedtoGoogleChrome)

WebSpeechAPI:Configuration

WebSpeechAPI:Events

WebSpeechAPI:Control

SpeechDemo

Seehttps://vimeo.com/162426456 foranexampleofthespeechrecognitioninprogress.

ButtonpressandreleaseconnectedtoWebSpeechAPIstart andstop Control

methods.

Continuousdictationswitchedon, toavoidcuttingcommandsshort.

Interimresultsswitchedon– showningreentext(finalresultsinwhite).

Eachsetofresultscheckedforuniquenesstoavoidsendingduplicatecommandsto

theRobot.

WebSpeechAPI:Robot

NodeBot RoverComponentOverviewHardware

RaspberryPI

Arduberry(Arduino)

PiCam

ZumoChassis

Servos

Software

HTML5Speech

Johnny-Five

WebServer

Integration

Other

Node.jsExpressWeb

Server(17linesofcode)

NodeBot RoverComponentOverviewHardware

RaspberryPI

Arduberry(Arduino)

PiCam

ZumoChassis

Servos

Software

Speech

Johnny-Five

Express

Integration

Other

Johnny-FiveProcess

ExpressProcess

Raspberry PI2

WE

Browser

HTTPS

NodeBotRover

Hardware

Firmata

Johnny-FiveProcess

ExpressProcess

Raspberry PI2

WE

Browser

HTTPS

NodeBotRover

Hardware

Firmata

MQTTMessageBroker

MQTT

MQTToverWebSockets

Commands

Acknowledgements

MQTT.jsClient

MQTT.jsClient

Why Add aMessageBroker?

• Seperation ofconcerns.

• Isolate maincomponents foreasier testing.

MQTT– MQTelemetry Transport• Internet of Thingsconnectivityprotocol.

• Designed tobelightweightwith asmall footprint andlittleoverhead.

• Isaprotocoland aPub-SubMessageBroker.

• UsedbyFacebook forpushing updates tomobileclients.

Adding MQTTtothe NodeBot RoverBroker

• PublicMQTTBroker

– ManyPublicBrokersexist.– Onelessprocess torunon

Raspberry PI.

Client

• MQTT.js

– Provides anMQTTclientlibrary forNode.js.

– Extremely simpletouse.– Integrates seamlesslywith

Johnny-Five.

MQTT.js (Node.js)ClientExample

MQTTOverWebSockets with MQTT.js• MQTT.js isaNode.js package andis

meant foruse on the ServerSide.

• Toallow MQTT.js torunfromtheBrowser,we firstneeded to”Browserify”the MQTTlibrary.

• We could then access the”Browserified”MQTTclient libraryfromthe Browser.

• Thissolution requires that your MQTTBrokerhasaWebSocket endpoint.

MQTTOverWebSockets Demo

DemooftheHiveMQ WebSocket Clienthttp://www.hivemq.com/demos/websocket-

client

NodeBot RoverComponentOverviewHardware

RaspberryPI

Arduberry(Arduino)

PiCam

ZumoChassis

Servos

Software

HTML5Speech

Johnny-Five

Express

MQTT&WebSocket

Other

Node.js Twitter Client• Fully fledged Twitter Client:

– Asynchronous.– SupportsRESTAPI(read andwrite)– SupportsStreaming API(events andtweets).

• Requires developer credentials fromTwitter:– Trivialtoget holdof.

Node.js TwitterClientRESTExample

VideoStreaming viaMotion• Motion:SoftwareMotionDetector.

• Provides streaming videowith possibility tocreatesnapshots.

• Good performance on the Raspberry PI.

• Potential sideproject:get Robottofollow moving objects?

NodeBot RoverComponentOverviewHardware

RaspberryPI

Arduberry(Arduino)

PiCam

ZumoChassis

Servos

Software

HTML5Speech

Johnny-Five

Express

MQTT&WebSocket

Twitter &Motion

SoDid IGet MyCoding Mojo

Back?

ControllingaParrotDronewithMotionDetectorsandJavaScript

https://vimeo.com/137264033

“please rate my talk in the officalIoT Tech Day app”

@markawest