Android Phone as GPS HAT for Raspberry pi Tracking with No Third Party Data Sharing

As we previously stated the Old Android phone which is a scrap for many users can be used as a Sensor HAT for raspberry pi because it has around 15 sensors and also the camera can be feasible in the future of this project as a Computer vision.

If you are interested in sensors on Android phone - check out here


Let's begin into the materials need for doing this,
  • Android phone (old preferable with sim card)
  • Raspberry pi (This can also be your computer for testing purpose)
connect Android phone hotspot to the raspberry pi or else use USB tethering to get internet access and markdown IP of the raspberry pi.

Steps are pretty simple:

Server - client programming is done by Python:

We are going to use the Qpython app to do that on the android phone as client programming.

shell script for updating the webserver on a raspberry pi which will be done on three stages to convert the GPS data got from the Qpython script.

Software Requirements:
  • Qpython app on Android (from play store)
  • Raspbian Os on a raspberry pi (Linux/windows if you use computers)
Now, let's make raspberry pi ready.

Download all files from here GITHUB

Place all files in the home directory and also run as a root user.

In the list, first-run python3 server-socket.py in raspberry pi  (kindly change the IP address to your raspberry pi or computer)



server-socket will start a bind server connection waiting for the client.

then let's move to Android, After installing Qpython - run the Androidgps.py from your downloads.



This Androidgps.py will get GPS data from the android phone and send it to server-socket.py through a socket connect established on port 12345 with respect to 5 seconds gap.

Now, the connection between your phone and Raspberry pi is successfully established if both scripts run without any error continuously.

Time for setting up the web server on Raspberry pi,

install apache server,

sudo apt-get install apache2

the next two steps are simple, you have run two bash files.

please note, already a terminal running server-socket.py

Open a new terminal, change directory to root - home

run parsedata.sh by using the command:- bash parsedata.sh


this will get the GPS data from the server socket and parse into normal latitude and longitude format.

Next, open a new terminal, again on the root -home directory,

run infinite_index.sh file using the command:- bash infinite_index.sh



this file on the background will run the write_index.sh file updating the index.html on the apache2 server with new GPS data for every 5 seconds.

now, open the browser and type localhost or use the public IP to get the map.



We can use the tasker app in android to automate the process and also task scheduler in raspberry pi to run on boot.

Post a Comment

0 Comments