$30 off During Our Annual Pro Sale. View Details »

Drive your own IoT device in a snap with cloud services

Drive your own IoT device in a snap with cloud services

Based on an inexpensive board (Raspberry Pi 3), a couple of sensors, basic Python code and Google Cloud Platform, see how easy it is to build your own home monitoring device.

Laurent Picard

November 16, 2018
Tweet

More Decks by Laurent Picard

Other Decks in Programming

Transcript

  1. Drive your own IoT device in a snap with cloud

    services Laurent Picard @PicardParis PyCon Balkan November 16, 2018
  2. Laurent Picard - @PicardParis - Developer Advocate ‒ Google Cloud

    Platform - Co-founder & CTO of Bookeen - Co-creator of 1st European ebook reader Who are you? - Developers? - Raspberry users? - IoT device users? - Cloud users? Let’s get to know each other
  3. 01 Meet Raspberry Pi 02 Meet Google Cloud 03 Some

    action! 04 ... Agenda
  4. Meet… …Raspberry Pi

  5. Raspberry Pi Raspberry Pi (RPI) - Foundation (UK-based charity) -

    Credit-card-sized computer - 19 million RPIs sold Latest Version - Raspberry Pi 3 Model B+ (3.14'18) - Broadcom quad-core Cortex-A53 @1.4GHz - ≈35€ - raspberrypi.org/ products/raspberry-pi-3-model--b-plus Alternatives Arduino, Beagleboard, Pine A64, Asus Tinker Board, C.H.I.P. Pro, XYZ Pi...
  6. Rainbow Hat Pimoroni - UK-based company - Pirate, Monkey, Robot,

    Ninja (Pi-Mo-Ro-Ni) Outputs - x4 alphanum segmented displays - x7 RGB LEDs - Piezo buzzer Inputs - x3 capacitive buttons (+ LEDs) - Temperature and pressure sensor
  7. Meet… …Google Cloud

  8. Compute Big Data BigQuery Cloud Dataflow Cloud Dataproc Cloud Datalab

    Cloud Pub/Sub Genomics Storage & Databases Cloud Storage Cloud Bigtable Cloud Datastore Cloud SQL Cloud Spanner Persistent Disk Machine Learning Cloud Machine Learning Cloud Vision API Cloud Speech API Cloud Natural Language API Cloud Translation API Cloud Jobs API Data Studio Cloud Dataprep Cloud Video Intelligence API Advanced Solutions Lab Compute Engine App Engine Container Engine GPU Cloud Functions Container- Optimized OS Identity & Security Cloud IAM Cloud Resource Manager Cloud Security Scanner Key Management Service BeyondCorp Data Loss Prevention API Identity-Aware Proxy Security Key Enforcement Internet of Things Cloud IoT Core Data Transfer Appliance Google Cloud Platform
  9. Google Cloud Platform Developer Tools Cloud SDK Cloud Deployment Manager

    Cloud Source Repositories Cloud Tools for Android Studio Cloud Tools for IntelliJ Cloud Tools for PowerShell Cloud Tools for Visual Studio Container Registry Google Plug-in for Eclipse Cloud Test Lab Networking Virtual Private Cloud Cloud Load Balancing Cloud CDN Cloud Interconnect Cloud DNS Cloud Network Cloud External IP Addresses Cloud Firewall Rules Cloud Routes Cloud VPN Management Tools Stackdriver Monitoring Logging Error Reporting Trace Debugger Cloud Deployment Manager Cloud Endpoints Cloud Console Cloud Shell Cloud Mobile App Cloud Billing API Cloud APIs Cloud Router Cloud Partner Interconnect Container Builder
  10. Some action!

  11. Live demo

  12. “ No servers will be harmed during this demo #Serverless

  13. “ A Raspberry Pi might be harmed during this demo

    #EmbeddedDev
  14. Starting from scratch NOOBS (New Out Of Box Software) -

    raspberrypi.org/documentation/installation/n oobs.md Micro SD - 8 GB mininum From development computer - Format micro SD card - Download NOOBS (1.7 GB) - Unzip/copy NOOBS root to SD root - ⌛ < 5 min
  15. Installing Raspbian OS From Raspberry - Insert micro SD card

    - Plug USB keyboard + mouse - Plug monitor (HDMI or adaptor) - Power the RPI - Select Raspbian - Install - ⌛ ≈ 12 min
  16. Desktop vs headless modes Desktop - Monitor - Mouse -

    Keyboard Headless - Console - Development computer Before going headless, make sure to enable - SSH - Serial
  17. Change default settings Raspberry - Enable SSH - Enable Serial

    - Shutdown
  18. “ With a headless device, not having a serial console

    will get you blind at the worst times #MurphysLaw
  19. USB to serial cable Example - https://www.adafruit.com/product/954 - ~10€ 4

    wires Ground 0 V TX 3.3 V RX 3.3 V Power 5 V
  20. Serial connection Serial connection configuration (UART0) - 3 wires: GND,

    RX, TX (mandatory) - Power wire: 5V (if not USB powered) - Baud rate: 115,200 - Data bits: 8 - Stop bits: 1 - Parity: None - Flow control: None 2 power options - Power via micro USB (stable power supply) - Power via serial (if not using peripherals)
  21. “ Use a proper power supply or I’ll behave in

    unusual ways #GimmeStablePower
  22. Serial console Pros - Universal low-level connection - Shows OS

    boot info - Stays connected as long as USB is plugged Con - Slower than SSH (over Ethernet or Wi-Fi)
  23. Customization Make the environment your own - User password -

    Hostname - Prompt - Aliases... Interfacing options (for Rainbow HAT) - Enable SPI - Enable I2C Pros - Time saver - Comfort ┌─────────┤ ├──────────┐ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └────────────────────────────────────────────────────────────────────── ────────┘
  24. Ethernet Auto - Local network - Works out of the

    box with DHCP Example of manual configuration - Private RPI ↔ computer network - Share laptop Wi-Fi Internet connection
  25. SSH Pros - Universal network secure shell - Fast throughput

    - Can complement or replace serial conn. Cons - Only available once Linux has started - Restart connection after every boot Notes - SSH was enabled upon first boot - Use hostname rather than varying IP …
  26. Up to date? Make sure your system is up to

    date - 1 command - 1 validation - Automated update - Reboot - ⌛ ≈ 3 min ⌛ ⌛
  27. “ Update your Raspberry Take a 3 minute pause now

    Save hours later #TimeForCoffee
  28. Wi-Fi Pro - Autonomous Raspberry Con - SSH connection might

    be harder depending on configurations Note - Define your country to use the right range of frequencies
  29. Dev environment Preinstalled dev envs - C/C++ - Java -

    Node.js - Python - Ruby - + many others Preinstalled Python packages - numpy - Flask/Jinja2 - Rainbow HAT! - RPi.GPIO!
  30. SFTP remote development Raspberry - Make sure you can ping

    it from your computer (Ethernet or Wi-Fi) - Create dev folder Example: VS Code - Install “sftp” package - SFTP: config Choose development folder - Adapt sftp.json - Files automatically uploaded on save
  31. Rainbow HAT – Display

  32. Rainbow HAT – LEDs

  33. Rainbow HAT – Buzzer …

  34. Rainbow HAT – Capacitive buttons (+ LEDs)

  35. Rainbow HAT – Pressure & temperature

  36. “ Sensors to skill? Calibrate you will! #adoYretsaM

  37. Rainbow HAT – Calibrated temperature

  38. Streaming device metrics Metrics Warehouse Analysis Streaming

  39. Streaming device metrics to BigQuery Metrics Warehouse Analysis Streaming

  40. Preparing the code for streaming (row based)

  41. Google Cloud Project One console to rule them all console.cloud.google.com

    Create your own project - Project ID
  42. Google Cloud SDK ⌛ ⌛

  43. gcloud initialization ⌛ ⌛ Note: use the serial console (or

    SSH without X11 forwarding), otherwise authentication will try to launch a web page on the Raspberry
  44. BigQuery client library ⌛ ⌛

  45. BigQuery table

  46. Streaming metrics to BigQuery Flush to BigQuery every 5 samples

  47. More?

  48. “ When I’m not at home, how can I pilot

    my device? #ConsideringComplexSolution
  49. Piloting the device with Pub/Sub Metrics Warehouse Async Messaging Publication

    Subscription Analysis Streaming
  50. Pub/Sub client library … ⌛ ⌛

  51. Pub/Sub client library

  52. “ My device generates many/big files. How can I store

    them? #ConsideringExternalDrive
  53. Storing device files to Cloud Storage Metrics Warehouse Async Messaging

    Media Vault Storage Publication Subscription Analysis Streaming
  54. Cloud Storage client library ⌛ ⌛

  55. “ The Rainbow HAT is very simple. Isn’t it more

    complicated for real? #Doubtful
  56. Capturing a video stream from a USB webcam ⌛ ⌛

  57. “ Does everything work altogether? #LetsCheck

  58. Combine everything

  59. “ I regularly update my code. How to update my

    device? #WhatAboutMicroServices
  60. Triggering actions with Cloud Functions Storage Publication Subscription Streaming Analysis

    Triggered Code Media Vault Async Messaging Metrics Warehouse
  61. “ Does it scale to several devices? #FromGarageToRealLife

  62. Natively scalable Storage Publication Subscription Streaming Analysis Triggered Code Media

    Vault Async Messaging Metrics Warehouse
  63. “ Does it scale to millions of devices? #FromGarageToStartup

  64. Cloud IoT Core

  65. Time to wrap up!

  66. Raspberry raspberrypi.org Google Cloud Platform cloud.google.com Developer Console console.cloud.google.com BigQuery

    cloud.google.com/bigquery Pub/Sub cloud.google.com/pubsub Cloud Storage cloud.google.com/storage Cloud Functions cloud.google.com/functions Cloud IoT Core cloud.google.com/iot Resources
  67. Thank you! Laurent Picard @PicardParis Your feedback is welcome: bit.ly/feedback-pycon-balkan