en:horloge_externe_gps_usb

The Raspberry Pi, when isn't connected to the Internet can not synchronize its clock (date and time). So for a Raspberry Pi isolated synchronize the date and time can be achieved by GPS satellite synchronization. In this example we use a GPS receiver with a USB connection.

GPS receiver

Any GPS should head, insofar as it sending data to the NMEA standard. The time and date are provided in the frame GPRMC, we use a model VK-162, available from Banggood

Receive GPS data

Then check if it sends back NMEA sentences, i.e. using cat: (CTRL-C to quit)

cat /dev/ttyACM0 
$GPRMC,191745.80,V,,,,,,,160314,,,N*7B
$GPVTG,,,,,,,,,N*30
...

For your information, the GPRMC frame is decoded by this way.

 $GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a*hh
1    = UTC of position fix
2    = Data status (V=navigation receiver warning)
3    = Latitude of fix
4    = N or S
5    = Longitude of fix
6    = E or W
7    = Speed over ground in knots
8    = Track made good in degrees True
9    = UT date
10   = Magnetic variation degrees (Easterly var. subtracts from true course)
11   = E or W
12   = Checksum

Install software to update time

Download the ZIP archive or fetch source code using git:

git clone https://github.com/adamheinrich/gpsdate

To build the project, simply navigate to project's directory and call make:

cd gpsdate
make all

Now you can use the gpsdate tool to change your local time. Simply call

sudo ./gpsdate /dev/ttyACM0
Local datetime was: 2014-03-16 20:19:06 (CET)
GPS   datetime  is: 2014-03-16 19:19:07 (UTC)
Succesfully updated local time.

Autoupdate date and time

Auto update daily

For autoupdated daily you need addd line in CRON files CRON

sudo crontab -e

Clock updated every day at 11h30pm, add folowed lines:

30 23 * * * /home/pi/gpsdate/gpsdate /dev/ttyACM0

You can save and quit using CTRL-X, Y and ENTER.

  • en/horloge_externe_gps_usb.txt
  • Last modified: 2020/07/05 17:13
  • (external edit)