{"id":2340,"date":"2018-09-03T19:44:34","date_gmt":"2018-09-03T19:44:34","guid":{"rendered":"http:\/\/www.daveakerman.com\/?p=2340"},"modified":"2019-04-22T13:14:23","modified_gmt":"2019-04-22T13:14:23","slug":"making-a-pi-zero-gsm-gps-hab-backup-tracker","status":"publish","type":"post","link":"http:\/\/www.daveakerman.com\/?p=2340","title":{"rendered":"Making a Pi Zero GSM\/GPS HAB Backup Tracker"},"content":{"rendered":"<p>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.<\/p>\n<h2>Introduction<\/h2>\n<p>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).\u00a0 So they don&#8217;t provide tracking throughout a flight, which is a problem as then you don&#8217;t know where the payload is until it lands.<\/p>\n<p>If you&#8217;re lucky.<\/p>\n<p>There are 2 problems here &#8211; one is that GSM coverage isn&#8217;t 100%, and the other is that the popular GSM trackers don&#8217;t seem to like high altitudes.\u00a0 I don&#8217;t know if they get confused, or they don&#8217;t like the cold, but I&#8217;ve tried these things several times and only had one work once.<\/p>\n<p>A GSM\/GPS tracker that actually works would be useful though, as a backup to a main tracker.\u00a0 Having had little success with commercial offerings, I thought I&#8217;d make one.\u00a0 I found a <a href=\"https:\/\/www.amazon.co.uk\/Waveshare-GSM-GPRS-GNSS-HAT\/dp\/B075M8WN5L\">Waveshare model<\/a> that uses the SIM868 GSM\/GPS module, plus supporting electronics on a Pi Zero HAT.\u00a0 So that plus a Pi Zero and suitable power supply would make a fairly small backup tracker.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-2327\" src=\"http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/SIM868.jpg\" alt=\"\" width=\"750\" height=\"564\" srcset=\"http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/SIM868.jpg 750w, http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/SIM868-300x226.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>The device supports GSM (calls, texts) and GPRS (2G, i.e. slow data).\u00a0 It also has a GPS receiver.\u00a0 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.\u00a0 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.\u00a0 I wrote this in Python using the PyGSM library, which makes things very easy (generally no need to mess around with AT commands).\u00a0 PyGSM doesn&#8217;t know about the SIM868 GPS functions however, but it was simple to add those.\u00a0 So my test script requests and parses the GPS position, then formulates a text message and ends it to my mobile phone:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-large wp-image-2328\" src=\"http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/DeDx9CKX4AEKu5b-1024x683.jpg\" alt=\"\" width=\"640\" height=\"427\" srcset=\"http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/DeDx9CKX4AEKu5b-1024x683.jpg 1024w, http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/DeDx9CKX4AEKu5b-300x200.jpg 300w, http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/DeDx9CKX4AEKu5b-768x512.jpg 768w, http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/DeDx9CKX4AEKu5b.jpg 2048w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>Live Map<\/h2>\n<p>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.\u00a0 This gateway is another Pi with a USB 3G modem attached.\u00a0 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:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-2329\" src=\"http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/DeEIw54W0AEajJz.jpg\" alt=\"\" width=\"772\" height=\"421\" srcset=\"http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/DeEIw54W0AEajJz.jpg 772w, http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/DeEIw54W0AEajJz-300x164.jpg 300w, http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/05\/DeEIw54W0AEajJz-768x419.jpg 768w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/p>\n<h2>Hardware Build<\/h2>\n<p>For the tracker, mount the Waveshare GSM\/GPS board on a suitable Pi (the Pi Zero is ideal &#8211; less power and weight).<\/p>\n<p>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).<\/p>\n<p>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.<\/p>\n<h2>Software Installation<\/h2>\n<p>Use the same instructions for both tracker and gateway.\u00a0\u00a0Build a bootable SD card in the usual way, using Raspbian Lite.<\/p>\n<p>Next install git other dependencies:<\/p>\n<pre>sudo apt install git apt-get python-setuptools python-pip wiringpi<\/pre>\n<p>Install the pygsm library:<\/p>\n<pre>git clone https:\/\/github.com\/adammck\/pygsm.git\ncd pygsm\npython setup.py install<\/pre>\n<p>and other Python dependencies:<\/p>\n<pre>sudo pip install crcmod<\/pre>\n<p>Install the tracker software:<\/p>\n<pre>cd ~\ngit clone https:\/\/github.com\/daveake\/GSMTracker.git<\/pre>\n<h2>Testing<\/h2>\n<h3>Gateway<\/h3>\n<p>First, start the gateway software:<\/p>\n<pre>cd ~\/GSMTracker\npython gateway.py<\/pre>\n<p>Assuming the 3G modem is connected and working, with a valid SIM card, you should see something like this:<\/p>\n<pre>Modem details ...\nManufacturer = huawei\nModel = E173\n\nPhone number = +4476543210\n\nWaiting for messages ...<\/pre>\n<p>Take a note of the phone number.<\/p>\n<h3>Payload Document<\/h3>\n<p>For the tracker to appear on the UKHAS map, it needs to have a payload document.\u00a0 Create one using the <a href=\"http:\/\/habitat.habhub.org\/genpayload\/\">habhub page<\/a>\u00a0and with these fields:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-2344\" src=\"http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/09\/gsm.png\" alt=\"\" width=\"725\" height=\"226\" srcset=\"http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/09\/gsm.png 725w, http:\/\/www.daveakerman.com\/wp-content\/uploads\/2018\/09\/gsm-300x94.png 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/p>\n<p>Set the payload ID to something meaningful (but please not &#8220;GSM&#8221; as that&#8217;s what I use!) and set the checksum type to &#8220;crc16-ccitt&#8221;.<\/p>\n<h3>Tracker<\/h3>\n<p>First, start the GSM\/GPS module by pressing the button on the side.<\/p>\n<p>Now run the tracker program, using that phone number and also the number of your smartphone.\u00a0 The format is:<\/p>\n<pre>python gsmtrack.py &lt;payload_ID&gt; &lt;phone_number&gt; [gateway_number]<\/pre>\n<p>For example:<\/p>\n<pre>python gsmtrack.py GSM 07987654321 07876543210<\/pre>\n<p>where the &#8220;payload_ID&#8221; 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.\u00a0 You should see something like this:<\/p>\n<pre>Texts will be sent to mobile phone 07987654321\nTexts will be sent to gateway number 07876543210\nGPS\/GSM UKHAS Tracker\n=====================\n\nModem details ...\nManufacturer = SIMCOM_Ltd\nModel = SIMCOM_SIM868\n\nSwitching GPS on ...\n['OK']\nPosition: 16:49:54, 52.12345, -1.23456, 155.611\nSend because of timeout\nSend because of horizontal movement\nSend because of vertical movement\nSending to mobile 07987654321: GSM position: 16:49:54, 51.1....\nSending text to gateway\nSending to gateway 07876543210: HAB:GSM,1,16:49:54,51.1...\nPosition: 16:50:05, 51.12335, -1.23458, 153.100<\/pre>\n<h2>Startup<\/h2>\n<p>For the tracker, you should have it start up automatically.\u00a0 This should include automatically starting the GSM\/GPS device as it does not start up when power is applied.\u00a0 Earlier we did that by pressing the button on the board, but we can automate that in a script:<\/p>\n<pre>#!\/bin\/bash\ncd \/home\/pi\/GSMTracker\n\ngpio mode 7 output\ngpio write 7 0\nsleep 1\ngpio write 7 1\ngpio mode 7 input\nsleep 5\n\nwhile :\ndo\n    python gsmtrack.py GSM 07987654321 07876543210\n    sleep 5\ndone\n\n<\/pre>\n<p>Start that when Raspbian starts, using your preferred startup method.<\/p>\n<h2>Usage<\/h2>\n<p>For flight, package the tracker in a small foam polystyrene container, using a suitable power source.\u00a0 I used a powerbank that accepts AA cells, populated with Energizer Lithiums; this is the safest option.\u00a0 Remember to connect the GSM and GPS aerials, and have the latter at the top of the payload.<\/p>\n<p>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.\u00a0 The update rates are in the code and can be easily changed.\u00a0 It will only attempt to send out texts when below 2000m.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. Introduction GSM-based trackers are quite rightly frowned upon for HAB tracking, mainly because [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=\/wp\/v2\/posts\/2340"}],"collection":[{"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2340"}],"version-history":[{"count":7,"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=\/wp\/v2\/posts\/2340\/revisions"}],"predecessor-version":[{"id":2479,"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=\/wp\/v2\/posts\/2340\/revisions\/2479"}],"wp:attachment":[{"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2340"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.daveakerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}