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
python install

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.

17 Replies to “Making a Pi Zero GSM/GPS HAB Backup Tracker”

  1. Hello i have a problem, i get sms to my phone, but i dont know what send data to habitat. Can you help me maybe on messanger?

    1. The SMS to phone is seperate from the SMS to the gateway. It’s the gateway that uploads to habitat; that’s what the gateway script is for. So make a gateway as described.

      1. I made a gateway as described, but, gsm does not send. Later i will give you screenshot. Best regards.

  2. Hello there,

    i tried to get it work but i am not such a good programmer (just hobby).
    Have a question about this:
    ImportError: cannot import name GsmModem

    I read that maybe depending tree structur doesn’t match. So what to do?

  3. Hi Dave,

    thanks for the excellent tutorial, exactly what i was looking for!
    Works like a charm but one problem: The SMS i receive on my smartphone only contains cryptic symbols. Any chance you know what to do about this?

    Regards from Germany,


    1. Probably your phone isn’t interpreting the embedded link, which is intended to open a maps app to show the tracker position. Works on Android untested on iPhone.

  4. Hi Dave,

    Would like to know if you have any suggestions to get GPRS to work with this HAT. Or any other advice on how to make it possible that my pi zero has GPS and send me the location through internet.

    Thanks in advance

  5. Hey Dave,

    thanks for this great tutorial!
    One question: Would it be possible to activate location tracking by sending an SMS with some sort of code to the tracker? I Don’t want this thing to send SMS the whole time.

    Thank you

  6. Hi Dave,

    I have managed to get this running OK in a virtual environment via PyCharm and the SIM868 hat connected directly to my mac (changed the port address). It sends texts the SMS fine to my Iphone as expected. But when I install everything on the Pi Zero W via ssh and try to run the program it stalls on –

    Texts will be sent to mobile phone 0771*********

    When connected to my Mac the jumbers were on A. When connected to th Pi I have them on B.

    Any ideas? Or can you reccomend any good ways to debug over ssh?

    Setting this up to use with the PITS Zero kit purchased earlier in the year.



    1. When stopping the program I get the following:

      ^CTraceback (most recent call last):
      File “”, line 50, in
      File “build/bdist.linux-armv6l/egg/pygsm/”, line 238, in boot
      File “build/bdist.linux-armv6l/egg/pygsm/”, line 573, in command
      File “build/bdist.linux-armv6l/egg/pygsm/”, line 268, in _write
      File “/usr/local/lib/python2.7/dist-packages/pyserial-3.5-py2.7.egg/serial/”, line 640, in write
      abort, ready, _ =[self.pipe_abort_write_r], [self.fd], [], None)

      1. Looks like serial comms issues. Ensure that the port is set up correctly in raspi-config – i.e. serial port enabled but no login. Also, if it’s a Zero-W, you need to disable bluetooth because that grabs the good serial port and gives you a crap one. To do this, edit /boot/config.txt:, then go to the end of the file and add a new line containing this:


        Exit the editor, saving your changes.

        Now type this command:

        sudo systemctl disable hciuart

        and reboot.

        1. Great thanks Dave, I will try this method tomorrow and disable the Bluetooth. Will disabling the bluetooth also help power consumption? Or is it inactive unless a command is sent?

      2. Changed the port in the to /dev/serial0 and it work.

        Thanks for the great tutorial.

  7. Hi Dave! When I run my, it seems to be stuck on “Sending message etc.”. I’m pretty new to Rasp pi.

  8. Hi Dave,

    I have multible Problems using the tracker.. The biggest one, is your Version compatible to Python3?


    1. Additional installing the pygsm libary:
      byte-compiling build/bdist.linux-armv6l/egg/pygsm/ to gsmmodem.cpython-39.pyc
      File “build/bdist.linux-armv6l/egg/pygsm/”, line 140
      print “%8s %s” % (event_type, msg_str)
      SyntaxError: invalid syntax

      byte-compiling build/bdist.linux-armv6l/egg/pygsm/ to errors.cpython-39.pyc
      File “build/bdist.linux-armv6l/egg/pygsm/”, line 85
      021: “Call Rejected (out of credit?)”,
      SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers

Leave a Reply

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

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