JavaScript models of interaction with the physical world
Use ← → keys to navigate the slides
You may block the camera access as they were used during live demos.





JavaScript running on hardware:
single-board computers or micro-controllers
| Processor | Architecture | OS | |
|---|---|---|---|
| My laptop | Intel Core i5 | x86 | MacOS |
| Tessel 2 | MediaTek MT7620 | MIPS | Linux (OpenWRT) |
| Raspberry PI 3 | Broadcom BCM2837 | ARM | Linux (Debian) |
| Beaglebone Black | Sitara AM335x | ARM | Linux (Debian) |
Node.js (ARM / MIPS) running on a tiny computer
with GPIO and wireless capabilities!



TesselRouter192.168.1.101
| Tessel | Tessel 2: MediaTek (Linux and WiFi), Atmel μ-controller |
|---|---|
| Servo | Tower Pro SG92 |
// File: index.js
// Run: t2 push index.js
var tessel = require('tessel')
var servoPin = tessel.port.A.pwm[0]
var app = require('express')()
var angle = 0
...
tessel.pwmFrequency(50)
servoPin.pwmDutyCycle(1/20)
app.get('/turn', function (req, res) {
angle += 30
servoPin.pwmDutyCycle(((angle)/180 + 1)/20) // move the servo
...
})




JavaScript tethered with firmata
| app | node-pixel | JS | laptop |
| firmata.js | JS | laptop | |
| serial-port | JS & C++ | laptop | |
| firmata sketch | Arduino (C++) | arduino uno | |
| arduino library | Arduino (C++) | arduino uno | |
| micro-controller | ATmega328p | binary | arduino uno |
| Neopixel | WS2812 has control circuit and RGB chip integrated |
|---|---|
| Arduino | micro-controller |
| Host | our laptop |
var five = require('johnny-five')
var pixel = require('node-pixel')
var board = new five.Board({ port: 8000 })
board.on('ready', function() {
ring = new pixel.Strip({
data: 6,
length: 60,
color_order: pixel.COLOR_ORDER.GRB,
board: this,
controller: 'FIRMATA',
})
ring.on('ready', function() {
app.get('/red', function(req, res) {
ring.color('#100')
ring.show()
res.redirect('/')
})
...
| JS lib | Firmata | Hardware |
|---|---|---|
| node pixel | node pixel | Neopixel |
| johnny-five | StandardFirmataPlus | plenty! |
| johnny-five | PingFirmata | hc-sr04 proximity |
| particle-io | voodootiki | particle photon |
Use nodebots-interchange to flash
custom firmata in your boards!





Hardware talking to the JavaScript server:
IoT Platform
| Wireless | Gateway | Range | Power | Data rate |
|---|---|---|---|---|
| BLE | Laptop | medium | low | low |
| WiFi | Router | medium | high | high |
| 4G | Cell Tower | wide | high | high |
| LoRaWAN | Receivers | wide | low | low |
| NB IoT | Cell towers | wide | low | low |
Low cost, low powered sensors running for years
IoT platform: get sensor data, visualise data, interpret data
| TI Sensor tag | Low powered BLE platform with sensors |
|---|---|
| Server | laptop or mobile with BLE capabilities |
var SensorTag = require('sensortag')
var app = require('express')()
var async = require('async')
var WebSocketServer = require('ws').Server
...
SensorTag.discover(function(sensorTag) {
async.series([
function(callback) {
console.log('Connected to Sensor Tag')
sensorTag.connectAndSetUp(callback)
},
function(callback) { sensorTag.enableIrTemperature(callback); },
function(callback) { setTimeout(callback, 2000); },
function(callback) {
sensorTag.readIrTemperature(function(error, objectTemperature, ambientTemperature) {
console.log('Temperature = %d °C', ambientTemperature.toFixed(1))
callback();
});
...




running on single-board computers or micro-controllers

communicating over firmata with boards and hardware


talking to wireless sensors via the Internet through gateways
One day Alice came to a fork in the road and saw a Cheshire cat in the tree.
"Which road should I take?" she asked.
"Where do you want to go?" was his response.
"I don't know" Alice answered.
"Then", said the cat,
"it doesn't matter"
Slides: talks.sayanee/alice
Demo code: GitHub