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

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

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. 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...
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. Desktop vs headless modes Desktop - Monitor - Mouse -

    Keyboard Headless - Console - Development computer Before going headless, make sure to enable - SSH - Serial
  10. “ With a headless device, not having a serial console

    will get you blind at the worst times #MurphysLaw
  11. 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)
  12. “ Use a proper power supply or I’ll behave in

    unusual ways #GimmeStablePower
  13. 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)
  14. Customization Make the environment your own - User password -

    Hostname - Prompt - Aliases... Interfacing options (for Rainbow HAT) - Enable SPI - Enable I2C Pros - Time saver - Comfort ┌─────────┤ ├──────────┐ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └────────────────────────────────────────────────────────────────────── ────────┘
  15. 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
  16. 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 …
  17. Up to date? Make sure your system is up to

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

    Save hours later #TimeForCoffee
  19. 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
  20. Dev environment Preinstalled dev envs - C/C++ - Java -

    Node.js - Python - Ruby - + many others Preinstalled Python packages - numpy - Flask/Jinja2 - Rainbow HAT! - RPi.GPIO!
  21. 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
  22. gcloud initialization ⌛ ⌛ Note: use the serial console (or

    SSH without X11 forwarding), otherwise authentication will try to launch a web page on the Raspberry
  23. “ When I’m not at home, how can I pilot

    my device? #ConsideringComplexSolution
  24. Storing device files to Cloud Storage Metrics Warehouse Async Messaging

    Media Vault Storage Publication Subscription Analysis Streaming
  25. “ The Rainbow HAT is very simple. Isn’t it more

    complicated for real? #Doubtful
  26. “ I regularly update my code. How to update my

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

    Triggered Code Media Vault Async Messaging Metrics Warehouse
  28. 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