Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bending the IoT to your will with JavaScript

Bending the IoT to your will with JavaScript

Brandon Satrom

October 25, 2018
Tweet

More Decks by Brandon Satrom

Other Decks in Technology

Transcript

  1. “ ” - 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.
  2. 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!
  3. “THE IOT” IS A NEW, FOREIGN WORLD FOR MANY HARDWARE

    ENGINEERS What a typical hardware engineer understands today
  4. THREE TYPES OF IOT APPS 1 2 3 IOT WEB

    APPS IOT MOBILE APPS IOT CLOUD APPS
  5. THREE TYPES OF IOT APPS 1 2 3 IOT WEB

    APPS IOT MOBILE APPS IOT CLOUD APPS
  6. HOW WEB APPS ENABLE THE IOT 1 IOT WEB APPS

    DATA AGGREGATION AND VISUALIZATION EXTENSIBLE AND PLATFORM-AGNOSTIC
  7. OPTIONS FOR BUILDING IOT WEB APPS 1 2 GET DATA

    FROM YOUR DEVICES BUILD YOUR APP MQTT TCP Pub/Sub Particle Pub/Sub
  8. 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(); } }
  9. 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"}
  10. 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)); }); }};
  11. THREE TYPES OF IOT APPS 1 2 3 IOT WEB

    APPS IOT MOBILE APPS IOT CLOUD APPS
  12. OPTIONS FOR BUILDING IOT MOBILE APPS 1 2 3 NATIVE

    APPS GENERIC CONTROLLER APP CROSS-PLATFORM
  13. 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"); } }];
  14. 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}`); }
  15. THREE TYPES OF IOT APPS 1 2 3 IOT WEB

    APPS IOT MOBILE APPS IOT CLOUD APPS
  16. HOW CLOUD APPS ENABLE THE IOT INSIGHT & CONTROL (NEARLY)

    INFINITE COMPUTATIONAL POWER 3 IOT CLOUD APPS
  17. OPTIONS FOR BUILDING IOT CLOUD APPS 1 2 3 CLOUD

    BACKHAUL CLOUD WORKFLOW CLOUD PROCESSING
  18. 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
  19. “ ” - L.P. Jacks WORK == PLAY The master

    in the art of living makes little distinction between work and play