Flickr Photos

Young Red Fox
Red Fox eating rowan berries
Roe Deer
Leopard in the rain
Lion mum taking care of cubs
Male Lion
Lion Cubs Playing
Lazy Spotted Hyena
Female Lion
Golden Jackal

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:

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

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:

<br />
FIDATE=`date --date='+3 hour'`<br />
echo $FIDATE<br />
date -s &quot;$FIDATE&quot;<br />
sleep 1<br />

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.

9 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>




This site uses Akismet to reduce spam. Learn how your comment data is processed.