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

Building connected Product using Android Things

Building connected Product using Android Things

Presented at DevFest CZ , Prague Czech Republic.

In this presentation, Rebecca will look into using the Android Things platform as a way in which you can build connected products using Android. Rebecca will cover controlling your Android Things device with the Google Assistant. She will also talk through some different options for storing data for IoT devices. She will also showcase a few different applications of Android Things.

2a37bf1e025cc1523124774c760df91a?s=128

Rebecca Franks

November 04, 2017
Tweet

Transcript

  1. Building a connected Product using Android Things Rebecca Franks Android

    Engineering Lead at DVT Google Developer Expert Android @riggaroo
  2. riggaroo.co.za

  3. Outline • Android Things • Google Assistant Integration • Storage

    Options • Examples
  4. Android Things

  5. Android Things is an extension of the Android platform for

    IoT and embedded devices.
  6. Interactive Ads Vending Machines Point of Sale Stock Control Retail

    Cameras Gateways Access Control Smart Meters Business Asset Tracking Fleet Management Driver Assist Predictive Service Logistics Security Systems Smart Doorbells Routers Energy Monitors Home Android Things is ideal for powerful, intelligent devices that need to be secure.
  7. Similarities Any other Android library... Android SDK Play Services Firebase

    Android Studio Cloud Platform
  8. Differences No Play Store Deploy OTAs Subset of APIs Custom

    Hardware Single Purpose Device
  9. Applications Launcher Phone Messaging Contacts Calendar Browser Settings Application Framework

    Activity Manager Window Manager Power Manager Resource Manager XMPP Service Content Providers Wallpapers System UI Package Manager Telephony Manager Location Manager Connectivity Manager View System Runtime Permissions Soft Keyboards Notifications Libraries Surface Manager Media Framework Chromium SSL HAL Audio Manager SQLite Open GL libc Core Libraries Android Runtime (ART) Android Runtime Linux Kernel Display Driver Camera Driver Bluetooth Driver Binder (IPC) Driver USB Driver Audio Driver WiFi Driver Power Management
  10. Applications Launcher Phone Messaging Contacts Calendar Browser Settings Application Framework

    Activity Manager Window Manager Power Manager Resource Manager XMPP Service Content Providers Wallpapers System UI Package Manager Telephony Manager Location Manager Connectivity Manager View System Runtime Permissions Soft Keyboards Notifications Libraries Surface Manager Media Framework Chromium SSL HAL Audio Manager SQLite Open GL libc Core Libraries Android Runtime (ART) Android Runtime Linux Kernel Display Driver Camera Driver Bluetooth Driver Binder (IPC) Driver USB Driver Audio Driver WiFi Driver Power Management
  11. Applications Launcher Phone Messaging Contacts Calendar Browser Settings Application Framework

    Activity Manager Window Manager Power Manager Resource Manager XMPP Service Wallpapers System UI Package Manager Telephony Manager Location Manager Connectivity Manager View System Soft Keyboards Notifications Libraries Surface Manager Media Framework Chromium SSL HAL Audio Manager SQLite Open GL libc Core Libraries Android Runtime (ART) Android Runtime Linux Kernel Display Driver Camera Driver Bluetooth Driver Binder (IPC) Driver USB Driver Audio Driver WiFi Driver Power Management Things Support Library Peripheral I/O Device Management User Drivers Connectivity
  12. SoM Architecture Google Managed BSP

  13. Distribution with Android Things Android Framework Hardware Libraries Linux Kernel

    Managed by Google Apps User Drivers Managed by Developers
  14. Android Things Console • Manage your Android Things IoT Product

    • Download and install the latest Android Things system image • Build factory images that contain OEM applications along with the system image • Push over-the-air (OTA) updates partner.android.com/things/console
  15. None
  16. None
  17. None
  18. Automatic Security Updates Signed Images Verified Boot A/B Rollback Protection

  19. Developing for Android Things

  20. Developer Kits NXP I.MX7D Raspberry Pi 3

  21. Hardware Integration Peripheral Driver Library - Github + many more...

    bit.ly/androidthings-github Button GPS PWM Servo RGB LED Strip Temperature Sensor Capacitive Touch Buttons Peripheral I/O - Low Level Access GPIO PWM I2C SPI UART I2S
  22. Build a Motion Sensing Camera

  23. Motion Sensing Camera

  24. Pico i.MX7 Pinout

  25. None
  26. None
  27. None
  28. //Automatically added in app level build.gradle compileOnly 'com.google.android.things:androidthings:...'

  29. //Automatically added in AndroidManifest.xml <application ...> <uses-library android:name="com.google.android.things"/> <activity ...>

    <!-- Launch activity automatically on boot --> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.IOT_LAUNCHER"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> </application>
  30. //Automatically added in AndroidManifest.xml <application ...> <uses-library android:name="com.google.android.things"/> <activity ...>

    <!-- Launch activity automatically on boot --> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.IOT_LAUNCHER"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> </application>
  31. Working with a Motion Sensor

  32. GPIO - General Purpose Input / Output - Programmable way

    to read true / false values (1 or 0) (push button, PIR Sensor) - Write true/false values (LED) - Configurable
  33. PIR Sensor

  34. Motion Sensor Control

  35. //Accessing Sensor Data private val motionSensorGpio: Gpio = PeripheralManagerService().openGpio(motionSensorPin) fun

    start() { motionSensorGpio.setDirection(Gpio.DIRECTION_IN) motionSensorGpio.setActiveType(Gpio.ACTIVE_HIGH) motionSensorGpio.setEdgeTriggerType(Gpio.EDGE_BOTH) motionSensorGpio.registerGpioCallback(object : GpioCallback() { override fun onGpioEdge(gpio: Gpio): Boolean { if (gpio.value) { motionListener.onMotionDetected() } else { motionListener.onMotionStopped() } return true } }) }
  36. //Accessing Sensor Data private val motionSensorGpio: Gpio = PeripheralManagerService().openGpio(motionSensorPin) fun

    start() { motionSensorGpio.setDirection(Gpio.DIRECTION_IN) motionSensorGpio.setActiveType(Gpio.ACTIVE_HIGH) motionSensorGpio.setEdgeTriggerType(Gpio.EDGE_BOTH) motionSensorGpio.registerGpioCallback(object : GpioCallback() { override fun onGpioEdge(gpio: Gpio): Boolean { if (gpio.value) { motionListener.onMotionDetected() } else { motionListener.onMotionStopped() } return true } }) }
  37. //Accessing Sensor Data private val motionSensorGpio: Gpio = PeripheralManagerService().openGpio(motionSensorPin) fun

    start() { motionSensorGpio.setDirection(Gpio.DIRECTION_IN) motionSensorGpio.setActiveType(Gpio.ACTIVE_HIGH) motionSensorGpio.setEdgeTriggerType(Gpio.EDGE_BOTH) motionSensorGpio.registerGpioCallback(object : GpioCallback() { override fun onGpioEdge(gpio: Gpio): Boolean { if (gpio.value) { motionListener.onMotionDetected() } else { motionListener.onMotionStopped() } return true } }) }
  38. LED Control

  39. val peripheralManagerService = PeripheralManagerService() ledGpio = peripheralManagerService.openGpio(LED_GPIO_PIN) ledGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW) ledGpio.value =

    true ledGpio.close()
  40. val peripheralManagerService = PeripheralManagerService() ledGpio = peripheralManagerService.openGpio(LED_GPIO_PIN) ledGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW) ledGpio.value =

    true ledGpio.close()
  41. val peripheralManagerService = PeripheralManagerService() ledGpio = peripheralManagerService.openGpio(LED_GPIO_PIN) ledGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW) ledGpio.value =

    true ledGpio.close()
  42. Google Assistant Integration

  43. None
  44. Smart Home Apps rely on Home Graph Living Room Kitchen

    Bedroom Office
  45. Smart Home App 1. Setup an OAuth 2.0 server for

    account linking. 2. Create an Actions on Google developer project. 3. Create an action package, declaring support for Smart Home intents. 4. Provide fulfillment of Smart Home intents. (Cloud function) 5. Test and submit your app for approval.
  46. Smart Home - Setup + SYNC

  47. Smart Home - EXECUTE Command

  48. Smart Home - QUERY Command

  49. None
  50. Google Assistant Example bit.ly/actions-google Hackster Project: bit.ly/hack-at-motion-camera

  51. Communication + Storage

  52. Firebase

  53. Firebase Realtime Database Cloud Firestore BETA

  54. Firebase Realtime Database Cloud Firestore - Beta - Advanced Querying

    - Automatic Scaling - Next Generation - Public - Store and sync data in realtime - Hard querying BETA
  55. Firebase Realtime Database data class User(val name: String? = null,

    val surname: String? = null) val ref = FirebaseDatabase.getInstance().getReference(FIREBASE_MOTION_LOGS).push() ref.setValue(User(“Rebecca”,“Franks”))
  56. Firebase val db = FirebaseFirestore.getInstance() val newUser = User("Ada", "Lovelace")

    db.collection("users") .add(newUser) .addOnSuccessListener { ref -> Log.d(TAG, "Added user with ID: " + ref.id) } .addOnFailureListener { err -> Log.w(TAG, "Error adding user", err) } Cloud Firestore BETA
  57. Cloud IoT Core BETA

  58. What is Cloud IoT Core? Device Manager Protocol Bridge (MQTT,

    HTTP)
  59. What is Cloud IoT Core?

  60. Example Device (Android Things) Google Cloud IoT Core Cloud Pub

    Sub Server or Cloud Function It is cold It is cold It is cold Turn on heat Turn on heat
  61. Or use your own solution…

  62. Examples

  63. Edison Candle Dave Smith @devunwired

  64. BrailleBox Joe Birch @hitherejoe

  65. AI Candy Dispenser Alvaro Viebrantz @alvaroviebrantz

  66. Wildlife Detector Paul Trebilcox-Ruiz @PaulTR88

  67. Automatic and Secure The Power of Android Managed by Google

    Summary: Why Android Things?
  68. More info: docs bit.ly/androidthings codelab bit.ly/at-codelab

  69. Thank you! Rebecca Franks Android Engineering Lead at DVT @riggaroo