telnet 127.0.0.1 2947
?WATCH={"enable":true}
?POLL;
で答えが得られますが、まだ小麦ともみ殻を分離する必要があります。また、GPS がコールド スタートから入っていないことも前提としています。
短いスクリプトを呼び出すことができます。
#!/bin/bash
exec 2>/dev/null
# get positions
gpstmp=/tmp/gps.data
gpspipe -w -n 40 >$gpstmp"1"&
ppid=$!
sleep 10
kill -9 $ppid
cat $gpstmp"1"|grep -om1 "[-]\?[[:digit:]]\{1,3\}\.[[:digit:]]\{9\}" >$gpstmp
size=$(stat -c%s $gpstmp)
if [ $size -gt 10 ]; then
cat $gpstmp|sed -n -e 1p >/tmp/gps.lat
cat $gpstmp|sed -n -e 2p >/tmp/gps.lon
fi
rm $gpstmp $gpstmp"1"
これにより、40 文が出力され、grep
緯度/経度が一時ファイルに出力されてからクリーンアップされます。
または、GPS3 github リポジトリgps3.py
から、次の Python2.7-3.4 スクリプトと同じディレクトリにアルファを配置し、実行します。
from time import sleep
import gps3
the_connection = gps3.GPSDSocket()
the_fix = gps3.DataStream()
try:
for new_data in the_connection:
if new_data:
the_fix.refresh(new_data)
if not isinstance(the_fix.TPV['lat'], str): # check for valid data
speed = the_fix.TPV['speed']
latitude = the_fix.TPV['lat']
longitude = the_fix.TPV['lon']
altitude = the_fix.TPV['alt']
print('Latitude:', latitude, 'Longitude:', longitude)
sleep(1)
except KeyboardInterrupt:
the_connection.close()
print("\nTerminated by user\nGood Bye.\n")
import sys
1回の反復後に閉じてからsleep(1)
、sys.exit()