Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

There is this code that claims to set the time of your linux environment,

http://blog.petrilopia.net/linux/raspberry-pi-set-time-gps-dongle/

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`
echo $GPSDATE
date -s "$GPSDATE"
/usr/sbin/ntpd

But When I am running this code through puTTy it sets my time to,

Sun Aug 8 06:08:11 PKT 2010

I'd like to know why it is setting my GPS time to 2010 ? while its 2013 ?

Here is the Output of gpspipe -w command

{"class":"TPV","tag":"MID2","device":"/dev/ttyUSB0","mode":1,"time":"1990-12-22T23:59:53.020Z","ept":0.005}
{"class":"TPV","tag":"MID2","device":"/dev/ttyUSB0","mode":1,"time":"1990-12-22T23:59:54.020Z","ept":0.005}
{"class":"SKY","tag":"MID4","device":"/dev/ttyUSB0","time":"1990-12-22T23:59:55.010Z"}
{"class":"TPV","tag":"MID2","device":"/dev/ttyUSB0","mode":1,"time":"1990-12-22T23:59:55.010Z","ept":0.005}
{"class":"TPV","tag":"MID2","device":"/dev/ttyUSB0","mode":1,"time":"1990-12-22T23:59:56.020Z","ept":0.005}
{"class":"TPV","tag":"MID2","device":"/dev/ttyUSB0","mode":1,"time":"1990-12-22T23:59:57.020Z","ept":0.005}

The output is continuous , which means it is changing every second.

share|improve this question
    
What is the output of the echo $GPSDATE? –  msw Oct 23 '13 at 14:09
    
As for now, It display nothing at all, earlier it was displyaing Sun Aug 8 06:08:11 PKT 2010 –  Sufiyan Ghori Oct 23 '13 at 17:17

2 Answers 2

up vote 3 down vote accepted

Since $GPSDATE is being reported as

Sun Aug 8 06:08:11 PKT 2010

the date -s command is doing exactly what you are telling it to do. Why is it reporting a wrong year (or nothing at all)? I have no idea.

Since you are already using ntpd why are you not content to let NTP do its thing? Is this an "I'd like gpsdate to work because it is there" issue?

The best way to help us help you debug this it by giving the full output of

gpsdate -w

in your question.

added in response to gpsdate output:

According to the gpsd documentation when the mode field of a TPV record is 1 it means "no fix". This means that the GPS receiver has not seen enough (or any) satellite data. This implies that the time value is junk which certainly makes sense if you are seeing a year of 1990 or 2014. In your script, the sleep 2 gives very little time for gpsd to get a proper GPS fix. Waiting longer might help, not having a proper antenna attached means you will wait forever for a fix.

The Network Time Protocol implemented by ntpd does not need GPS to work. It exchanges time synchronization information with other internet hosts, some of which do get their clock from a reference like GPS. Since your script stops and restarts your ntpd, you could just forget about a GPS fix and work with that. For example, the machine I am typing this on uses ntpd and is +4.7 milliseconds off of UTC which is more than accurate for many purposes. You can use ntpq -p to find out if and how well your clock is synchronized.

share|improve this answer
    
hello, i do not know anything about ntpd , and have never used GPS before. P.S: I have added the output you have asked for –  Sufiyan Ghori Oct 23 '13 at 18:18
    
@Xufyan see "added" above. –  msw Oct 23 '13 at 19:51
… "mode":1 …

That's why. You don't have a GPS fix and the GPS receiver likely has no idea what time it is. You want mode to be 3.

From the fact that SKY is being reported without any additional data, I'd further guess your receiver doesn't even have an almanac yet.

Leave the GPS running with a clear view of the sky for at least 15 minutes (yes, really). That should improve things.

See the documentation here for what those fields mean.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.