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

Build your own IoT

Build your own IoT

A short presentation on how I built my own temperature and humidity monitoring system. Presented at WebCamp Slovenia 2017.

Jernej Virag

April 22, 2017
Tweet

More Decks by Jernej Virag

Other Decks in Technology

Transcript

  1. Build your own IoT Because buying things from Amazon is

    for lazy people. Jernej Virag @jernejv
  2. What do we need? • Data-collection device and storage space

    • Temperature and humidity sensor in each of the rooms • A way to transfer data from sensors to device
  3. Collection and storage • One (1) Raspberry Pi (1st gen)

    with 16GB of SD card • With WiFi adapter (optional) • With screen (optional)
  4. Sensors • Turns out sensors aren't that cheap and need:

    • Microcontroller to plug them into • Power supply • Chasis / box to put them into • Can use a lot of power which causes issues with battery power supply
  5. Weather stations • Sensors already prepackaged • Low power usage

    (running months on a pair of AAA batteries) • Protected against environment (can be used outdoor even in winter) • Standard 433MHz transcievers • Long range (15m+)
  6. Receiving data • Keyword - RTL-SDR (software defined radio) •

    RTL2832U chip - natively supported in Linux
  7. Getting sensor data • Collecting data from unknown radio sensors

    can be annoying - there's no documentation. • BUT.... we're in luck - https://github.com/merbanan/rtl_433
  8. KISS principle • RPi isn't a fast device - let's

    make it as lean as possible • Small python script (daemon) running rtl_433 and reading JSON input • Storing data into SQLite database • Small python script serving collected data via JSON • Static HTML/JS user interface served from RPi via nginx
  9. Software choice • DietPi Debian distribution running on RPi •

    Python 3.x • Peewee ORM • Flask web framework • SQLite storage
  10. Python daemon • Called tempsd.py • Uses subprocess to run

    `rtl_433` with JSON as output option • Reads input, parses JSON and saves each reading into SQLite database • Maps sensor ID to room name enum (hardcoded for now =( ) Source on GitHub: https://github.com/izacus/house-temperatures
  11. Python server • Called serverd.py • Two JSON endpoints •

    /current_status - returns current temperatures, time of reading, battery • /graph/<N> - returns hourly grouped data for sensor number N Source on GitHub: https://github.com/izacus/house-temperatures
  12. UI • Simple static index.html served from RPi • Dashboard

    CSS for visual design - https://github.com/hpoydar/dashboard- css • Plotly.js for graphs - https://plot.ly/javascript/ Source on GitHub: https://github.com/izacus/house-temperatures
  13. What went wrong? • RPi corrupted the SD-card losing all

    data and breaking the system • Lesson - don't store data on volatile storage, do backups • One of the sensors doesn't support humidity • It'd be great if the solution wouldn't cost more than off-the-shelf stuff
  14. // TODO • User interface for the touchscreen • Could

    be headless Chrome/Firefox running the same index.html and refreshing periodically • Rather light Qt-based interface for better performance • Better data backup system