Creating the Android Application and Connecting it to the Server
1. Receive the temperature readings on your Android device.
2. Display the database of the temperature readings sent by the Pi.
- To receive the temperature readings on your Android device, we need our Android app to receive data from the server created above.
- 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