Share
Embed
Bending the IoT to your will with JavaScript
Brandon Satrom
October 25, 2018
Transcript
46 slides
-
BENDING THE IOT TO YOUR WILL WITH JAVASCRIPT Brandon Satrom
| @BrandonSatrom | [email protected] -
“ ” - Nikola Tesla MOBILE, CIRCA 1926 When wireless
is perfectly applied the whole earth will be converted into a huge brain, which in fact it is, all things being particles of a real and rhythmic whole… and the instruments through which we shall be able to do this will be amazingly simple compared with our present telephone. A man will be able to carry one in his vest pocket. -
34 BILLION Devices online by 2020 Spent on the IoT
(2016-2021) $6 TRILLION -
THE EVER-PRESENT GARTNER HYPE CYCLE PEAK OF INFLATED EXPECTATIONS TECHNOLOGY
TRIGGER TROUGH OF DISILLUSIONMENT SLOPE OF ENLIGHTENMENT PLATEAU OF PRODUCTIVITY VISIBILITY TIME IOT TODAY IOT TOMORROW! -
“THE IOT” IS A NEW, FOREIGN WORLD FOR MANY HARDWARE
ENGINEERS What a typical hardware engineer understands today -
THREE TYPES OF IOT APPS 1 2 3 IOT WEB
APPS IOT MOBILE APPS IOT CLOUD APPS -
THREE TYPES OF IOT APPS 1 2 3 IOT WEB
APPS IOT MOBILE APPS IOT CLOUD APPS -
HOW WEB APPS ENABLE THE IOT 1 IOT WEB APPS
DATA AGGREGATION AND VISUALIZATION EXTENSIBLE AND PLATFORM-AGNOSTIC -
OPTIONS FOR BUILDING IOT WEB APPS 1 2 GET DATA
FROM YOUR DEVICES BUILD YOUR APP MQTT TCP Pub/Sub Particle Pub/Sub -
PARTICLE PUBLISH AND SUBSCRIBE double tempC = 0; void setup()
{ Particle.variable("temp", tempC); pinMode(A0, INPUT); } void loop() { analogvalue = analogRead(A0); tempC = (((analogvalue * 3.3) / 4095) - 0.5) * 100; if (tempC > 120) { Particle.publish("temp/critical", tempC); } else if (tempC > 80) { Particle.publish("temp/warning", tempC); } } void setup() { !// Subscribes to temp/warning AND temp/critical Particle.subscribe("temp", handleTemp); } void handleTemp(const char *event, const char *data) { double temp = extractTemp(data); if (temp > 120) { deactivatePump(); } else if (temp > 80) { reducePumpSpeed(); } } -
THE PARTICLE DEVICE CLOUD API # API Call # GET
/v1/events/{EVENT_NAME} # EXAMPLE REQUEST curl -H "Authorization: Bearer {ACCESS_TOKEN_GOES_HERE}" \ https:!//api.particle.io/v1/events/temp/critical # Will return a stream that echoes text when your event is published event: temp/critical data: {"data":"125","ttl":"60","published_at":"2018-05-28 T19:20:34.638Z", "deviceid":"0123456789abcdef"} -
THE PARTICLE JS LIBRARY const Particle = require('particle-api-js'); const particleAPI
= new Particle(); const token = process.env.PARTICLE_TOKEN; const particle = { listDevices: () !=> { return new Promise((resolve, reject) !=> { particleAPI .listDevices({ auth: token }) .then(devices !=> resolve(devices)) .catch(err !=> reject(err)); }); }, deviceFunctions: deviceName !=> { return new Promise((resolve, reject) !=> { particleAPI .listDevices({ auth: token }) .then(devices !=> { const device = devices.body.filter(device !=> device.name !!=== deviceName)[0]; return device.id; .then(id !=> { return particleAPI.getDevice({ deviceId: id, auth: token }); }) .then(device !=> { resolve(device.body.functions); }).catch(err !=> reject(err)); }); }}; -
THREE TYPES OF IOT APPS 1 2 3 IOT WEB
APPS IOT MOBILE APPS IOT CLOUD APPS -
HOW MOBILE APPS ENABLE THE IOT VISUALIZATION AND CONTROL PORTABLE
AND UBIQUITOUS 2 IOT MOBILE APPS -
OPTIONS FOR BUILDING IOT MOBILE APPS 1 2 3 NATIVE
APPS GENERIC CONTROLLER APP CROSS-PLATFORM -
SDKS FOR MOBILE DEVELOPMENT myPhoton!.getVariable("temperature", completion: { (result:Any?, error:Error?) !->
Void in if let _ = error { print("Failed reading temperature from device") } else { if let temp = result as? NSNumber { print("Room temp is \(temp.stringValue) degrees") } } }) List<ParticleDevice> devices = ParticleCloudSDK.getCloud().getDevices(); for (ParticleDevice device : devices) { if (device.getName().equals("myDevice")) { doSomethingWithMyDevice(device); break; } } ParticleDevice myDevice = null; List<ParticleDevice> devices = ParticleCloud.SharedCloud.GetDevicesAsync(); foreach (ParticleDevice device in devices) { if (device.Name().equals("myDeviceName")) myDevice = device; } [myPhoton getVariable:@"temperature" completion:^(id result, NSError *error) { if (!error) { NSNumber *temperatureReading = (NSNumber *)result; NSLog(@"Room temperature is %f degrees",temperatureReading.floatValue); } else { NSLog(@"Failed reading temperature from Photon"); } }]; -
THE NATIVESCRIPT PARTICLE PLUGIN listDevices(): void { this.devices.splice(0, this.devices.length); this.set(HelloWorldModel.SELECTED_DEVICE_KEY,
undefined); this.particle.listDevices() .then(devices !=> { if (devices.length !!=== 0) { this.set(HelloWorldModel.MESSAGE_KEY, "No devices have been claimed in this account."); } else { this.set(HelloWorldModel.MESSAGE_KEY, "Select a device below:"); } this.devices.push(devices); }) .catch(error !=> this.set(HelloWorldModel.MESSAGE_KEY, error)); } onDeviceTap(args): void { this.set(HelloWorldModel.SELECTED_DEVICE_KEY, this.devices.getItem(args.index)); this.set(HelloWorldModel.MESSAGE_KEY, `Selected: ${this.selectedDevice.name}`); } -
THREE TYPES OF IOT APPS 1 2 3 IOT WEB
APPS IOT MOBILE APPS IOT CLOUD APPS -
HOW CLOUD APPS ENABLE THE IOT INSIGHT & CONTROL (NEARLY)
INFINITE COMPUTATIONAL POWER 3 IOT CLOUD APPS -
OPTIONS FOR BUILDING IOT CLOUD APPS 1 2 3 CLOUD
BACKHAUL CLOUD WORKFLOW CLOUD PROCESSING -
NODE-BASED, WITH CLOUD INTEGRATIONS WHAT CAN I DO WITH THE
IOT RULES ENGINE? Real-time alerting Device commands Data management Visualizations & analytics Fleet-wide Remote Diagnostics OTA firmware automation Node.js runtime Built-in Cloud Integrations -
“ ” - L.P. Jacks WORK == PLAY The master
in the art of living makes little distinction between work and play