name: inverse class: center, middle, inverse layout: true .header[.floatleft[.teal[Christopher Biggs] — Two Minute IoT].floatright[.logo[@accelerando_au]]] .footer[.floatleft[BrisJS Jul 2017]] --- layout: true class: bulletsh4 .header[.floatleft[.teal[Christopher Biggs] — Two Minute IoT].floatright[.logo[@accelerando_au]]] .footer[.floatleft[BrisJS Jul 2017]] --- template: inverse # Two Minute IoT ## Up and running in two minutes with Mongoose OS and AWS IoT .bottom.right[ Christopher Biggs, .logo[Accelerando Consulting]
.logo[@accelerando_au] ] --- layout: true class: bulletsh4 .header[.floatleft[.teal[Christopher Biggs] — Two Minute IoT].floatright[.logo[@accelerando_au]]] .footer[.floatleft[BrisJS Jul 2017]] .crumb[ # Agenda ] --- .fig50[ ] # Platform Desiderata #### Well documented, multi-supplier #### Comprehensive identity management #### Scriptable tools, no-hands deploy #### Cloud managed #### Field upgradeable #### Disconnection-tolerant --- class: tight # Enter the Mongoose (OS) .fig60[ ] #### Supports four different CPUs #### Toolchain on Linux, MacOS, Windows #### Web IDE, plus command-line tools #### Develop over USB or WiFi #### Integrated with AWS and Google IoT #### Over-the-air updates via push or pull #### Extensible API callable via serial, websockets, REST, MQTT #### Arduino API compatible #### Code in C, C++ or **.red[JavaScript]** --- layout: true class: bulletsh4 .header[.floatleft[.teal[Christopher Biggs] — Two Minute IoT].floatright[.logo[@accelerando_au]]] .footer[.floatleft[BrisJS Jul 2017]] .crumb[ # Agenda # Platform ] --- # MongooseOS platform #### Based in Dublin (cesanta.com) #### Ex Googler Sergey Lyubka et.al. #### Started as embedded web server, expanded to whole OS #### Dual License, GPL or Commercial #### Supports CPUs from Espressif (.cn), TI (.us) , ST (.ch) --- .fig50[ ] # Espressif ESP8266 and ESP32 #### WiFi microcontrollers originally for wifi backpacks and appliances #### C-lang SDK from manufacturer #### Open source runtimes * Arduino (C++) * NodeMCU (Lua) * MicroPython * Mongoose OS (JS) --- layout: true class: bulletsh4 .header[.floatleft[.teal[Christopher Biggs] — Two Minute IoT].floatright[.logo[@accelerando_au]]] .footer[.floatleft[BrisJS Jul 2017]] .crumb[ # Agenda # Platform # Development ] --- class: autodim # Micro Javascript #### An ES6 subset -- #### a very small subset! 25k FLASH, 1k RAM. -- #### No standard library, but #### Dead easy calls to the MOS C stdlib ```javascript Timer.set(1000, true, function(arg) { let now = ffi('unsigned long mg_time()')(); let topic = Cfg.get('device.id') + '/event/close'; let message = JSON.stringify({ time: now }); }, null); ``` --- # Mongoose OS Toolchain * Compile from Go source on github * One-line shell paste to install released binary * Interactive setup wizard * Device talks RPC on serial port (unlike most others) * Command line mos tool ``` mos ls mos put init.js mos get init.js mos flash aws-esp8266 mos wifi MyNetwork MySekritPassword mos aws-iot-setup ``` * Web IDE ``` .mos/bin/mos ui ``` --- # Mongoose OS Toolchain - IDE .fig60[ ] .fig7[ ] #### File browser and editor #### Project and library manager #### Configuration editor #### RPC Inspector #### Terminal #### Log viewer --- class: tight # Connecting your device #### Direct USB * MacOS driver support (or rather vendor device IDs) can be iffy * No USB A? Get a $15 ARM linux box to use as a dongle. * Golang IDE listens on http://localhost:1992/ * Docker containers: http://github.com/unixbigot/mongoose-os/ * The IDE server uses the RPC api to interact with the device, so... #### Internet * ...you can develop over the network! * `mos ui ws://some.ip.address:1992/` * Maybe set a password, eh? --- class: vtight .fig60[ ] ## Easy enrol in AWS and Google cloud #### Get an AWS account #### Install the AWS cli ``` pip install --upgrade awscli ``` #### Put your api key in `~/.aws/credentials`, then ``` mos wifi WIFI_SSID WIFI_PASSWORD mos config-set mqtt.enable=true mos aws-iot-setup --aws-iot-policy=mos-default mos console ``` The `aws-iot-setup` invocation enrols the device, and then requests and installs SSL client certificates on the device. --- ## What can you do with AWS IoT console .fig60[ ] #### See your device registry #### Manage certificates #### Listen to and send MQTT messages #### View and modify Device shadow #### Define Rules --- class: vtight ## Wait, rules, messages, shadows? .fig50[ ] #### MQTT is a publish-subscribe message system * Messages have a topic (think filename) and body (text or JSON) #### AWS is mostly standard MQTT, except * Limited QoS options. * No "retained publish", instead... * A "device shadow" document allows updates to happen offline. * Shadow updates propagate via MQTT on special topics eg `$aws/things/SOME_ID/shadow/update`. * Who knows what happened when a device was offline? -- * .red[The Shadow Knows!!!] --- class: vtight ## Interacting with your Thing  #### Plain old MQTT is fine if you don't care about LoS #### Send all interactions via the shadow document to cope with disconnects #### But if you want to react to events, go back to MQTT -- ## IoT rules #### When a message with TOPIC A (and PAYLOAD B) arrives, do ACTION C -- #### Actions can be * Database inserts * Push notifications * Re-queue to MQTT, Kinesis, SQS, Salesforce, Cloudwatch * Store to S3, and... -- * .red[**Invoke a Lambda Function**] --- layout: true class: bulletsh4 .header[.floatleft[.teal[Christopher Biggs] — Two Minute IoT].floatright[.logo[@accelerando_au]]] .footer[.floatleft[BrisJS Jul 2017]] .crumb[ # Agenda # Platform # Development # Deployment ] --- # Interlude - packaging and updates #### You can get a long way with `mos ls`, `mos get` and `mos put`, #### The IDE lets you browse and edit files, including the MJS APIs #### Firmwares are zipfiles, `mos flash` fetches or builds a zip #### You can use the RPC Api to instruct a device to fetch a zip #### Devices can poll on their own --- # Interlude - Library and Project management #### New in Mongoose THIS WEEK #### Browse and fetch Libraries for extra stuff (eg LCD screens) #### A number of sample apps - YAML library spec, C and/or JS code #### Create your own libs and apps by cloning the empty app #### The AWS demo app is a good place to start #### Good collection of tutorials and videos at mongoose-os.com --- layout: true class: bulletsh4 .header[.floatleft[.teal[Christopher Biggs] — Two Minute IoT].floatright[.logo[@accelerando_au]]] .footer[.floatleft[BrisJS Jul 2017]] .crumb[ # Agenda # Platform # Development # Deployment # Demo Demons ] --- .fig50[ ] # Demo Demons, I Invoke Thee! ### Let's make a medication reminder #### Have I opened the medicine box today? #### Should I have done so by now? #### Did I leave without doing it? **Hilarious Live Demo Goes Here** --- layout: true class: bulletsh4 .header[.floatleft[.teal[Christopher Biggs] — Two Minute IoT].floatright[.logo[@accelerando_au]]] .footer[.floatleft[BrisJS Jul 2017]] .crumb[ # Agenda # Platform # Development # Deployment # Demo Demons # Tips ] --- # Some tips ## Put a delay in init.js in case of crash loops ## Do something visible at the end of init.js (eg. flash onboard LED) ## Create and test your Lambda functions first, then set up IoT rules --- .crumb[ # Agenda # Platform # Development # Deployment # Demo Demons # Coda ] ## Summary #### Choose a full service embedded OS that skips the drudgery * Provisionoing * Management * Message transport #### Ensure you have a "DevOps Ready" toolchain #### Field upgrades are a **must have** #### Avoid low level languages if you can. --- class: small .crumb[ # Landscape # Challenges # Solutions # Coda ## Summary ## Resources ] ## Resources, Questions #### Mongoose OS - [github.com/cesanta/mongoose-os](https://github.com/cesanta/mongoose-os) #### Related talks - [http://christopher.biggs.id.au/#talks](http://christopher.biggs.id.au/#talks) #### Me - Christopher Biggs - Twitter: .blue[@unixbigot] - Email: .blue[christopher@biggs.id.au] - Slides, and getting my advice: http://christopher.biggs.id.au/ - Accelerando Consulting - IoT, DevOps, Big Data - https://accelerando.com.au/ ??? Thanks for your time today, I'm happy to take questions in the few moments remaining and I'm here all week if you want to have a longer chat. Over to you.