[ale] how I did Ubuntu + NTPD + GPS, but how do I keep it?
Ron Frazier (ALE)
atllinuxenthinfo at c3energy.com
Tue Feb 14 19:44:41 EST 2012
Hi all,
I have been doing a bunch of experimentation lately to get a GPS running
with NPTD on both Windows and Linux. If you're interested, the story of
how I got it working on Windows is here:
http://www.satsignal.eu/ntp/conversation-with-ron.html
The story of how I got it working on Linux is below. Hopefully, this
experience may help others with similar projects to do. I've posted a
number of messages on the NTP questions list at ntp.org. However, I
decided to post it here also since it's Linux related. As you will see,
I also need some help on some things.
This is the story of the hoops I had to jump through to get my USB GPS
to work with Ubuntu 11.04 and NPTD without using GPSD. When I first set
up the system, I couldn't get the GPS to work any way I tried. It turns
out that the AppArmor system was preventing it from working. Another
person on the list suggested checking the log files. I eventually
figured it out, and I'm posting the procedure here. However, when I
reboot, I lose some of these configuration steps, which I need help with
figuring out how to make permanent. Hopefully, by sharing this
information, it will help others in a similar situation. I used lots of
internet sources for this data, and don't remember all the websites I
went to.
AppArmor must be tweaked every time you want to add an NTPD external
reference clock, otherwise, AppArmor won't allow NTPD to access the
GPS. This assumes you already have NTP set up and running with internet
servers.
Edit the AppArmor tunable file for ntpd with:
gksu gedit /etc/apparmor.d/tunables/ntpd
Add lines to allow ntpd to access the port you want - in this case
/dev/gps5. I'm using 127.127.20.5 as my GPS address in ntp.conf. In
Windows, NTPD expects to find the GPS on COM5. The last digit of the
address controls the COM number. On Linux, NTPD expects to see the GPS
on /dev/gps5. The last digit of the address controls the number at the
end of this string. This following modification to the AppArmor file
will allow NTPD to access /dev/gps5, or 1, or whatever you have
uncommented.
Here is the contents of my AppArmor file.
-------------------------
# Added by Ron - 2012-02-11
# Path to this file is: /etc/apparmor.d/tunables/ntpd
# Added /dev/gps1 and /dev/gps5
# /dev/null was the original line. /dev/ttyS1 was there but commented out.
# Apparently only one device can be active. Commented others out.
#Add your ntpd devices here eg. if you have a DCF clock
# @{NTPD_DEVICE}="/dev/ttyS1"
#@{NTPD_DEVICE}="/dev/null"
#@{NTPD_DEVICE}="/dev/gps1"
@{NTPD_DEVICE}="/dev/gps5"
-----------------------
Now, reinitialize AppArmor with:
(You may have to cd to this directory. I don't remember for sure.)
sudo invoke-rc.d apparmor reload
Stop ntpd with:
sudo /etc/init.d/ntp stop
Plug in the USB GPS. Wait a few seconds for it to initialize if it's
been on recently, or up to 12 minutes (I think) for a full cold start
and satellite data download. My GPS flashes a LED light about once /
second when it has a position fix.
Set the parameters for the USB port with:
(Customize your baud rate and USB port number.)
stty -F /dev/ttyUSB0 57600 igncr clocal -echo -ixon
Now, the output of the GPS should be appearing on /dev/ttyUSB0. This
must be sent to /dev/gps5 to satisfy NTPD.
Set up a symlink linking this port with /dev/gps5 with:
sudo ln -T /dev/ttyUSB0 /dev/gps5
Check that the gps is outputting data on /dev/gps5 with:
cat /dev/gps5
This should output something like (output will vary with different
gps's). There should be no blank lines. I have my GPS set to output
only the GPZDA sentences.
----------------------
ron at asus-k52f-1:/etc$ cat /dev/gps5
$GPZDA,184622.000,11,02,2012,,*5E
$GPZDA,184623.000,11,02,2012,,*5F
$GPZDA,184624.000,11,02,2012,,*58
$GPZDA,184625.000,11,02,2012,,*59
$GPZDA,184626.000,11,02,2012,,*5A
$GPZDA,184627.000,11,02,2012,,*5B
ctrl-c to stop
----------------------
Edit /etc/ntp.conf with:
gksu gedit /etc/ntp.conf
Set up the gps lines:
---------------------
# Uncomment this if GPS is available, Tweak com no. Unprefer NIST.
# GPS on COM5 - xxx.xxx.xxx.5 - Mode 16 = 9600 baud Mode 64 = 57600
# Add 1 to mode to use GPRMC sentence - same as default
# Add 2 to mode to use GPGGA sentence - may have better timing
# Add 8 to mode to use GPZDA or GPZDG sentence - recommended by Trimble
# Mode 66 = 57600 baud and use GPGGA sentence
# Mode 72 = 57600 baud and use GPZDA or GPZDG sentence
# Fudge - Tweak the GPS input for less offset from nist
# GlobalSat BU-353 USB GPS - 57600 baud /dev/ttyUSB0 link to /dev/gps1
or /dev/gps5
# Linux settings
# Fudge factor using time2 for Linux = 0.300
server 127.127.20.5 prefer minpoll 3 maxpoll 3 mode 72
fudge 127.127.20.5 time2 0.3000 refid GPS1
---------------------
Initialize the clock with:
sudo ntpdate nist1-ny.ustiming.org
Restart the ntpd service with:
sudo /etc/init.d/ntp start
Check the status of ntp with:
ntpq -p
At this point, NTPD should be reading the GPS. You may have to wait
several minutes for it to stabilize. Initial reports may be bogus.
---------------------
ron at asus-k52f-1:/etc$ ntpq -p
remote refid st t when poll reach delay offset
jitter
==============================================================================
*GPS_NMEA(5) .GPS1. 0 l 6 8 377 0.000 0.002
0.002
nist1-ny.ustimi .ACTS. 1 u 66 64 1 56.459
-1.558 0.000
216.119.63.113 .ACTS. 1 u 65 64 1 59.852
16.922 0.000
india.colorado. .ACTS. 1 u 64 64 1 65.036
-2.705 0.000
ping-audit-207- .ACTS. 1 u 3 64 3 85.151
-34.626 0.619
----------------------
If you wish, you can set ntpd startup options by amending the file
/etc/default/ntp with:
gksu gedit /etc/default/ntp
Mine has:
NTPD_OPTS='-g'
------------------------------------------------------------
Once all this is done, you should have NTPD reading the USB GPS without
using GPSD. Writing this procedure was a bit difficult, but hopefully
enough detail is there to be useful. Now, I need the help of the people
on the list. I need to know how to make these things persistent, as
right now, I lose them when I reboot. The changes to the config files
should be persistent anyway, except possibly during an Ubuntu version
upgrade. However, I think I need to somehow do the STTY command and set
up the symlink on every reboot. This has to be done after the USB port
with the GPS is initialized and thus /dev/ttyUSB0 will be active. If
anybody can tell me how to do that automatically on bootup, that would
be greatly appreciated. Also, I'd like to know how to have multiple USB
serial devices plugged in, since, as I understand it, there's no
guarantee that the same USB device will always be assigned to /dev/ttyUSB0.
Sincerely,
Ron
--
(PS - If you email me and don't get a quick response, you might want to
call on the phone. I get about 300 emails per day from alternate energy
mailing lists and such. I don't always see new messages very quickly.)
Ron Frazier
770-205-9422 (O) Leave a message.
linuxdude AT c3energy.com
More information about the Ale
mailing list