Skip to content

Instantly share code, notes, and snippets.

@linuxsocist
Last active May 19, 2024 06:57
Show Gist options
  • Save linuxsocist/55e10998e88f61af9e6ec12c12bbb04e to your computer and use it in GitHub Desktop.
Save linuxsocist/55e10998e88f61af9e6ec12c12bbb04e to your computer and use it in GitHub Desktop.
Converts the gpsd JSON output to the osmand protocol. In order for this to work, this script requires 'jq' to process the JSON output of gpsd.
#!/bin/bash
ADDR="192.168.1.9" # Replace with your traccar server address
PORT="5055" # Replace this with the port of your traccar server
ID="1234" # Replace this with your chosen traccar id
UPDATE="5" # Update interval
while [ true ]
do
{ echo "?WATCH={"enable":true}"; sleep 1; echo "?POLL;"; sleep 1; } | telnet 127.0.0.1 2947 2> /dev/null 1> gpsgrab-dump
MODE=$( cat gpsgrab-dump | tail -n 1 | jq -r '.tpv[0] | {mode}' | awk '{print $2}' | head -n 2 | tail -n 1)
TIME=$( cat gpsgrab-dump | tail -n 1 | jq -r '.tpv[0] | {time}' | awk '{print $2}' | head -n 2 | tail -n 1 | cut -c2-25)
LAT=$( cat gpsgrab-dump | tail -n 1 | jq -r '.tpv[0] | {lat}' | awk '{print $2}' | head -n 2 | tail -n 1)
LON=$( cat gpsgrab-dump | tail -n 1 | jq -r '.tpv[0] | {lon}' | awk '{print $2}' | head -n 2 | tail -n 1)
ALT=$( cat gpsgrab-dump | tail -n 1 | jq -r '.tpv[0] | {alt}' | awk '{print $2}' | head -n 2 | tail -n 1)
SPEED=$(cat gpsgrab-dump | tail -n 1 | jq -r '.tpv[0] | {speed}' | awk '{print $2}' | head -n 2 | tail -n 1)
HDOP=$( cat gpsgrab-dump | tail -n 1 | jq -r '.sky[0] | {hdop}' | awk '{print $2}' | head -n 2 | tail -n 1)
DATA="http://"$ADDR":"$PORT"/?id="$ID"&lat={"$LAT"}&lon={"$LON"}&timestamp={"$TIME"}&hdop={"$HDOP"}&altitude={"$ALT"}&speed={"$SPEED"}"
curl "$DATA" 2> /dev/null
sleep $UPDATE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment