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

An Introduction To IoT (Internet of Toilets 🚽)...

An Introduction To IoT (Internet of Toilets 🚽); Or How I Built an IoT Kitty Litter Box Using JavaScript - 20 Mins

My favorite things in life are cats 🐈, computers 🖥 and crappy ideas 💩, so I decided to combine all three and make an IoT (Internet of Things) litter box using a Raspberry Pi and JavaScript! If you have ever wanted to get build your own IoT project, but didn’t know how to start, then this is the talk for you.

Together, we will go through how I setup my IoT Litter Box from start to finish. Including how to setup Node.js on a Raspberry Pi and how to connect sensors to a Raspberry Pi and how to read the sensor inputs with Node.js.

Joe Karlsson

June 25, 2020
Tweet

More Decks by Joe Karlsson

Other Decks in Programming

Transcript

  1. { name: “Joe Karlsson”, company: “MongoDB”, title: [ “Developer Advocate”,

    “Software Engineer” ], } twitter: “@JoeKarlsson1”, twitch: “joe_karlsson”, tiktok: “joekarlsson”, website: “joekarlsson.com”, opinions: “my own”, links: “bit.ly/IoTKittyBox”
  2. @JoeKarlsson1 Agenda • Intro to IoT • Why JS &

    IoT? • IoT Kitty Litter Box • The future of IoT @JoeKarlsson1
  3. @JoeKarlsson1 Agenda • Intro to IoT • Why JS &

    IoT? • IoT Kitty Litter Box • The future of IoT @JoeKarlsson1
  4. @JoeKarlsson1 Why Node? 58 percent of respondents that identified as

    IoT developers use Node Source: https:/ /nodejs.org/en/blog/announcements/nodejs-foundation-survey/ @JoeKarlsson1
  5. @JoeKarlsson1 JS is a great choice for new devs Other

    low level programming languages can be difficult to develop @JoeKarlsson1
  6. @JoeKarlsson1 Agenda • Intro to IoT • Why JS &

    IoT? • IoT Kitty Litter Box • The future of IoT @JoeKarlsson1
  7. @JoeKarlsson1 var five = require("johnny-five"); var Raspi = require("raspi-io").RaspiIO; var

    board = new five.Board({ io: new Raspi() }); board.on("ready", function() { var led = new five.Led("P1-13"); led.blink(); });
  8. @JoeKarlsson1 const { RaspiIO } = require('raspi-io'); const five =

    require(‘johnny-five'); const board = new five.Board({ io: new RaspiIO(), }); let state = { isMaintenenceMode: false, }; board.on('ready', () => { const spdt = new five.Switch('GPIO16'); spdt.on('open', () => { state.isMaintenenceMode = true; }); spdt.on('close', () => { state.isMaintenenceMode = false; }); });
  9. @JoeKarlsson1 const spawn = require('child_process').spawn; const process = spawn('python', ['./hx711py/scale.py'],

    { detached: true }); // Takes stdout data from script which executed // with arguments and send this data to res object process.stdout.on('data', data => { let currWeight = parseFloat(data); let avgWeight = updateAverageWeight(currWeight, recentsWeights); }); process.stderr.on('data', err => { console.error(err); }); process.on('close', (code) => { console.log(`child process exited with code ${code}`); });
  10. { "_id": { "$oid": "dskfjlk2j92121293901233" }, "timestamp_day": { "$date": {

    "$numberLong": "1573854434214" } }, "type": "cat_in_box", "cat": { "name": "BMO", "weight": "200" }, "owner": "Joe Karlsson", "events": [ ] } IoT Time Series Schema { "timestamp_event": { "$date": { "$numberLong": "1573854435016" } }, "weight": { "$numberDouble": “15.593333333" } }, { "timestamp_event": { "$date": { "$numberLong": "1573854435824" } }, "weight": { "$numberDouble": "15.132222222" } }, { "timestamp_event": { "$date": { "$numberLong": "1573854436632" } }, “type”: “maintenance” } @JoeKarlsson1
  11. @JoeKarlsson1 Agenda • Intro to IoT • Why JS &

    IoT? • IoT Kitty Litter Box • The future of IoT @JoeKarlsson1
  12. @JoeKarlsson1 Smaller and more powerful devices \ Better Hardware support

    JS with a smaller footprint Batteries will become the bottleneck The Future of JS + IoT? @JoeKarlsson1
  13. @JoeKarlsson1 All resources and links used in this talk can

    be found here: @JoeKarlsson1 bit.ly/IoTandJS
  14. { name: “Joe Karlsson”, company: “MongoDB”, title: [ “Developer Advocate”,

    “Software Engineer” ], twitter: “@JoeKarlsson1”, twitch: “joe_karlsson”, website: “joekarlsson.com”, links: “bit.ly/IoTKittyBox” }
  15. @JoeKarlsson1 •Source Code - http://bit.ly/IotKittyBox • IoT Reference Architecture -

    https:// www.mongodb.com/collateral/iot-reference- architecture •Time Series Data and MongoDB: Best Practices Guide - https://www.mongodb.com/ collateral/time-series-best-practices Additional Resources