NTP-Server with Raspberry Pi and Trimble Resolution SMT

Aus DL8RDS Wiki
Version vom 4. Mai 2016, 22:54 Uhr von Dl8rds (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „== Scope == Basically this project is the same as the predecessor: NTP-Server with Raspberry Pi and Sure Electronics GPS Eval board However I am using an…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

1 Scope

Basically this project is the same as the predecessor: NTP-Server with Raspberry Pi and Sure Electronics GPS Eval board

However I am using another timing receiver board here. It's one that I also purchased a long time ago but it would be shame throwing it away. Particularly given that I still have a large stockpile of Raspberry Pi boards.

2 References

3 Implementation

3.1 OS Installation and Preparation

First of all I decided to use a minibian image:

https://sourceforge.net/projects/minibian/files/2016-03-12-jessie-minibian.tar.gz

because I don't want to create a really big thing. I just want to have an NTP server.

  • Unpack, write it to the SD card, as described so often everywhere on almost every RPI page.
  • Use gparted to resize the root partition to the rest of your SD card. We should not waste space.
  • Log in using uid root pwd raspberry (default). Note that opposed to Raspian, there is no user "pi".
  • apt-get update; apt-get upgrade and update the minibian image.
  • Give it a nice hostname, editing the file /etc/hostname and reboot.
  • Edit /boot/config.txt - Add dtoverlay=pps-gpio,gpiopin=18 on a new line. - Connect the PPS signal of the Sure board to this pin. Don't get the pin wrong :-)

Raspi1BPlusHeaders.jpg

As before, I connected the PPS with GPIO pin 18. In order to make this work, I edited the file /boot.config.txt...

  • I added another line to the boot'config.txt file: dtparam=i2c_arm=on because I have included an I2C sensor that gives me some more values.
Here is why: http://stackoverflow.com/questions/32021924/raspberry-pi-2-cannot-enable-dev-i2c-0
  • Save the file...
  • Edit the file /etc/modules to contain the following lines. Just paste them below what is there already:
i2c-bcm2708
i2c_dev
pps-gpio
so to ensure that these modules will be loaded.
  • Install the pps-tools:
apt-get install pps-tools

If you are using a BMP085 or a BMP180 sensor to grab some data as I do, then do this:

  • Install the according i2c devices:
apt-get update
apt-get install i2c-tools      # I2C-Toolkit for commandline
apt-get install python-smbus   # Python library for I2C
apt-get install libi2c-dev     # library for C
apt-get install git            # need this later...
Note here (German): http://www.netzmafia.de/skripten/hardware/RasPi/RasPi_I2C.html
  • Configure the timezone using the command dpkg-reconfigure tzdata

Now we're running into a difference to the previous project, because I am not using an external USB source, but I decided to connect the native Raspberry's UART.

Now Reboot. A device will be created during system startup: /dev/pps0 Check for it to be created. Another device will be created for the I2C stuff, see below.

If you connected the PPS, the following command will produce results like here:

root@ntp2:~# ppstest /dev/pps0
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
source 0 - assert 1462395271.608254834, sequence: 4022 - clear  0.000000000, sequence: 0
source 0 - assert 1462395272.608254999, sequence: 4023 - clear  0.000000000, sequence: 0
source 0 - assert 1462395273.608254163, sequence: 4024 - clear  0.000000000, sequence: 0
source 0 - assert 1462395274.608255327, sequence: 4025 - clear  0.000000000, sequence: 0
source 0 - assert 1462395275.608373487, sequence: 4026 - clear  0.000000000, sequence: 0
^C
root@ntp2:~# 

If you get one of these lines every second, this means that your kernel is now disciplined by a PPS. It reacts to the pulse coming in, it recognizes the pulse properly. Congratulations!

Now let's check for the I2C stuff: The device /dev/i2c-1 should have been created. If you also use the BMP sensor, you should find it as '77'. Once you got the sensor connected as described in the manuals, detect it:

i2cdetect -y 1

and it should show up as "77":

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- 77

Great!

3.2 NTP configuration

The default NTP package is not sufficient, as I wrote above. It does not support reading the PPS from the kernel. It is quite disappointing if you did everything right and you're still not successful.

Though I recommend installing it first because we can prepare it nevertheless, using the command apt-get install ntp

Then edit the config file /etc/ntp.conf and make it look like this. Maybe it's agood idea to copy it to another filename and to have a reference: cp /etc/ntp.conf /etc/ntp.conf_orig. Now edit the /etc/ntp.conf: root@ntp1:/etc# cat /etc/ntp.conf

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.
statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
filegen sysstats  file sysstats  type day link enable 
 
tos  minsane 3
tos  orphan 10
tos  mindist 0.4 

server 127.127.22.0 minpoll 4 prefer
fudge 127.127.22.0 refid PPS flag2 0 flag3 1 

server 127.127.20.0 minpoll 4 mode 18 prefer # NMEA serial port, 16 = 9600 baud, 2 = $GPGGA
fudge 127.127.20.0 time2 0.413  flag1 0  refid GPS stratum 1 flag3 1

#server 127.127.1.0
#fudge  127.127.1.0 stratum 10

pool de.pool.ntp.org minpoll 10 iburst

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

restrict        172.16.0.0  mask 255.240.0.0
restrict        192.168.0.0 mask 255.255.0.0

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

Since NTP is frequently writing to the SD card, I did a trick. The creation of the mount point /var/log/ntpstats will be done during package installation.

  • Stop the daemon with servcie ntp stop
  • Now delete the contents of this directory: rm /var/log/ntpstats/*
  • Now add the following line to the file /etc/fstab and create a RAM disk
tmpfs /var/log/ntpstats tmpfs nodev,nosuid,size=10M 0 0
It will cost 10 of your 512 MB RAM, but you didn't plan a high performance compute cluster anyway :-) If you want, you can easily add more. Occasional reboots will keep it empty anyway.
Note that the process ntpd just consumes about 5 MBytes... So 512 is almost a waste of RAM. :-)
  • Reboot.