Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Android Things Projects
Android Things Projects

Android Things Projects: Efficiently build IoT projects with Android Things

eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Android Things Projects

Getting Started with Android Things

Recently, Google released its first operating system built for the Internet of Things, called Android Things. During this book, you will learn how to build IoT projects using this OS with compatible development boards and peripherals such as sensors, LEDs, servo, and so on.

In this chapter, at the beginning, we will give an overview of Android Things, covering what it is and how it differs from Android. You will learn how to reuse your Android knowledge in Android Things projects. After this, you will learn how to install Android Things on different boards such as Raspberry Pi 3 and Intel Edison with an Arduino breakout kit. This will help you to familiarize yourself with development boards while we set up our development environment. Once you are comfortable with it, we will move to creating the first Android Things project and you will learn how to use simple peripherals such as LEDs and buttons (or switches). In more detail, we will explore how to convert an Android project into an Android Things project. Moreover, you will have an overview of the most import Android Things API and how to use it in a real IoT project.

The main topics covered in this chapter are:

  • Internet of things overview Android Things layer structure
  • How to install Android Things on Raspberry Pi 3
  • How to install Android Things on Intel Edison with Arduino breakout kit
  • How to create an Android Things project

Internet of Things overview

Internet of Things, or briefly IoT, is one of the most promising trends in technology. According to many analysts, Internet of things can be the most disruptive technology in the upcoming decade. It will have a huge impact on our lives and it promises to modify our habits. IoT is and will be in the future a pervasive technology that will span its effects across many sectors:

  • Industry
  • Healthcare
  • Transportation
  • Manufacturing
  • Agriculture
  • Retail
  • Smart cities

All these areas will benefit from using IoT. Before diving into IoT projects, it is important to know what IoT means. There are several definitions about the Internet of things, addressing different aspects and considering different areas of application. Anyway, it is important to underline that the IoT is much more than a network of smartphones, tablets, and PCs connected to each other. Briefly, IoT is an ecosystem where objects are interconnected and, at the same time, they connect to the internet. The Internet of things includes every object that can potentially connect to the internet and exchange data and information. These objects are always connected anytime, anywhere, and they exchange data.

The concept of connected objects is not new and over the years it has been developed. The level of circuit miniaturization and the increasing power of CPU with a lower consumption makes it possible to imagine a future where there are millions of "things" that talk to each other.

The first time that the Internet of things was officially recognized was in 2005. The International Communication Union (ITU) in a report titled The Internet of things (https://www.itu.int/osg/spu/publications/internetofthings/InternetofThings_summary.pdf), gave the first definition:

"A new dimension has been added to the world of information and communication technologies (ICTs): from anytime, any place connectivity for anyone, we will now have connectivity for anything ... . Connections will multiply and create an entirely new dynamic network of networks - an Internet of Things "

In other words, the IoT is a network of smart objects (or things) that can receive and send data and we can control it remotely.

IoT components

There are several elements that contribute to creating the IoT ecosystem and it is important to understand the role they play in order to have a clear picture about IoT. This will be useful to better understand the projects we will build using Android Things. The basic brick of IoT is a smart object. It is a device that connects to the internet and it is capable of exchanging data. It can be a simple sensor that measures a quantity such as pressure, temperature, and so on, or a complex system. Extending this concept, our oven, our coffee machine, and even our washing machine are all examples of smart objects once they connect to the internet. All of these smart objects contribute to developing the internet of things network. Anyway, it's not only household appliances that are examples of smart objects, but also cars, buildings, actuators, and so on. We can reference these objects, when connected, using a unique identifier and start talking to them.

At the low level, these devices exchange data using a network layer. The most important and known protocols at the base of Internet of things are:

  • Wi-Fi
  • Bluetooth
  • Zigbee
  • Cellular network
  • NB-IoT
  • LoRA

From an application point of view, there are several application protocols widely used in the internet of things. Some protocols derive from different contexts (such as the web); others are IoT-specific. To name a few of them, we can remember:

  • HTTP
  • MQTT
  • CoAP
  • AMQP
  • Rest
  • XMPP
  • Stomp

By now, they could be just names or empty boxes, but throughout this book we will explore how to use these protocols with Android Things.

Prototyping boards play an important role in the Internet of things and they help to develop the number of connected objects. Using prototyping boards, we can experiment with IoT projects and in this book, we will explore how to build and test IoT projects using boards compatible with Android Things. As you may already know, there are several prototyping boards available on the market, each one having specific features. Just to name a few of them, we can list:

  • Arduino (in different flavors)
  • Raspberry Pi (in different flavors)
  • Intel Edison
  • ESP8266
  • NXP

We will focus our attention on Raspberry Pi 3 and Intel Edison because Android Things officially supports these two boards. During the books, we will also use other development boards so that you can understand how to integrate them.

Android Things overview

Android Things is the new operating system developed by Google to build IoT projects. This helps you to develop professional applications using trusted platforms and Android. Yes Android, because Android Things is a modified version of Android and we can reuse our Android knowledge to implement smart Internet of things projects. This OS has great potential because Android developers can smoothly move to IoT and start developing and building projects in a few days. Before diving into Android Things, it is important to have an overview. Android Things OS has the layer structure shown in the following diagram:

This structure is slightly different from Android OS because it is much more compact so that apps for Android Things have fewer layers beneath and they are closer to drivers and peripherals than normal Android apps. Even if Android Things derives from Android, there are some APIs available in Android not supported in Android Things. We will now briefly describe the similarities and the differences.

Let us start with the content providers, widely used in Android, and not present in Android Things SDK. Therefore, we should pay attention when we develop an Android Things app. To have more information about these content providers not supported, please refer to the Official Android Things website at https://developer.android.com/things/sdk/index.html.

Moreover, like a normal Android app, an Android Things app can have a User Interface (UI), even if this is optional, and it depends on the type of application we are developing. A user can interact with the UI to trigger events as they happen in an Android app. From this point of view, as we will see later, the developing process of a UI is the same as used in Android. This is an interesting feature because we can develop an IoT UI easily and fast, re- using our Android knowledge.

It is worth noting that Android Things fits perfectly in the Google services. Almost all cloud services implemented by Google are available in Android Things with some exceptions. Android Things does not support Google services strictly connected to the mobile world and those that require user input or authentication. Do not forget that user interface for an Android Things app is optional. To have a detailed list of Google services available in Android Things refer to the official page at https://developer.android.com/things/sdk/index.html.

An important Android aspect is the permission management. An Android app runs in a sandbox with limited access to the resources. When an app needs to access a specific resource outside the sandbox it has to request permission. In an Android app, this happens in the Manifest.xml file. This is still true in Android Things and all the permissions requested by the app are granted at installation time. Android 6 (API level 23) has introduced a new way to request a permission. An app can request a permission not only at installation time (using the Manifest.xml file), but at run-time too. Android Things does not support this new feature, so we have to request all the permissions in the Manifest file.

The last thing to notice is the notifications. As we will see later, Android Things UI does not support the notification status bar, so we cannot trigger notifications from our Android Things apps.

To make things simpler, you should remember that all the services related to the user interface or that require a user interface to accomplish the task are not guaranteed to work in Android Things.

Things support library

Things support library is the new library developed by Google to handle the communication with peripherals and drivers. This is a completely new library not present in the Android SDK and this library is one of the most important features. It exposes a set of Java Interface and classes (APIs) that we can use to connect and exchange data with external devices such as sensors, actuators, and so on. This library hides the inner communication details, supporting several industry standard protocols such as:

  • GPIO
  • I2C
  • PWM
  • SPI
  • UART

During the book, we will discover how to use this library to connect to several devices.

Moreover, this library exposes a set of APIs to create and register new device drivers called user drivers. These drivers are custom components deployed with the Android Things app that extends the Android Things framework. In other words, they are custom libraries that enable an app to communicate with other device types not supported by Android Things natively.

This book will guide you, step by step, to learn how to build real-life projects using Android. You will explore the new Android Things APIs and how to use them. In the next sections, you will learn how to install Android Things on Raspberry Pi 3 and Intel Edison.

Android Things board compatibility

Android Things is a new operating system specifically built for IoT. At the time of writing, Android Things supported four different development boards:

  • Raspberry Pi 3 Model B
  • Intel Edison
  • NXP Pico i.MX6UL
  • Intel Joule 570x

In the near future, more boards will be added to the list. Google has already announced that it will support this new board NXP Argon i.MX6UL.

The book will focus on using the first two boards: Raspberry Pi 3 and Intel Edison. Anyway, you can develop and test all the book's projects on the other boards too. This is the power of Android Things: it abstracts the underlying hardware providing, a common way to interact with peripherals and devices. The paradigm that made Java famous, Write Once and Run Anywhere (WORA), applies to Android Things too. This is a winning feature of Android Things because we can develop an Android Things app without worrying about the underlying board. Anyway, when we develop an IoT app there are some minor aspects we should consider so that our app will be portable to other compatible boards.

How to install Android Things on Raspberry

Raspberry Pi 3 is the latest board developed by Raspberry. It is an upgrade of Raspberry Pi 2 Model B and like its predecessor it has some great features:

  • Quad-core ARMv8 Cpu at 1.2Ghz
  • Wireless Lan 802.11n
  • Bluetooth 4.0

The following image shows a Raspberry Pi 3 Model B:

In this section, you will learn how to install Android Things on Raspberry Pi 3 using a Windows PC or a macOS.

Before starting the installation process you must have:

  • Raspberry Pi 3 Model B
  • At least an 8Gb SD card
  • A USB cable to connect Raspberry to your PC
  • An HDMI cable to connect Raspberry to a tv/monitor (optional)

If you do not have an HDMI cable you can use a screen mirroring tool. This is useful to know the result of the installation process and when we will develop the Android Things UIs. The installation steps are different if you are using Windows, OS X, or Linux.

How to install Android Things using Windows

At the beginning we will cover how to install Android Things on Raspberry Pi 3 using a Windows PC:

  1. Download the Android Things image from this link: https://developer.android.com/things/preview/download.html. Select the right image; in this case, you have to choose the Raspberry Pi image.
  2. Accept the license and wait until the download is completed.
  3. Once the download is complete, extract the ZIP file.
  4. To install the image on the SD card, there is a great application called Win32 Disk Imager that works perfectly. It is free and you can download it from SourceForge at: https://sourceforge.net/projects/win32diskimager/. At the time of writing, the application version is 0.9.5.
  5. After you have downloaded it, you have to run the installation executable as Administrator. Now you are ready to burn the image into the SD card.
  6. Insert the SD card into your PC.
  7. Select the image you have unzipped in step 3 and be sure to select the right disk name (your SD). At the end, click on Write.

You are done! The image is installed on the SD card and we can now start Raspberry Pi.

How to install Android Things using OS X

If you have a Mac OS X, the steps to install Android Things are slightly different. There are several options to flash this OS to the SD card; you will learn the fastest and easiest one.

These are the steps to follow:

  1. Format your SD card using FAT32. Insert your SD card into your Mac and run Disk Utility. You should see something like this:
  1. Download the Android Things OS image using this link: https://developer.android.com/things/preview/download.html.
  2. Unzip the file you have downloaded.
  3. Insert the SD card into your Mac.
  4. Now it is time to copy the image to the SD card. Open a terminal window and write the following:
sudo dd bs=1m if=path_of_your_image.img of=/dev/rdiskn

Where the path_to_your_image is the path to the file with the img extension you downloaded at step 2. In order to find out the rdiskn you have to select Preferences and then System Report. The result is shown in the following screenshot:

The BSD name is the disk name we are looking for. In this case, we have to write the following:

sudo dd bs=1m if=path_of_your_image.img of=/dev/disk1

That's all. You have to wait until the image is copied into the SD card. Do not forget that the copying process could take a while. So be patient!

Testing the installation

Once we have flashed the Android Things image into the SD card, we can remove it from the PC or Mac and insert it into the board:

  1. Connect Raspberry Pi to a video using the HDMI.
  2. Connect Raspberry Pi to your network using the LAN connection.
  3. Connect Raspberry Pi to your Mac/PC using a USB cable.

Wait until Android Things completes the boot phase. At the end, you should see the following:

Now your development board is ready and we can start developing our first Android Things project. To confirm that your Android Things is up and running, you can execute from the command line the following command:

adb devices

You should see, in the list, at least one Android device with an IP address. Congratulations; you have just installed and tested your Android Things OS. By now you should see the Android Things default screen because we did not install an app on the system.

How to install Android Things on Intel Edison

Intel Edison is a prototyping board developed by Intel with interesting features. It is a Raspberry Pi 3 alternative and it is powerful. The main specifications for this board are:

  • Intel Dual-core Atom at 500MHz
  • 1 Gb DDR3 Ram and 4 Gb eMMC flash
  • Compatible with Arduino (using an Arduino breakout Kit)
  • Bluetooth and WiFi

Intel Edison with Arduino Kit is shown in the following image:

In this book, we will use Intel Edison and Arduino breakout kit to develop our projects. Anyway, you can apply all the topics covered here to other Intel development boards compatible with Android Things. Before starting to flash the image into the Intel board, be sure you have installed the following on your system:

  • SDK Platform tools 25.0.3 or later

Moreover, check if the fastboot application is installed on your system. To do so, go to <Android_SDK_HOME>/platform-tools.

If you do not have the SDK installed correctly, please go to SDK Manager at https://developer.android.com/tools/help/sdk-manager.html and download and install it before continuing the flashing process.

Let us start:

  1. Go to https://developer.android.com/things/preview/download.html and download the image for Intel Edison.
  2. Unzip the file.
  3. Go to https://01.org/android-ia/downloads/intel-platform-flash-tool-lite. Download and install Platform flash tool light according to your operating system (OS X or Windows).
  4. In the directory where you unzipped the image downloaded at step 1 there is a file called FlashEdison.json. This is our file. Check if it exists before continuing.
  5. Run the Platform flash tool light:
  1. If you are using Intel Edison with Arduino breakout kit be sure that you:
    1. Click on the FW button and keep it pressed until step 7.
    2. Connect the USB port (J16) to your PC or Mac.
  2. When the board is connected to your PC or Mac, it appears in the Platform Flash Tool Light:
  1. Click on the Browse button and select the FlashEdison.json file, as described in step 4.
  2. Check in Platform Tool Flash Light that the Configuration list box contains Non_OS.

 

  1. Click on the Flash button and wait for the end of the process, as shown in the following screenshot:
  1. Open a terminal console or the command prompt and execute the following command:
<Android_SDK>/platform-tools/adb reboot bootloader
  1. To verify that the board is connected, write the following:
<Android_SDK>/platform-tools/fastboot devices

You should get the following as the result: edisonXXXXX

  1. Move to the directory containing the unzipped content.

 

  1. Write these commands:
<Android_SDK>/platform-tools/fastboot
flash gpt partition-table.img
flash u-boot u-boot-edison.bin flash boot_a boot.img
flash boot_b boot.img flash system_b system.img
flash userdata userdata.img erase misc
set_active _a

Now wait until the process is complete.

  1. As the process completes and you have the prompt again, execute the following:
<Android_SDK>/platform-tools/fastboot
flash gapps_a gapps.img
flash gapps_b gapps.img

Wait until the end of the process.

  1. Finally, execute the last command:
<Android_SDK>/platform-tools/fastboot
flash oem_a oem.img
flash oem_b oem.img
  1. At the end, reboot your board:
<Android_SDK>/platform-tools/fastboot reboot

You can verify your installation listing the Android device connected to your system with:

adb devices

In the device list, there should be a device named edison.

Configuring the WiFi

After you have installed the Android Things OS on your Raspberry board or Intel Edison, we can configure the WiFi connection. This can be done using the adb shell. Open a terminal window or a command prompt and write the following:

adb shell am startservice
-n com.google.wifisetup/.WifiSetupService
-a WifiSetupService.Connect
-e ssid <Your_WIFI_SSID>
-e passphrase <WIFI_password>

Where Your_WIFI_SSID is the ID of your WIFI and WIFI_password is the password you use to connect to your WiFi.

Creating the first Android Things project

Considering that Android Things derives from Android, the development process and the app structure are the as same we use in a common Android app. For this reason, the development tool to use for Android Things is Android Studio. If you have already used Android Studio in the past, reading this section will help you to discover the main differences between an Android Things app and an Android app. Otherwise, if you are new to Android development, this section will guide you step by step to create your first Android Things app.

Android Studio is the official development environment to develop Android Things apps, therefore, before starting, it is necessary you have installed it. If not, go to https://developer.android.com/studio/index.html, to download and install it. The development environment must adhere to these prerequisites:

  • SDK tools version 24 or higher
  • Update the SDK with Android 7 (API level 24)
  • Android Studio 2.2 or higher

If your environment does not meet the previous conditions, you have to update your Android Studio using the Update manager.

Now there are two alternatives to starting a new project:

  • Clone a template project from GitHub and import it into Android Studio
  • Create a new Android project in Android Studio

To better understand the main differences between Android and Android Things you should follow option number 2, at least the first time.

Cloning the template project

Create the project manually

This step is longer in respect to the previous option, but it is useful to know the main differences between these two worlds:

  1. Create a new Android project. Do not forget to set the Minimum SDK to level API 24:
  1. By now, you should create a project with empty activity. Confirm and create the new project.

There are some steps you have to follow before your Android app project turns into an Android Things app project:

  1. Open the Gradle scripts folder and modify build.gradle (app-level) and replace the dependency directive with the following lines:
dependencies {
provided 'com.google.android.things:androidthings:
0.2-devpreview'
}
  1. Open the res folder and remove all the files under it except strings.xml.
  2. Open Manifest.xml and remove the android:theme attribute in the application tag.
  3. In Manifest.xml add the following line inside the application tag:
<uses-library android:name="com.google.android.things"/>
  1. In the layout folder, open all the layout files created automatically and remove the references to values.
  2. In the activity created by default (MainActivity.java) remove this line:
import android.support.v7.app.AppCompatActivity;
  1. Replace AppCompatActivity with Activity.
  2. Under the folder java remove all the folders except the one with your package name.

That's all. You have now transformed an Android app project into an Android Things app project. Compiling the code you will have no errors. In future, you can simply clone the repository holding the project template and start coding.

Differences between Android and Android Things

As you can see an Android Things project is very similar to an Android project. We always have Activities, layouts, gradle files, and so on. At the same time, there are some differences:

  • Android Things does not use multiple layouts to support different screen sizes. So when we develop an Android Things app we create only one layout.
  • Android Things does not support themes and styles.
  • Android support libraries are not available in Android Things.

Create your first Android Things app

In this paragraph, we will modify the previous project and we will see how to control peripherals connected to Android Things. In more details, we will control the RGB led color using the three buttons. Each button controls a color (Red, Green, and Blue), so that when you press one button, Android Things turns on and off the corresponding color on the RGB led. To create this project, you need:

  • Wire jumpings
  • Resistors (200Ohm, 10Kohm)
  • Three buttons

The following image shows the button that we will use in the project:

The following image shows a 1 RGB Led:

Before connecting the devices and resistor to the board be sure that the board is disconnected from the PC, otherwise you could damage it.

The following figure describes how to connect these components to the Raspberry Pi 3:

If you are using Intel Edison the schema is as follows:

The following image shows how to connect buttons in practice:

The connections are quite simple; a pull-down resistor of 10 Kohm connects one button pin to the ground. Each button has a pull-down resistor. Moreover, the following image shows how to connect the led:

A 200 Ohm resistor connects each RGB led pin and the boards pin limiting the current flowing into the LED. The other pin, the anode pin, is connected to 3.3V for Raspberry Pi and +5V for Intel Edison. Before modifying the source code, it is necessary to add a library that helps us to interact with buttons easily. Open build.gradle (app-level) and modify the file adding the following lines:

dependencies {
...
compile 'com.google.android.things.contrib:driver-button:0.1'
}

Using this library, we can handle the button status. Moreover, we can create listeners to listen to button state changes.

Now open the MainActivity.java that you created in the project and add the following lines:

  1. In the onCreate method add the following:
PeripheralManagerService manager = new PeripheralManagerService();

This one of the most important classes introduced by Android Things SDK. By now, you should know that this class is used to interact with external peripherals. It exposes a set of methods to interact with several devices using different protocols (that is, GPIO, PWM, and so on). Using this class, an Android Things app turns on or off each board pin, so that it can control the external devices, or it can open a port for a specific purpose.

  1. Create three different instances of the Button class corresponding to each button used in the circuit:
Button button1 = new Button("IO13", Button.LogicState.PRESSED_WHEN_LOW);
One important thing to notice is that we have to specify the pin where the button is connected to the board. In the following code line, the pin is IO13.

By now, it is enough to know that each pin on the board has a specific name and these names change depending on the board. For example, if you use Intel Edison, the pin names are different from Raspberry Pi 3 pin layout. We will cover this aspect in the next chapter. The other parameter represents the button logic level when it is pressed. If you are using Raspberry Pi 3, then instead of the code line shown previously, you have to use the following:

Button button1 = new Button("BCM4", Button.LogicState.PRESSED_WHEN_LOW);

Maybe you are wondering if there are some compatibility problems when we install an Android Things app on different boards. The answer is yes, but we will see in the next chapter how to handle this problem and how to create an app that is board-independent:

  1. Now add a listener to be notified when the user presses the button. We do it as if this is an Android app with a UI:
button1.setOnButtonEventListener(
new Button.OnButtonEventListener() {
@Override
public void onButtonEvent(Button button, boolean
pressed) { if (pressed) {
redPressed = !redPressed;
try {
redIO.setValue(redPressed);
}
catch (IOException e1) {}
}
}
});

The interesting part is that we set the redIO pin value to 1 (high) or 0 (low) according to the button status. The redIO represents the pin that connects the red pin of the led. We get the reference to it using the following:

redIO = manager.openGpio("IO2");

Do not worry now about this piece of code; we will cover it in the next chapter. Using the preceding code line, we open the communication to the LED using another board pin. The previous example is for Intel Edison, and again if you are using Raspberry, the pin name changes.

  1. Now repeat the same piece of code shown previously for the green and blue buttons:
button2.setOnButtonEventListener(new Button.OnButtonEventListener()
{
@Override
public void onButtonEvent(Button button,
boolean pressed) {
if (pressed) {
greenPressed = !greenPressed; try {
greenIO.setValue(greenPressed);
}
catch (IOException e1) {}
}
}
});
  1. Where greenIO is defined as follows:
greenIO = manager.openGpio("IO4");
  1. While for the blue buttons:
button3.setOnButtonEventListener(new Button.OnButtonEventListener()
{
@Override
public void onButtonEvent(Button button,
boolean pressed) {
if (pressed) {
bluePressed = !bluePressed; try {
blueIO.setValue(bluePressed);
}
catch (IOException e1) {}
}
}
});
  1. And the blueIO is defined as follows:
blueIO = manager.openGpio("IO7");
  1. Finally, we have to modify Manifest.xml. From the Android point of view, an app uses the Manifest.xml to define the Android components such as Activity, Services, and so on.

This is still valid in the Android Things project, but there is a difference in the way it declares an Activity:

  1. Open the Manifest.xml and look for the Activity definition.
  2. Remove all the intent-filter tag.
  3. Add the following lines at the same position:
<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>
  1. Save the file.

The interesting part to notice is a new category type. If we want to execute an Activity that runs on an embedded device such as Raspberry or Intel Edison we have to add the category IOT_LAUNCHER.

That's all. Now you can connect the board to your PC/Mac. Press the run button at the top of Android Studio:

And wait until the board appears in the list of available devices, as shown in the following screenshot:

Now you can execute the app. The installation process is the same as used for the Android app. When the process completes you can start using the app.

When you press each button, you should see the led changing color, moreover, you can completely turn off the led.

Summary

This chapter introduced you to Android Things and how it works. We installed Android Things on Raspberry Pi 3 and Intel Edison. This was a necessary step so that we have a development board where we can test our next Android Things IoT projects. We developed and tested our first Android Things app that interacts with external peripherals. Now, you are ready to start developing amazing IoT projects using Android Things SDK.

In the next chapter, we will build an alarm system. We will use a PIR sensor with Android Things to detect motion. Moreover, you will explore how to use GPIO pins to communicate with the external world.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn to build promising IoT projects with Android Things
  • Make the most out of hardware peripherals using standard Android APIs
  • Build enticing projects on IoT, home automation, and robotics by leveraging Raspberry Pi 3 and Intel Edison

Description

Android Things makes developing connected embedded devices easy by providing the same Android development tools, best-in-class Android framework, and Google APIs that make developers successful on mobile. With this book, you will be able to take advantage of the new Android framework APIs to securely build projects using low-level components such as sensors, resistors, capacitors, and display controllers. This book will teach you all you need to know about working with Android Things through practical projects based on home automation, robotics, IoT, and so on. We’ll teach you to make the most of the Android Things and build enticing projects such as a smart greenhouse that controls the climate and environment automatically. You’ll also create an alarm system, integrate Android Things with IoT cloud platforms, and more. By the end of this book, you will know everything about Android Things, and you’ll have built some very cool projects using the latest technology that is driving the adoption of IoT. You will also have primed your mindset so that you can use your knowledge for profitable, practical projects.

Who is this book for?

This book is for Android enthusiasts, hobbyists, IoT experts, and Android developers who want to gain a deeper knowledge of Android Things. The main focus is on implementing IoT projects using Android Things.

What you will learn

  • Understand IoT ecosystem and the Android Things role
  • See the Android Things framework: installation, environment, SDK, and APIs
  • See how to effectively use sensors (GPIO and I2C Bus)
  • Integrate Android Things with IoT cloud platforms
  • Create practical IoT projects using Android Things
  • Integrate Android Things with other systems using standard IoT protocols
  • Use Android Things in IoT projects
Estimated delivery fee Deliver to Ecuador

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 30, 2017
Length: 232 pages
Edition : 1st
Language : English
ISBN-13 : 9781787289246
Vendor :
Google
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Ecuador

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Publication date : Jun 30, 2017
Length: 232 pages
Edition : 1st
Language : English
ISBN-13 : 9781787289246
Vendor :
Google
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 136.97
Android Things Projects
$43.99
Android System Programming
$48.99
ESP8266 Internet of Things Cookbook
$43.99
Total $ 136.97 Stars icon
Banner background image

Table of Contents

8 Chapters
Getting Started with Android Things Chevron down icon Chevron up icon
Creating an Alarm System Using Android Things Chevron down icon Chevron up icon
How to Make an Environmental Monitoring System Chevron down icon Chevron up icon
Integrate Android Things with IoT Cloud Platforms Chevron down icon Chevron up icon
Create a Smart System to Control Ambient Light Chevron down icon Chevron up icon
Remote Weather Station Chevron down icon Chevron up icon
Build a Spying Eye Chevron down icon Chevron up icon
Android with Android Things Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(1 Ratings)
5 star 0%
4 star 0%
3 star 100%
2 star 0%
1 star 0%
Klemen Petrovčič Dec 22, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
The book contains some recipes for connecting various sensors and actuators to one of the two DIY platforms presented in the book (Raspberry pi3 and Intel Edison), taking various measurements of physically quantifiable properties and sending them to an IoT platform. I would not say this is a book for beginners, because it assumes that the reader already has some knowledge of, at least, Android programming (since it is so simillar to programming for Android Things). On top of that, the reader should be familliar with some concepts/protocols (I2C, UART, logical operations) from embedded programming (writing an I2C driver is much harder than explained in this book) and basic Linux commands (for navigating the command line of the Raspberry Pi). The chapters at the end describe the usage of the MQTT application protocol (it introduces concepts like: broker, QoS, topics), which is widely popular among the maker/DIY community. The book is not filled with unnecessary theory and is packed with short tutorials, which can later be reused and extended by the readers.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela