Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Android Things Projects

You're reading from  Android Things Projects

Product type Book
Published in Jun 2017
Publisher Packt
ISBN-13 9781787289246
Pages 232 pages
Edition 1st Edition
Languages
Author (1):
Francesco Azzola Francesco Azzola
Profile icon Francesco Azzola

Table of Contents (15) Chapters

Title Page
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface
Getting Started with Android Things Creating an Alarm System Using Android Things How to Make an Environmental Monitoring System Integrate Android Things with IoT Cloud Platforms Create a Smart System to Control Ambient Light Remote Weather Station Build a Spying Eye Android with Android Things

Chapter 4. Integrate Android Things with IoT Cloud Platforms

In this chapter, we will learn how to integrate Android Things with IoT cloud platforms. This is an important aspect when developing an IoT app. As a matter of fact, there are several scenarios where it is required that the data acquired from Android Things boards must be transferred to the cloud. For this reason, this chapter will give you all the information you need to connect your Android Things board to IoT cloud platforms.

In this chapter, we will look at the following topics:

  • IoT cloud architecture
  • How to configure an IoT cloud platform
  • How to connect an Android Things app to the IoT cloud platform
  • How to stream real-time data to the cloud and create dashboards

During this chapter, we will reuse our Android expertise to handle HTTP communication.

IoT cloud architecture


By now we have explored how to develop Android Things apps that are self-contained. In other words, we have built Android Things apps that do not communicate with external systems or platforms. The data acquired through the sensors are managed locally. There are other scenarios where the Android Things app sends the data acquired to the cloud so that this information is analyzed and integrated with other kinds of data producing new services. In this scenario, the IoT platforms play an important role. Before digging into the IoT cloud architecture details and describing how to integrate Android Things with these platforms, it is important to clarify what we mean by the IoT cloud platform.

An IoT cloud platform overview

Nowadays, the IoT cloud platforms are an important brick in IoT ecosystem. Using these platforms, we can extend the services we can provide and unlock the power of Android Things boards. Through IoT platforms, it is possible to give to the data acquired...

Streaming data to the IoT cloud platform


Once we know what an IoT cloud platform is and the reference architecture, we can implement an Android Things app that streams real-time data to the cloud. Generally speaking, to use an IoT cloud platform we have to follow these steps:

  1. Configure the IoT project on the cloud platform providing all the information including the type of the data we want to manage.
  2. Create an IoT platform client on the client side (Android Things app) that handles the connection and sends the data.

In this Android Things IoT project, we will use Samsung Artik Cloud (https://artik.cloud/) as the IoT cloud platform,. This is a professional platform that provides almost all the services described in the previous paragraphs. Moreover, it is easy to use and it provides several SDKs that simplify the data exchange process. In this project, we will manually implement the data exchange between the Android Things board and Samsung Artik Cloud so that we can learn all the steps to...

Sending data from the Android Things app


Once the client is ready, we have to call it from MainActivity.java, the class that we used to read sensor data. The easiest way to send data to Artik Cloud is invoking its API whenever the sensor reads a new value. Anyway, we have to consider the high frequency at which the sensor reads new values. This approach would require calling the Artik API almost continuously. The best approach is sending data using a scheduler. With a scheduler, the Android Things app sends data at specific time intervals without overwhelming the Artik Cloud. In this way, we can adjust the frequency having more control on the app behavior and the bandwidth the app consumes. Let us modify MainActivity.java:

  1. Add the following method to this class:
        // Scheduler to send data//
        private void initScheduler() {
          ScheduledExecutorService scheduler=
          Executors.newSingleThreadScheduledExecutor();

         scheduler.scheduleAtFixedRate(new Runnable(...

Creating a dashboard


While the app is running, it acquires data from sensors and sends the values acquired to the Artik cloud. We can use these values to create charts and visualize the data using different formats. Data charts offer a better way to analyze the data. Let us see how to do it:

  1. Log in to the Artik cloud.
  2. Go to https://my.artik.cloud/ and selectCharts:
  1. Click on Chart in the left top of the window to add the variable we used to collect data from the Android Things board. Add temperature and pressure.
  2. Adjust the time range to fit the period when you sent the data.
  3. At the end, you will see a chart like the following:
  1. Notice the temperature, the pressure, and the different charts used to represent these two variables.
  2. You can use other chart types to better represent your information.

Data logging

While charts give an overview of the values acquired by the Android Things app we developed, we can use other ways to show data. We can visualize all the requests Android Things clients made to...

Adding voice capabilities to Android Things


By now we have described how to send data to IoT cloud platforms. In this context, an IoT platform behaves like a data container where we store information. There are other kinds of services offered by IoT platforms. There are some IoT platforms that provide integration services. In other words, they are not focused on acquiring data from sensors and storing it, but their target is offering integration services with other cloud systems. One of these platforms is Temboo (https://temboo.com/). It offers a long list of integration services that can be used to extend the capabilities of an IoT app. Generally speaking, Temboo supports several programming languages and IoT platforms and one of these OSes is Android. This is perfect for our project.

What we want to do is add voice capabilities to our Android Things app so that it can trigger a voice phone call with a pre-configured message to inform us that a specific event happened. To this purpose, the...

Summary


In this chapter, we covered how to integrate Android Things with IoT cloud platforms. Moreover, we have covered how to stream data to the cloud and how to create dashboards using the data sent. Now we are ready to use other kinds of IoT platforms and integrate the Android Things boards with cloud services. The concepts developed in this chapter can be applied to other IoT platforms even if they have different features and capabilities. In the next chapter, we will learn how to use Android Things to control remote IoT boards that do not support Android Things. We will implement a master-slave architecture where the Android Things board is the master and the slaves are the low-level boards such as Arduino UNO.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Android Things Projects
Published in: Jun 2017 Publisher: Packt ISBN-13: 9781787289246
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}