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

2411e1b8fa28ddd0c8071dc4aec1c5a1?s=128

Brandon Satrom

October 25, 2018
Tweet

Transcript

  1. BENDING THE IOT TO YOUR WILL WITH JAVASCRIPT Brandon Satrom

    | @BrandonSatrom | brandon@particle.io
  2. THE CURRENT STATE OF THE INTERNET OF THINGS

  3. “ ” - 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.
  4. 34 BILLION Devices online by 2020 Spent on the IoT

    (2016-2021) $6 TRILLION
  5. 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!
  6. THE EXIT “THE TROUGH,” THE IOT MUST SOLVE REAL PROBLEMS

  7. SMARTFIN

  8. None
  9. ENVIROFIT

  10. FROM CLOSED TO OPEN

  11. FROM CLOSED TO OPEN

  12. IoT Solutions are about much more than embedded hardware &

    firmware
  13. “THE IOT” IS A NEW, FOREIGN WORLD FOR MANY HARDWARE

    ENGINEERS What a typical hardware engineer understands today
  14. JAVASCRIPT: THE COMMON DENOMINATOR

  15. THREE TYPES OF IOT APPS 1 2 3 IOT WEB

    APPS IOT MOBILE APPS IOT CLOUD APPS
  16. IoT Builders are the real full-stack developers

  17. THREE TYPES OF IOT APPS 1 2 3 IOT WEB

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

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

    FROM YOUR DEVICES BUILD YOUR APP MQTT TCP Pub/Sub Particle Pub/Sub
  21. 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(); } }
  22. https://api.<your-iot-service>.com/v1

  23. YOU NEED A GOOD API

  24. 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"}
  25. 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)); }); }};
  26. DEMO THE PARTICLE JS LIBRARY

  27. THREE TYPES OF IOT APPS 1 2 3 IOT WEB

    APPS IOT MOBILE APPS IOT CLOUD APPS
  28. HOW MOBILE APPS ENABLE THE IOT VISUALIZATION AND CONTROL PORTABLE

    AND UBIQUITOUS 2 IOT MOBILE APPS
  29. EXAMPLE: THE BLYNK APP

  30. OPTIONS FOR BUILDING IOT MOBILE APPS 1 2 3 NATIVE

    APPS GENERIC CONTROLLER APP CROSS-PLATFORM
  31. 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"); } }];
  32. 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}`); }
  33. DEMO PARTICLE + NATIVESCRIPT

  34. THREE TYPES OF IOT APPS 1 2 3 IOT WEB

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

    INFINITE COMPUTATIONAL POWER 3 IOT CLOUD APPS
  36. EXAMPLE: ELECTRIC IO

  37. OPTIONS FOR BUILDING IOT CLOUD APPS 1 2 3 CLOUD

    BACKHAUL CLOUD WORKFLOW CLOUD PROCESSING
  38. THE PARTICLE IOT RULES ENGINE

  39. 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
  40. DEMO THE IOT RULES ENGINE

  41. A WORD ABOUT “REAL IOT”

  42. “ ” - L.P. Jacks WORK == PLAY The master

    in the art of living makes little distinction between work and play
  43. SOLVING REAL PROBLEMS THROUGH PLAY

  44. SOLVING REAL PROBLEMS THROUGH PLAY

  45. BECOME A FULLER-STACK DEVELOPER TODAY!

  46. THANKS! @BRANDONSATROM BRANDON@PARTICLE.IO