Created
July 9, 2019 02:05
-
-
Save steveherrin/82e65d54cd5b610a6c7db9aedd377fbb to your computer and use it in GitHub Desktop.
Raspberry Pi GPS Utility Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires
sudo apt-get install gpsd gpsd-clients python-gps jq
This was done using the VK-162 USB GPS receiver.