GPS on Linux
Compile kernel with usb-modem feature
Connect the GPS to usb port ….
Check /var/log/messages
$ tailf /var/log/messages
Jun 20 22:26:39 localhost kernel: usb 6-2: new full speed USB device using uhci_hcd and address 3
Jun 20 22:26:40 localhost kernel: usb 6-2: configuration #1 chosen from 1 choice
Jun 20 22:26:40 localhost kernel: cdc_acm 6-2:1.0: ttyACM0: USB ACM device
Device created is ttyACM0
This should give you a continuous stream
$ cat /dev/ttyACM0
$GPRMC,071601.00,A,1907.09660,N,07252.30735,E,0.029,235.62,130711,,,A*67
$GPGGA,071601.00,1907.09660,N,07252.30735,E,1,09,2.21,33.2,M,-62.8,M,,*40
$GPGSV,3,1,12,13,82,086,34,20,11,177,35,19,43,072,35,10,25,274,*77
$GPGSV,3,3,12,07,40,343,15,11,20,137,31,08,25,316,10,28,32,250,*7A
$GPZDA,071601.00,13,07,2011,00,00*60
Now that the device is detected lets install the rpms required
$ yum install -y gpsd gpsd-clients
Incase Not created Please create
Created startup script
$ cat /etc/init.d/gpsd
#!/bin/sh
#
# gpsd Service daemon for mediating access to a GPS
#
# chkconfig: – 44 66
# description: gpsd is a service daemon that mediates access to a GPS sensor \
# connected to the host computer by serial or USB interface, \
# making its data on the location/course/velocity of the sensor \
# available to be queried on TCP port 2947 of the host computer.
# processname: gpsd
# pidfile: /var/run/gpsd.pid
# http://fedoraproject.org/wiki/FCNewInit/Initscripts
### BEGIN INIT INFO
# Provides: gpsd
# Required-Start: network
# Required-Stop: network
# Should-Start:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Service daemon for mediating access to a GPS
# Description: gpsd is a service daemon that mediates access to a GPS sensor
# connected to the host computer by serial or USB interface, making its
# data on the location/course/velocity of the sensor available to be
# queried on TCP port 2947 of the host computer.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
exec=”/usr/sbin/gpsd”
prog=$(basename $exec)
PIDFILE=/var/run/gpsd.pid
CONTROL_SOCKET=/var/run/gpsd.sock
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
: ${OPTIONS:=-n}
: ${DEVICE:=/dev/ttyACM0}
lockfile=/var/lock/subsys/$prog
start() {
[ “$EUID” != “0” ] && exit 4
echo -n $”Starting $prog: ”
daemon $exec -P $PIDFILE -F $CONTROL_SOCKET $OPTIONS $DEVICE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
[ “$EUID” != “0” ] && exit 4
echo -n $”Stopping $prog: ”
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
case “$1” in
start|stop|restart)
$1
;;
force-reload)
restart
;;
status)
status $prog
;;
try-restart|condrestart)
if status $prog >/dev/null ; then
restart
fi
;;
reload)
status $prog >/dev/null || exit 7
# If config can be reloaded without restarting, implement it here,
# remove the “exit”, and add “reload” to the usage message below.
action $”Service $prog does not support the reload action: ” /bin/false
exit 3
;;
*)
echo $”Usage: $0 {start|stop|status|restart|try-restart|force-reload}”
exit 2
esac
$ echo “/etc/init.d/gpsd start ” >> /etc/rc.local
Or start it via services
Graphic front end
$ /usr/bin/xgps
Running cgps utility, I can obtain the following (You will know where I am by interpreting the Lat/Lon). cgps runs on serial or console terminal and connects to local port 2947, which is the default port that gpsd listened to for serving queries from client programs:
$ cgps localhost 2947
CGPS Test Client
┌───────────────────────────────────────────┐┌─────────────────────────────────┐
│ Time: 2011-07-13T06:27:43.00Z ││PRN: Elev: Azim: SNR: Used: │
│ Latitude: 19.118427 N ││ │
│ Longitude: 72.871813 E ││ │
│ Altitude: 50.3 m ││ │
│ Speed: 0.0 kph ││ │
│ Heading: 356.4 degrees ││ │
│ HPE: 8 m ││ │
│ VPE: 13 m ││ │
│ Climb: 0.0 m/min ││ │
│ Status: 3D FIX ││ │
│ Change: 0 secs ││ │
│ ││ │
│ ││ │
└───────────────────────────────────────────┘└─────────────────────────────────┘
┌───────────────────────────────────────────┐
│Command: │
└───────────────────────────────────────────┘
GPSD,O=GGA 1310538463.00 0.005 19.118427 72.871813 50.30 ? ? 356
.4500 0.011 0.000 ? ? ?
GPSD,O=GSA 1310538463.00 0.005 19.118427 72.871813 50.30 8.32 13.20 356.4500
0.011 0.000 165.6961 16.64 ?
There are two more native way to interact with gpsd for retrieving GPS data – by telnet or gpspipe. Since gpsd listen to port 2947, you can just “telnet” to it. Once connect, type ‘p’ or ‘d’ followed by return will query for position and time respectively
$ telnet localhost 2947
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
p
GPSD,P=19.118280 72.871878
d
GPSD,D=2011-07-13T06:33:19.00Z
$ gpspipe -r localhost 2947
GPSD,R=1
$GPGSV,4,2,14,10,25,287,14,32,05,165,,06,16,048,33,23,63,124,48*70
$GPGSV,4,3,14,03,29,054,35,07,36,330,,16,08,039,,08,20,305,29*74
$GPGSV,4,4,14,11,15,147,,28,25,239,26*7B
$GPGLL,1907.09502,N,07252.31343,E,065047.00,A,A*6C
$GPZDA,065047.00,13,07,2011,00,00*61
Setting up time via gps
#!/bin/bash
#setup time via gps
i=0;
while [ “$i” -lt 5 ];
do
sleep 5
(echo d ; sleep 1; echo d; sleep 1; echo d) | (nc localhost 2947) > /tmp/gps_time &
TEST=$!
sleep 4
kill -s SIGINT $TEST
i=$(($i+1))
date=$`cat /tmp/gps_time | tail -n 1`
year=$(echo $date | sed ‘s/.*D=\([0-9]*\)-.*/\1/’)
[ “$year” -gt 2004 ] && break
done;
echo “slept $i times while waiting gps lock..”
echo “Setting date $date”
export TZ=UTC
date $(echo $date | sed ‘s/GPSD,D=\([0-9]*\)\(.*\):.*/\2\1/’ | sed ‘s/[^0-9]//g’)
sleep 2
export TZ=”/usr/share/zoneinfo/Asia/Calcutta”
add3sec=`date –date=’3 seconds’`
date -s “${add3sec}”
date
hwclock –systohc
hwclock
Getting Location via bash
#!/bin/bash
#setup time via gps
i=0;
while [ “$i” -lt 5 ];
do
sleep 5
(echo dp ) | (nc localhost 2947) > /tmp/gps_location &
TEST=$!
sleep 1
kill -s SIGINT $TEST
i=$(($i+1))
echo $i
done;
echo “slept $i times while waiting gps lock..”
cat /tmp/gps_location| \
awk -F “P=” ‘{ print $NF}’ | \
awk ‘{ print “Latitude: ” $1 ” Longitude: ” $2}’
-
Recent
- Set Time Zone + Fedora 18
- Fedora 17 + Tata Photon (Huawei)
- Fedora 17: Install OpenSSH Server
- Change the default keyring password
- Error: Could not stat() command file ‘/usr/local/nagios/var/rw/nagios.cmd’!
- Gnone 3.X adding personal launcher
- Gnome 3.x Change Panel
- KDE remove autostart programs
- GPS on Linux
- Debian Squeeze change root password
- Download YouTube Videos on Linux
- Pidgin + The certificate for omega.contacts.msn.com could not be validated
-
Links
-
Archives
- April 2013 (1)
- September 2012 (2)
- August 2012 (2)
- July 2012 (2)
- November 2011 (1)
- July 2011 (1)
- April 2011 (1)
- January 2011 (1)
- November 2010 (1)
- September 2010 (2)
- July 2010 (3)
- March 2010 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS