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

Android Things - The power of Android for Internet of Things

Android Things - The power of Android for Internet of Things

In this talk we'll see what is Android Things and what we need to know to begin developing IoT application.

Marco Gomiero

March 20, 2017
Tweet

More Decks by Marco Gomiero

Other Decks in Programming

Transcript

  1. Agenda: 1. History 2. Difference with “standard” Android 3. Simple

    Example 4. Hardware Platform 5. Access to Peripheral & “More Complex” Examples
  2. About me: Marco Gomiero Computer Engineering Student (Free Time) Android

    Developer @marcoGomier github.com/prof18 marcogomiero.com [email protected]
  3. History: • Brillo: ◦ Based on the Android software stack.

    But is not Android! ◦ Lower components of the Android operating system ◦ Development in C and C++ • Weave: ◦ device-to-device communication protocol ◦ used for sending commands, updating devices and performing initial setup of new devices ◦ Not exclusive to Brillo OS
  4. 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 on the edge that need to be secure
  5. Displays are Optional.. ..but activities are still the primary component

    of the app Most API that include showing a dialog or view to the user are not available: ◦ No authentication and sign-on ◦ No Android System Notification ◦ No runtime granted permissions ◦ No system status bar and navigation button
  6. Consider Alternate UI Alternate forms of user input: ◦ Speech

    recognition ◦ Game controllers ◦ Sensors
  7. Android SDK Android Studio Play Services Develop with the power

    of Android: Firebase Cloud Platform Compatible Java/Android Library
  8. Add the things shared library entry to the app’s Manifest:

    <application ...> <uses-library android:name="com.google.android.things"/> ... </application>
  9. Declare an activity as the main entry point after the

    device boots: <application android:label="@string/app_name"> <uses-library android:name="com.google.android.things"/> <activity android:name=".HomeActivity"> <!-- Launch activity as default from Android Studio --> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <!-- 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>
  10. Main Activity: public class MainActivity extends Activity { @Override protected

    void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
  11. What I need: • Breadboard • Cables • Resistors •

    Buttons • Sensors • Led • ...
  12. How to use: Actually on dev preview. Known Issue: •

    System power management is currently disabled. Devices will not suspend and wake locks are not necessary. • Bluetooth APIs are currently disabled. • USB APIs are currently disabled. • Dangerous permissions requested by apps are not granted until the next device reboot. This includes new app installs and new <uses-permission>elements in existing apps. • Google Play Services requires 2-3 minutes on first boot to pre-optimize dex. App installs are blocked until this process is complete. • Hardware graphics acceleration (OpenGL) is not currently enabled. APIs depedent on this functionality (such as WebView) are not available.
  13. Peripheral I/O: GPIO PWM I2C SPI UART • General Purpose

    Input/Output (GPIO) ◦ Buttons, relays, and proximity sensors. • Pulse Width Modulation (PWM) ◦ Servo motors, speakers, LEDs • Inter-Integrated Circuit (I2C) ◦ Sensors, displays, advanced peripherals • Serial Peripheral Interface (SPI) - ◦ Sensors, displays, higher speed peripherals • Universal Asynchronous Receiver Transmitter (UART) ◦ GPS, printers, RFID readers, barcode scanners
  14. List available peripherals: public class HomeActivity extends Activity { private

    static final String TAG = "HomeActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PeripheralManagerService service = new PeripheralManagerService(); Log.d(TAG, "Available GPIO: " + service.getGpioList()); } }
  15. Handle button event: private Gpio mButtonGpio; PeripheralManagerService service = new

    PeripheralManagerService(); try { mButtonGpio = service.openGpio(GPIO_PIN_NAME); mButtonGpio.setDirection(Gpio.DIRECTION_IN); mButtonGpio.setEdgeTriggerType(Gpio.EDGE_FALLING); mButtonGpio.registerGpioCallback(new GpioCallback() { @Override public boolean onGpioEdge(Gpio gpio) { Log.i(TAG, "GPIO changed, button pressed"); return true; } }); } catch (IOException e) { Log.e(TAG, "Error on PeripheralIO API", e); }
  16. Handle button event: //Close the resource if (mButtonGpio != null)

    { mButtonGpio.unregisterGpioCallback(mCallback); try { mButtonGpio.close(); } catch (IOException e) { Log.e(TAG, "Error on PeripheralIO API", e); } }
  17. Blink a LED: private Handler mHandler = new Handler(); private

    Gpio mLedGpio; PeripheralManagerService service = new PeripheralManagerService(); try { mLedGpio = service.openGpio(GPIO_PIN_NAME); mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW); mHandler.post(mBlinkRunnable); } catch (IOException e) { Log.e(TAG, "Error on PeripheralIO API", e); } }
  18. Blink a LED: private Runnable mBlinkRunnable = new Runnable() {

    @Override public void run() { // Exit if the GPIO is already closed if (mLedGpio == null) { return; } try { mLedGpio.setValue(!mLedGpio.getValue()); mHandler.postDelayed(mBlinkRunnable, INTERVAL_BETWEEN_BLINKS_MS); } catch (IOException e) { Log.e(TAG, "Error on PeripheralIO API", e); } } };
  19. GPIO PWM I2C SPI UART Input Sensors GPS Peripheral Driver

    Library Peripheral I/O User Drivers
  20. Integrate Peripheral Drivers: private ButtonInputDriver mButtonInputDriver; try { mButtonInputDriver =

    new ButtonInputDriver( GPIO_PIN_NAME, Button.LogicState.PRESSED_WHEN_LOW, KeyEvent.KEYCODE_SPACE); } catch (IOException e) { Log.e(TAG, "Error configuring GPIO pin", e); } }
  21. Integrate Peripheral Drivers: @Override public boolean onKeyDown(int keyCode, KeyEvent event)

    { if (keyCode == KeyEvent.KEYCODE_SPACE) { // Handle button pressed event return true; } return super.onKeyDown(keyCode, event); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SPACE) { // Handle button released event return true; } return super.onKeyUp(keyCode, event); }