Flickr Photos

Roe Deer
Leopard in the rain
Lion mum taking care of cubs
Male Lion
Lion Cubs Playing
Lazy Spotted Hyena
Female Lion
Golden Jackal
Golden Jackal
Young Cheetah

Raspberry Pi: Set time from GPS dongle

I had a little problem with my Raspberry Pi Raspbian Wheezy and with Kali-Linux when I wanted to do some wardriving
and wanted to have right time/date on my Pi and I didn’t have anykind of Internet connection.

You could get right time from the GPS but I didn’t get it to work with NTP and my GPS receiver
but I found a nice script that get’s me around that problem:

date -s '01/01/2014 00:01'
sleep 1
pkill ntpd
pkill gpsd
gpsd -b -n -D 2 /dev/ttyUSB0
sleep 2
GPSDATE=`gpspipe -w | head -10 | grep TPV | sed -r 's/.*"time":"([^"]*)".*/\1/' | head -1`
date -s "$GPSDATE"

As far as I know this sets your Pi time to GMT but if that is not your local time then you can add this:

FIDATE=`date --date='+3 hour'`
echo $FIDATE
date -s "$FIDATE"
sleep 1

This one correct time to be my local (Finnish) time which is +3 hours from that GMT which you get from GPS.

So this script first sets your Pi time to 01/01/2014 00:01 because you need to set time near the right time before getting it from the GPS and after that this script
reads NMEA data from GPS and grep the time part from it and parse it so that it can be set to your Pi using normal date command. You have to have working GPS before trying this.
I have used this for a while with my wardrive Raspberry Pi setup with Raspbian Wheezy and with Kali-Linux distribution.

8 comments to Raspberry Pi: Set time from GPS dongle

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>