Table of Contents
NTP Stratum 1 Server
Preface
Stratum 1 server need to be connected to Stratum 0 server that can provide reference time. In our case we are going to use GPS receiver connected to Stratum 1 server so that we can use GPS clock as Stratum 0 server. In this case it is required to have the possibility to locate our GPS receiver outside of the building so that our receiver will have best possible signal.
I will use as GPS reciever (with USB interface):
- GlobalSat BU-353 (SiRF Star III)
- Garmin GPS 18 USB
OS : CentOS 6.5(basic server installation)
Install
I will use a CentOS 6.5 with Basic Server installation.
Before we will start
Please install this packages:
# yum update # it will update your already installed packages # reboot # reboot the server # yum -y install screen # it is handy in the case that you would like to work in several screens without reconnecting to server # yum -y install mc # sometime its handy # yum -y install telnet
This packages are needed only if you are going to Compile / Install GPSD from source:
# yum -y install libc.so.6 # yum -y install libdbus-1.so.3 # yum -y install libdbus-glib-1.so.2 # yum -y install libglib-2.0.so.0 # yum -y install libgobject-2.0.so.0 # yum -y install libgps.so.19 # yum -y install libgpsd.so.0 # yum -y install libm.so.6 # yum -y install libm.so.6 # yum -y install libncurses.so.5 # yum -y install libnsl.so.1 # yum -y install libpthread.so.0 # yum -y install libpthread.so.0 # yum -y install librt.so.1 # yum -y install libtinfo.so.5 # yum -y install libusb-1.0.so.0 # yum -y install ncurses-devel # yum -y install python-devel # yum -y install python-pivy # yum -y install scons # yum -y install chrpath
Check if it NTPD is installed
# rpm -qa | grep ntp # Check if it is installed if not install it ntpdate-4.2.6p5-1.el6.centos.x86_64 ntp-4.2.6p5-1.el6.centos.x86_64
Connect GPS receiver
In this step we will need to test if the GPS receiver will be working with our OS.
# lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port # OS can see our GPS reciver connected to USB bus
Check logs
# cat /var/log/messages # Check logs Mar 17 18:46:31 NTP-Server kernel: usb 2-2: USB disconnect, device number 2 Mar 17 18:46:31 NTP-Server kernel: pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0 Mar 17 18:46:31 NTP-Server kernel: pl2303 2-2:1.0: device disconnected Mar 17 18:46:37 NTP-Server kernel: usb 2-2: new full speed USB device number 3 using uhci_hcd Mar 17 18:46:37 NTP-Server kernel: usb 2-2: New USB device found, idVendor=067b, idProduct=2303 Mar 17 18:46:37 NTP-Server kernel: usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 Mar 17 18:46:37 NTP-Server kernel: usb 2-2: Product: USB-Serial Controller D Mar 17 18:46:37 NTP-Server kernel: usb 2-2: Manufacturer: Prolific Technology Inc. Mar 17 18:46:37 NTP-Server kernel: usb 2-2: configuration #1 chosen from 1 choice Mar 17 18:46:37 NTP-Server kernel: pl2303 2-2:1.0: pl2303 converter detected Mar 17 18:46:37 NTP-Server kernel: usb 2-2: pl2303 converter now attached to ttyUSB0 # Our Device is accessible as " /dev/ttyUSB0 "
According to this can access our device like “ /dev/ttyUSB0 ”
Read Data from GPS receiver
It's important to check if we are able to read data from GPS receiver as it would be pointless to continue in the case that we are not able to read the data from GPS receiver.
Please run this command:
#stty -F /dev/<GPS_device> ispeed 4800 && cat </dev/<GPS_device> # Instead of <GPS_device> please use the correct device name based on /var/log/messages information
Example:
# stty -F /dev/ttyUSB0 ispeed 4800 && cat </dev/ttyUSB0 $GPGGA,0000.0000,,,,,0,00,,,M,0.0,M,,0000*5E $GPGLL,,,,,000000.000,V,N*72
Install GPSD (from Source)
Go to ” http://download.savannah.gnu.org/releases/gpsd/ ” to check the last release of gpsd.
# mkdir /tmp/gpsd # Create a temp directory # cd /tmp/gpsd/ # wget http://download.savannah.gnu.org/releases/gpsd/gpsd-3.10.tar.gz # Download the gpsd source # tar -vxzf gpsd-3.10.tar.gz # Uncompres the source # cd /tmp/gpsd/gpsd-3.10 # Go to source files of GPSD # scons # Compile it # cp libgps.so.21.0.0 /usr/lib/ # cp libgpsd.so.22.0.0 /usr/lib/ # ln -s /usr/lib/libgpsd.so.22.0.0 /usr/lib/libgpsd.so.22 # ln -s /usr/lib/libgpsd.so.22.0.0 /usr/lib/libgpsd.so.22.0 # ln -s /usr/lib/libgps.so.21.0.0 /usr/lib/libgps.so.21 # ln -s /usr/lib/libgps.so.21.0.0 /usr/lib/libgps.so.21.0 # cp libgps.so.21.0.0 /usr/lib64/ # cp libgpsd.so.22.0.0 /usr/lib64/ # ln -s /usr/lib64/libgpsd.so.22.0.0 /usr/lib64/libgpsd.so.22 # ln -s /usr/lib64/libgpsd.so.22.0.0 /usr/lib64/libgpsd.so.22.0 # ln -s /usr/lib64/libgps.so.21.0.0 /usr/lib64/libgps.so.21 # ln -s /usr/lib64/libgps.so.21.0.0 /usr/lib64/libgps.so.21.0 # scons udev-install # Install gpsd binary files
Install GPSD (from Repository)
Install GPSD demon:
# cd /etc/yum.repos.d/ # wget http://download.opensuse.org/repositories/home:robverduijn:CentOS/CentOS_CentOS-6/home:robverduijn:CentOS.repo # yum -y install gpsd # yum -y install gpsd-clients
Start GPSD after boot
You'll need to cerate starting scripts to start the GPSD at OS boot time.
Create “ /etc/sysconfig/gpsd ”
DAEMON_OPTS="-n" BAUDRATE="4800" DEVICE="/dev/ttyS0"
Create “ /etc/init.d/gpsd ”
#!/bin/bash # # gpsd This shell script takes care of starting and stopping # gpsd (GPS daemon). # # Source function library. . /etc/init.d/functions # Source networking configuration. . /etc/sysconfig/network if [ -f /etc/sysconfig/gpsd ];then . /etc/sysconfig/gpsd fi RETVAL=0 prog="gpsd" start() { setserial $DEVICE low_latency stty $BAUDRATE -F $DEVICE echo -n $"Starting $prog: " daemon gpsd $DAEMON_OPTS $DEVICE RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/gpsd return $RETVAL } stop() { echo -n $"Shutting down $prog: " killproc gpsd RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/gpsd return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status gpsd RETVAL=$? ;; restart|reload) stop start RETVAL=$? ;; condrestart) if [ -f /var/lock/subsys/gpsd ]; then stop start RETVAL=$? fi ;;<nowiki> *</nowiki>) echo $"Usage: $0 {start|stop|restart|condrestart|status}" RETVAL=3 esac exit $RETVAL
Make sure that GPSD will start after reboot:
# chkconfig --add gpsd # chkconfig --level 345 gpsd on
Test GPSD
Debugging mode, you can use parameter “ –D “ to run the gpsd in debugging mode. You can run the application in foreground with using of parameter “ –N “.
# gpsd -D 5 -N -n /dev/ttyUSB0
It is possible to directly connect to the gpsd with using telnet
# telnet 127.0.0.1 2947 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. {"class":"VERSION","release":"3.10","rev":"3.10","proto_major":3,"proto_minor":9}
You can now ask gpsd for data
?WATCH={"enable":true,"json":true};\x0a # Send this command in to opened telnet session
You shell see:
{"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyUSB0","driver":"SiRF","subtype":"GSW3.5.0_3.5.00.00-SDK-3EP2.01 ","activated":"2014-03-17T21:40:55.908Z","flags":1,"native":1,"bps":4800,"parity":"N","stopbits":1,"cycle":1.00}]} {"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false} {"class":"ERROR","message":"Unrecognized request '\x0'"} {"class":"SKY","tag":"MID4","device":"/dev/ttyUSB0","time":"2014-03-17T21:40:55.670Z","hdop":0.00} {"class":"TPV","tag":"MID2","device":"/dev/ttyUSB0","mode":1,"time":"2014-03-17T21:40:55.670Z","ept":0.005} {"class":"TPV","tag":"MID2","device":"/dev/ttyUSB0","mode":1,"time":"2014-03-17T21:40:56.670Z","ept":0.005}
cgps
Cgps is client application that can connect to gpsd server from CLI
[root@NTP-Stratum-1 ~]# cgps -s
You will see something like this (I have changed all my local values to 11..)
┌───────────────────────────────────────────┐┌─────────────────────────────────┐ │ Time: 2014-03-20T17:32:22.0Z ││PRN: Elev: Azim: SNR: Used: │ │ Latitude: 11.111111 N ││ 17 11 011 11 Y │ │ Longitude: 11.111111 E ││ 4 11 011 11 N │ │ Altitude: 111.1 ft ││ 24 11 011 11 Y │ │ Speed: 1.1 mph ││ 2 11 011 11 Y │ │ Heading: 111.0 deg (true) ││ 14 11 011 11 N │ │ Climb: 11.1 ft/min ││ 15 11 011 11 Y │ │ Status: 3D FIX (9 secs) ││ 22 11 011 11 N │ │ GPS Type: ││ 25 11 011 11 Y │ │ Longitude Err: +/- 11 ft ││ 126 11 011 11 N │ │ Latitude Err: +/- 11 ft ││ │ │ Altitude Err: +/- 11 ft ││ │ │ Course Err: n/a ││ │ │ Speed Err: +/- 11 mph ││ │ │ ││ │ │ ││ │ │ ││ │ │ ││ │ │ ││ │ └───────────────────────────────────────────┘└─────────────────────────────────┘
NTPD
To provide NTP service we will need to use NTPD demon as NTP server where are going all NTP Stratum 2 servers connect to.
According to this update the “ /etc/ntp.conf “ file and replace all “ servers “ with:
server 127.127.28.0 minpoll 4 fudge 127.127.28.0 time1 0.183 refid NMEA server 127.127.28.1 minpoll 4 prefer fudge 127.127.28.1 refid PPS
Restart NTPD demon and it will start to pool the time from NTP Stratum 0 server.
[root@NTP-Stratum-1 ~]# /etc/init.d/ntpd restart Shutting down ntpd: [ OK ] Starting ntpd: [ OK ]
Check the NTP Stratum 1 status (I have used: GlobalSat BU-353 (SiRF Star III) ):
[root@NTP-Stratum-1 ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *SHM(0) .NMEA. 0 l 2 16 17 0.000 451.499 1.729 # This is my Reference Time source SHM(1) .PPS. 0 l - 16 0 0.000 0.000 0.000 # My device is not supporting PPS
Configure NTPD to srart after reboot:
# chkconfig --level 345 ntpd on