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

Android Things - The IoT platform for everyone - App Builders Switzerland

Android Things - The IoT platform for everyone - App Builders Switzerland

Presented at App Builders Switzerland - 25 April 2017

Internet Of Things on Android!

Rebecca Franks

April 25, 2017
Tweet

More Decks by Rebecca Franks

Other Decks in Technology

Transcript

  1. Android Engineering Lead at Dynamic Visual Technologies Google Developer Expert

    for Android & Internet of Things riggaroo.co.za @riggaroo Rebecca Franks
  2. Cameras
 Gateways
 HVAC Control
 Smart Meters Point of Sale
 Inventory

    Control
 Interactive Ads
 Vending Machines Security Systems
 Smart Doorbells
 Routers
 Energy Monitors Asset Tracking
 Fleet Management
 Driver Assist
 Predictive Service Ideal for powerful, intelligent devices that need to be secure.
  3. How is Android Things different? Android Studio Android SDKs &

    Developer Tools Firebase Libraries Google Cloud Platform SDKs Any other compatible Android/Java libraries...
  4. Cons • Only in developer preview • Known issues -

    hardware graphics acceleration is off etc • Weave not yet available for Android Things • Very new platform – not many samples • A bit slow for things that need precise timing • Not open source yet (?)
  5. Electronic Components Breadboard - Construction base for prototyping electronics Jumper

    Wire - Used to interconnect the components of a breadboard
  6. LEDs - Emits visible light when an electric current passes

    through it Push Switches - Allows electricity to flow between its two contacts Electronic Components
  7. Electronic Components Raspberry Pi Rainbow HAT • Seven APA102 multicolor

    LEDs • Four 14-segment alphanumeric displays (green LEDs) • HT16K33 display driver chip • Three capacitive touch buttons • Atmel QT1070 capacitive touch driver chip • Blue, green, and red LEDs • BMP280 temperature and pressure sensor • Piezo buzzer • Breakout pins for servo, 12C, SPI, and UART (all 3v3)
  8. Ohm’s Law The current through a conductor between two points

    is directly proportional to the voltage across the two points. V = I * R V is Voltage (volts) I is Current (amps) R is Resistance (ohms) I = 0.023A V = 5V R = 5V / 0.023A R = ± 217 ohms
  9. Hardware Integration on Android Things GPIO PWM I2C SPI UART

    Peripheral I/O COMPLEX EASY! https://github.com/androidthings/contrib-drivers Button PWM Servo RGB LED Strip GPS Temperature Sensor Capacitive touch buttons Github - Peripheral Driver Library
  10. • A Raspberry Pi 3 or alternative - Running Android

    Things • Create standard project in Android Studio • Add to app level build.gradle: provided 'com.google.android.things:androidthings:...' Getting Started
  11. <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> AndroidManifest.xml
  12. Button button = new Button("BCM6", Button.LogicState.PRESSED_WHEN_LOW);
 button.setOnButtonEventListener(new Button.OnButtonEventListener() {
 @Override


    public void onButtonEvent(final Button button, final boolean pressed) { //...
 Log.i(TAG, "Button value changed:" + pressed);
 ledGpio.setValue(pressed); } }); Button Press compile 'com.google.android.things.contrib:driver-button:0.2'
  13. //get access to the pin
 PeripheralManagerService service = new PeripheralManagerService();


    ledGpio = service.openGpio("BCM6");
 ledGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
 
 ledGpio.setValue(true);
 
 //remember to close the peripheral
 ledGpio.close(); Turn on an LED
  14. Turn it on or off using Firebase Realtime DB FirebaseDatabase.getInstance().getReference("ledKitchen")


    .addValueEventListener(new ValueEventListener() {
 @Override
 public void onDataChange(final DataSnapshot dataSnapshot) {
 Boolean value = (Boolean) dataSnapshot.getValue();
 ledGpio.setValue(value);
 //.. handle exceptions
 }
 //..
 });
  15. final DatabaseReference onlineRef = firebaseDatabase.child(".info/connected"); final DatabaseReference isPowerOnRef = firebaseDatabase.child("/online");

    onlineRef.addValueEventListener(new ValueEventListener() {
 }); @Override public void onDataChange(final DataSnapshot dataSnapshot) { if (dataSnapshot.getValue(Boolean.class)) { isPowerOnRef.setValue(true); isPowerOnRef.onDisconnect().setValue(false); } } Electricity Monitor – Companion App – onDisconnect()
  16. Electricity Monitor – Cloud Functions on Firebase const functions =

    require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendPowerNotification = functions.database.ref("/online").onWrite((event) => { }); const data = event.data; if (!data.changed()) { return; } const onOff = data.val() ? "on": "off"; const payload = { notification: { body: `Your electricity is now ${onOff}` } }; return admin.messaging().sendToTopic("Power_Notifications", payload, ..);
  17. Rebecca Franks riggaroo.co.za @riggaroo Google's IoT Developers Community https://g.co/iotdev Google's

    IoT Solutions https://iot.google.com Android Things SDK https://developer.android.com/things
  18. • https://www.myelectronicslab.com/tutorial/raspberry-pi-3-gpio-model-b- block-pinout/ • https://developers.google.com/weave/ • https://techcrunch.com/2015/10/24/why-iot-security-is-so-critical/ • https://github.com/androidthings/sample-simplepio/ •

    https://developer.android.com/things/index.html • https://github.com/riggaroo/android-things-electricity-monitor • https://github.com/riggaroo/android-things-distributed-piano • https://github.com/riggaroo/android-things-button-examples Links & References