Skip to content

Instantly share code, notes, and snippets.

@filipsPL
Created December 5, 2023 20:48
Show Gist options
  • Save filipsPL/457516b196b1b05c83db3bc8a970cb59 to your computer and use it in GitHub Desktop.
Save filipsPL/457516b196b1b05c83db3bc8a970cb59 to your computer and use it in GitHub Desktop.
information on gps from gpsd (gpspipe and qj)
#!/bin/bash
# Run gpspipe to get GPS data in JSON format
# gps_data=$(gpspipe -w -n 10 | grep -m 1 TPV)
gps_data=$(/usr/local/bin/gpspipe -w -n 15 | grep -m 1 -E "TPV")
gps_data_sat=$(/usr/local/bin/gpspipe -w -n 15 | grep -m 1 -E "SKY")
# Check if the data is available
if [ -n "$gps_data" ]; then
time=$(echo "$gps_data" | jq -r '.time')
latitude=$(echo "$gps_data" | jq -r '.lat')
longitude=$(echo "$gps_data" | jq -r '.lon')
altHAE=$(echo "$gps_data" | jq -r '.altHAE')
altMSL=$(echo "$gps_data" | jq -r '.altMSL')
alt=$(echo "$gps_data" | jq -r '.alt')
epx=$(echo "$gps_data" | jq -r '.epx')
epy=$(echo "$gps_data" | jq -r '.epy')
epv=$(echo "$gps_data" | jq -r '.epv')
speed=$(echo "$gps_data" | jq -r '.speed')
climb=$(echo "$gps_data" | jq -r '.climb')
eps=$(echo "$gps_data" | jq -r '.eps')
epc=$(echo "$gps_data" | jq -r '.epc')
geoidSep=$(echo "$gps_data" | jq -r '.geoidSep')
eph=$(echo "$gps_data" | jq -r '.eph')
sep=$(echo "$gps_data" | jq -r '.sep')
# Extract satellite information if it is not null
satellites=$(echo "$gps_data_sat" | jq -r '.satellites')
if [ "$satellites" != "null" ]; then
satellites_info=$(echo "$satellites" | jq -r 'map("Used: \(.used) gnssid: \(.gnssid) PRN: \(.PRN), Elev: \(.el), Az: \(.az), SNR: \(.ss), ") | join("\n")')
else
satellites_info="No satellite information available."
fi
satcount=$(echo -e "$satellites_info" | wc -l)
satusedcount=$(echo -e "$satellites_info" | grep "Used: true" | wc -l)
satellites_info=$(echo -e "$satellites_info" | sed -e 's/true/🟢/g' -e 's/false/🔴/g' -e 's/gnssid: 0/🟦GPS /g' -e 's/gnssid: 1/🟧SBAS/g' -e 's/gnssid: 5/🟨QZSS/g')
# Prepare multiline string
multiline_string="Time: $time
Latitude: $latitude
Longitude: $longitude
Altitude (HAE): $altHAE
Altitude (MSL): $altMSL
Altitude: $alt
Estimated Position Error in Longitude (epx): $epx
Estimated Position Error in Latitude (epy): $epy
Estimated Vertical Error (epv): $epv
Speed: $speed
Climb: $climb
Estimated Speed Error (eps): $eps
Estimated Climb Error (epc): $epc
Geoid Separation: $geoidSep
Estimated Horizontal Position Error (eph): $eph
Estimated Position Error (sep): $sep
Satellites: seen: $satcount, used: $satusedcount
Satellite Information:
$satellites_info"
# Save the multiline string to a file
echo -e "$multiline_string"
else
echo "No GPS data available."
fi
Time: 2023-12-05T20:45:34.000Z
Latitude: 52.xxx
Longitude: 19.xxx
Altitude (HAE): null
Altitude (MSL): null
Altitude: null
Estimated Position Error in Longitude (epx): 2.167
Estimated Position Error in Latitude (epy): 2.945
Estimated Vertical Error (epv): 6.21
Speed: 0.021
Climb: null
Estimated Speed Error (eps): 5.89
Estimated Climb Error (epc): 12.42
Geoid Separation: 33.004
Estimated Horizontal Position Error (eph): 4.037
Estimated Position Error (sep): 6.508
Satellites: seen: 12, used: 9
Satellite Information:
Used: 🟢 🟦GPS PRN: 5, Elev: 29, Az: 51, SNR: 48,
Used: 🟢 🟦GPS PRN: 16, Elev: 46, Az: 299, SNR: 44,
Used: 🟢 🟦GPS PRN: 18, Elev: 79, Az: 175, SNR: 43,
Used: 🔴 🟦GPS PRN: 20, Elev: 4, Az: 29, SNR: 34,
Used: 🟢 🟦GPS PRN: 23, Elev: 22, Az: 158, SNR: 37,
Used: 🔴 🟦GPS PRN: 25, Elev: 4, Az: 149, SNR: 33,
Used: 🟢 🟦GPS PRN: 26, Elev: 62, Az: 260, SNR: 47,
Used: 🟢 🟦GPS PRN: 27, Elev: 17, Az: 280, SNR: 41,
Used: 🟢 🟦GPS PRN: 28, Elev: 5, Az: 214, SNR: 40,
Used: 🟢 🟦GPS PRN: 29, Elev: 42, Az: 90, SNR: 49,
Used: 🟢 🟦GPS PRN: 31, Elev: 18, Az: 232, SNR: 36,
Used: 🔴 🟧SBAS PRN: 40, Elev: 23, Az: 139, SNR: 42,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment