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 6. Remote Weather Station

This chapter explores how to build a Remote Weather station that acquires weather information using several sensors. This IoT project uses an Android Things-compatible board and several IoT boards that connect to Android Things using the MQTT protocol. Through this project, we will cover how to exchange data between different devices. This aspect is known as machine to machine communication. This is an important topic in the IoT ecosystem. As we will see during this chapter, Machine to Machine (M2M) includes all the technologies that enable devices to talk to each other. In this chapter, we will focus on the MQTT protocol, describing how it is used in real-life IoT projects.

In more detail, this chapter focuses on:

  • The M2M architecture and MQTT protocol
  • How to use the MQTT protocol with Android Things
  • How to acquire and stream real-time data

Before starting, it is useful to have an overview of the Weather remote IoT project so that we can better understand the...

Remote weather station project description


As stated before, we want to build an Android Things Remote weather station that acquires data from remote sensors connected to several IoT boards. In this project, the Android Things board acts as an MQTT client that collects data coming from remote sensors and visualizes it through an UI. In this context, the sensors are not connected physically to the Android Things board, but they are managed by other non-compatible IoT boards. In turn, these IoT boards exchange data with Android Things using MQTT. We will describe in more details what MQTT is and how to use it later. For now, it is enough to know that MQTT is a lightweight protocol that is widely used in M2M communication.

The following diagram describes the project architecture:

As you might already foresee, this project emulates the scenario where we have sensors and IoT boards physically placed somewhere far from the place where we collect data and analyze it. Therefore, this project architecture...

The M2M architecture and the MQTT protocol


By now, in the previous chapters, we have covered how to acquire data from sensors connected to the Android Things board and how to use the Android Things board to manage remote IoT boards that are non-compatible with Android Things. Moreover, we use the Android Things board to send data to the cloud using IoT cloud platforms. There is another important aspect that is important to cover: how to use Android Things in Machine to Machine (M2M) architecture and the role the MQTT protocol plays in this architecture.

M2M is an emerging key component in Internet of things and Industrial Internet of Things (IIoT). M2M is focused on how machines talk to each other when exchanging data and information. In other words, with Machine to Machine terms, we refer to all the technologies and wireless networks that enable real-time data exchanging without human actions. In other words, the machine (or object) exchanges data by itself with other machines. This aspect...

Installing the MQTT server


The last step of this wide IoT project is installing the MQTT server. As you already know, this is the link between the publisher and the subscriber. We added this step at the end because it is not the main focus of this chapter, but it is important to know how to do it so that you gain a deep knowledge about MQTT and the steps necessary to implement an IoT ecosystem that exchanges data and information using MQTT protocol. As stated before, this IoT project uses Mosquitto an open source MQTT broker (https://mosquitto.org/). There are several versions working on different operating systems. You can find more information about the platforms supported at this link (https://mosquitto.org/download/). In this project, we will use the Raspberry Pi 2, anyway, you are free to use any version you like according to your needs.

Installing the MQTT broker

To install the MQTT broker you have to connect to Raspberry Pi 2 and follow these steps:

  1. The first step is adding a repository...

Summary


At the end of this chapter, you have gained the knowledge about MQTT protocol. We have explored how to build a complex IoT system that uses heterogeneous components. We have explored how to build a remote weather station that acquires data remotely and send it through MQTT to Android Things board. Using this project, we have covered an important topic related to M2M. In the next chapter, we will explore how to use Pulse Width Modulation (PWM) to control servo motor using Android Things and how to acquire images using cameras.

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}