Making a Pi Zero GSM/GPS HAB Backup Tracker

This is an update of a previous post, but post-flight (so I know that it works!) and with instructions on how to make your own tracker, and your own gateway to upload to the live HAB map.


GSM-based trackers are quite rightly frowned upon for HAB tracking, mainly because they only work at low altitudes (within range of a mobile phone tower, which aim the signal generally downwards).  So they don’t provide tracking throughout a flight, which is a problem as then you don’t know where the payload is until it lands.

If you’re lucky.

There are 2 problems here – one is that GSM coverage isn’t 100%, and the other is that the popular GSM trackers don’t seem to like high altitudes.  I don’t know if they get confused, or they don’t like the cold, but I’ve tried these things several times and only had one work once.

A GSM/GPS tracker that actually works would be useful though, as a backup to a main tracker.  Having had little success with commercial offerings, I thought I’d make one.  I found a Waveshare model that uses the SIM868 GSM/GPS module, plus supporting electronics on a Pi Zero HAT.  So that plus a Pi Zero and suitable power supply would make a fairly small backup tracker.

The device supports GSM (calls, texts) and GPRS (2G, i.e. slow data).  It also has a GPS receiver.  It seemed attractive to use GPRS to provide internet access (via PPP), but that would lock out the single serial port thus making GPS unavailable.  So I decided to just send SMS from the device instead, using a script that gets the GPS position, then builds and sends an SMS containing that position.  I wrote this in Python using the PyGSM library, which makes things very easy (generally no need to mess around with AT commands).  PyGSM doesn’t know about the SIM868 GPS functions however, but it was simple to add those.  So my test script requests and parses the GPS position, then formulates a text message and ends it to my mobile phone:

Live Map

It would also be useful to have the balloon position automatically uploaded to the live map, so I decided to have the device send a second SMS but this time to a gateway based at home.  This gateway is another Pi with a USB 3G modem attached.  I used the same library, but a different script to poll for new messages, determine whether an incoming message is of the correct format, and if so build a UKHAS telemetry sentence, finally uploading it to habhub for the live map:

Hardware Build

For the tracker, mount the Waveshare GSM/GPS board on a suitable Pi (the Pi Zero is ideal – less power and weight).

For the gateway, use a Pi B+ (V2 or 3 or whatever you have handy), and connect a USB modem (e.g. Huawei E173, which is very common and works well on the Pi).

You can use the software without a gateway if you wish, in which case you will only have texts sent to a smartphone and not uploaded to the live HAB map.

Software Installation

Use the same instructions for both tracker and gateway.  Build a bootable SD card in the usual way, using Raspbian Lite.

Next install git other dependencies:

sudo apt install git apt-get python-setuptools python-pip wiringpi

Install the pygsm library:

git clone
cd pygsm
sudo python

and other Python dependencies:

sudo pip install crcmod

Install the tracker software:

cd ~
git clone



First, start the gateway software:

cd ~/GSMTracker

Assuming the 3G modem is connected and working, with a valid SIM card, you should see something like this:

Modem details ...
Manufacturer = huawei
Model = E173

Phone number = +4476543210

Waiting for messages ...

Take a note of the phone number.

Payload Document

For the tracker to appear on the UKHAS map, it needs to have a payload document.  Create one using the habhub page and with these fields:

Set the payload ID to something meaningful (but please not “GSM” as that’s what I use!) and set the checksum type to “crc16-ccitt”.


First, start the GSM/GPS module by pressing the button on the side.

Now run the tracker program, using that phone number and also the number of your smartphone.  The format is:

python <payload_ID> <phone_number> [gateway_number]

For example:

python GSM 07987654321 07876543210

where the “payload_ID” must exactly match the ID you used in the payload document; the phone number is that for your smartphone, and the optional gateway number is that of your gateway to upload to the map.  You should see something like this:

Texts will be sent to mobile phone 07987654321
Texts will be sent to gateway number 07876543210

Modem details ...
Manufacturer = SIMCOM_Ltd
Model = SIMCOM_SIM868

Switching GPS on ...
Position: 16:49:54, 52.12345, -1.23456, 155.611
Send because of timeout
Send because of horizontal movement
Send because of vertical movement
Sending to mobile 07987654321: GSM position: 16:49:54, 51.1....
Sending text to gateway
Sending to gateway 07876543210: HAB:GSM,1,16:49:54,51.1...
Position: 16:50:05, 51.12335, -1.23458, 153.100


For the tracker, you should have it start up automatically.  This should include automatically starting the GSM/GPS device as it does not start up when power is applied.  Earlier we did that by pressing the button on the board, but we can automate that in a script:

cd /home/pi/GSMTracker

gpio mode 7 output
gpio write 7 0
sleep 1
gpio write 7 1
gpio mode 7 input
sleep 5

while :
    python GSM 07987654321 07876543210
    sleep 5

Start that when Raspbian starts, using your preferred startup method.


For flight, package the tracker in a small foam polystyrene container, using a suitable power source.  I used a powerbank that accepts AA cells, populated with Energizer Lithiums; this is the safest option.  Remember to connect the GSM and GPS aerials, and have the latter at the top of the payload.

The tracker will send texts to your phone and gateway when it first gets a position, every 10 minutes thereafter, or more often if it detects horizontal or vertical movement.  The update rates are in the code and can be easily changed.  It will only attempt to send out texts when below 2000m.

This entry was posted in Weather Balloon. Bookmark the permalink.

One Response to Making a Pi Zero GSM/GPS HAB Backup Tracker

  1. Pingback: #piday #raspberrypi @Raspberry_Pi « Adafruit Industries – Makers, hackers, artists, designers and engineers!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.