How to Get Started With IoT Using Raspberry Pi and PuTTY – Part 2

In this part we will be building the Android application for the Raspberry Pi IoT project from Part 1 of this tutorial. The project files for the Android application are also available.

If you are a beginner to Android, checking out resources like these will be helpful resources: tutorial video, building your first app.

Creating the Android Application and Connecting it to the Server

Objectives:
1. Receive the temperature readings on your Android device.
2. Display the database of the temperature readings sent by the Pi.

how to get started with iot using raspberry pi and putty part 2

Structural Flow:

  1. To receive the temperature readings on your Android device, we need our Android app to receive data from the server created above.
  2. For this, we will use Google Cloud Messaging, HTTP Protocol (Downstream messaging).
    The following will be the directional flow of data in GCM Downstream messaging:

Web Server–>Google Cloud Messaging
(The web application will connect to the Google cloud messaging API URL and send a notification message to GCM server to push it to the registered Android device).

Before we write the script to send GCM push notifications, you’ll have to create a Google API key for your application.

What this Code Does:

When a new application user registers with Google GCM, the application sends the GCM RegID to the server which gets saved in the table regions that we created earlier. As soon as the recorded temperature exceeds the set threshold, the file ‘write-to-database.py’ sends a URL request to the server to run this file to send an alert to the user. Your web server then connects to the Google server and sends the message which is pushed by the server to registered devices.

That is all there is to the server side scripting for this project.

Building the Android Application for the Raspberry Pi IoT System

The Android application is a GCM client and it will register with the GCM server and receive a GCM-Registration Id. Then it will share the GCM-Reg-Id  with the application server. Finally, it will receive a push notification from the GCM server and alert the user.

*The application is developed on Android Studio, thus it is recommended that you install Android studio.  *Make sure that you are running/testing the application on a real Android device rather than on the emulator.

For more detail: How to Get Started With IoT Using Raspberry Pi and PuTTY – Part 2


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top