Skip to content

Instantly share code, notes, and snippets.

@steveherrin
Created July 9, 2019 02:05
Show Gist options
  • Save steveherrin/82e65d54cd5b610a6c7db9aedd377fbb to your computer and use it in GitHub Desktop.
Save steveherrin/82e65d54cd5b610a6c7db9aedd377fbb to your computer and use it in GitHub Desktop.
Raspberry Pi GPS Utility Scripts
#!/usr/bin/env python2
from __future__ import print_function, unicode_literals
import gps
import gps.clienthelpers
def get_lat_lon(client):
while client.read() == 0:
if (client.valid & gps.PACKET_SET and
client.data["class"] == "TPV" and
client.data.mode >= gps.MODE_2D and
hasattr(client.data, "lat") and
hasattr(client.data, "lon")
):
return (client.data.lat, client.data.lon)
if __name__ == '__main__':
mode = (
gps.WATCH_ENABLE |
gps.WATCH_JSON |
gps.WATCH_SCALED
)
client = gps.gps(mode=mode)
lat, lon = get_lat_lon(client)
mh = gps.clienthelpers.maidenhead(lat, lon)
print(mh)
#!/usr/bin/env bash
set -eu
GPSTIME=$(gpspipe -w | grep -m 1 \"time\": | jq -r .time)
echo "GPS Reported Time: $GPSTIME"
date -I -s "${GPSTIME}" 1>/dev/null
@steveherrin
Copy link
Author

steveherrin commented Jul 9, 2019

Requires sudo apt-get install gpsd gpsd-clients python-gps jq

This was done using the VK-162 USB GPS receiver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment