You are here

Setting location from gpsd workaround

1 post / 0 new
kf6iiu
Setting location from gpsd workaround
Since the ""Use local or network GPS to set location" setting" with gpsd don't seem to be working, at least if the gpsd in on another host and not a locally attached GPS, you can still easily set your lat/long using this script if you have gpsd running on your LAN. The gpsd has to be running on an IP address accessible to the AREDN node (most likely on the WAN). You don't need gpsd installed on the AREDN node. This script just outputs the uci commands you need to set a new location, it could be adapted to run as a daemon with the addition of some sanity checks.

And to think, I gave away my 1990's vintage "Awk In A Nutshell" book a few months ago thinking I'd never need it again!

Chmod the script to 755, it echoes the uci commands you need to set the lat and long on the AREDN node. This script has only been tested on a TPLink CPE550. The command line argument is the IP address of the host where gpsd is running:
HOST=$1
TMPFILE=/tmp/latlon.$$

# gpsd protocol commands - see manpage gpsd_json(5)
nc $HOST 2947 << EOFFF > $TMPFILE
?WATCH={"enable":true,"json":false};
?POLL;
EOFFF

# extract lat/lon from herefile. AREDN/OpenWrt has a
# stripped down awk, not gawk
awk '{
    if (match($0, /"lon":([0-9.-]+)/))
        print "uci set aredn.@location[0].lon=" substr($0, RSTART+6, RLENGTH-6)
}' <$TMPFILE

awk '{
    if (match($0, /"lat":([0-9.-]+)/))
        print "uci set aredn.@location[0].lat=" substr($0, RSTART+6, RLENGTH-6)
}' <$TMPFILE

echo uci commit

rm -f $TMPFILE

Usage (copy paste these commands into the shell):

# ./latlong 10.21.75.107
uci set aredn.@location[0].lon=-122.094271667
uci set aredn.@location[0].lat=37.911353333
uci commit





 

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer