doc(time/README):Add working ntp.conf file and refs
[EVA-2020-02.git] / doc / time / README.org
CommitLineData
6bdc2473
SBS
1* Time
2This document was created by Steven Baltakatei Sandoval on
3~2020-07-23T22:27Z~ under a [[https://creativecommons.org/licenses/by-sa/4.0/][Creative Commons BY-SA 4.0 license]]. It
1b813272 4was updated by Steven Baltakatei Sandoval on ~2020-10-12T22:22Z~
6bdc2473
SBS
5** Development Task list
6*** Set up prototype unit
aafe11cf
SBS
7**** DONE Solder wire for PPS signal
8***** 2020-07-25T20:03Z; bktei> Soldered pins to permit accessibility.
9 CLOSED: [2020-07-25 Sat 20:03]
6bdc2473
SBS
10**** Follow guide
11- [[https://ozzmaker.com/forums/topic/connecting-gps-pps-pin/][Ozzmaker post]] on ~PPS~ wiring and a [[https://www.satsignal.eu/ntp/Raspberry-Pi-NTP.html][guide]] recommendation.
12- [[http://www.satsignal.eu/raspberry-pi/Schmidt-RPZ-NTP-2016.pdf][Schmidt article]] on Raspberry Pi Zero time server.
13- [[https://gpsd.gitlab.io/gpsd/gpsd-time-service-howto.html][GPSD dev ref]] page for ~gpsd~ interfacing with ~ntp~.
aafe11cf 14- [[https://raspberryautomation.com/connect-multiple-ds18b20-temperature-sensors-to-a-raspberry-pi/][Raspberry Autom]] article on specifying custom GPIO pin.
6bdc2473 15*** Document prototype unit
1b813272
SBS
16**** TODO Integrate DHCP details from gregledet tutorial
17http://www.gregledet.net/computers/building-a-stratum-1-ntp-server-with-a-raspberry-pi-4-and-adafruit-ultimate-gps-hat/
18**** TODO Note working ntp.conf file
19
20#+BEGIN_EXAMPLE
21# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
22
23driftfile /var/lib/ntp/ntp.drift
24logfile /var/log/ntp.log
25
26# Leap seconds definition provided by tzdata
27leapfile /usr/share/zoneinfo/leap-seconds.list
28
29# Enable this if you want statistics to be logged.
30statsdir /var/log/ntpstats/
31
32statistics loopstats peerstats clockstats
33filegen loopstats file loopstats type day enable
34filegen peerstats file peerstats type day enable
35filegen clockstats file clockstats type day enable
36
37
38# You do need to talk to an NTP server or two (or three).
39#server ntp.your-provider.example
40server time.nist.gov iburst minpoll 5 maxpoll 5
41server tick.usno.navy.mil iburst minpoll 5 maxpoll 5
42server 0.us.pool.ntp.org iburst minpoll 5 maxpoll 5
43server 0.us.pool.ntp.org iburst minpoll 5 maxpoll 5
44server 0.us.pool.ntp.org iburst minpoll 5 maxpoll 5
45server 0.us.pool.ntp.org iburst minpoll 5 maxpoll 5
46
47# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
48# pick a different set every time it starts up. Please consider joining the
49# pool: <http://www.pool.ntp.org/join.html>
50#pool 0.debian.pool.ntp.org iburst
51#pool 1.debian.pool.ntp.org iburst
52#pool 2.debian.pool.ntp.org iburst
53#pool 3.debian.pool.ntp.org iburst
54
55# PPS Kernel mode
56server 127.127.22.0 minpoll 4 maxpoll 4 true
57fudge 127.127.22.0 flag3 1 refid kPPS
58
59# GPS PPS reference (NTP2)
60server 127.127.28.2 minpoll 4 maxpoll 4
61fudge 127.127.28.2 refid SHM2
62
63# GPS Serial data reference (NTP0)
64server 127.127.28.0 minpoll 4 maxpoll 4 prefer
65fudge 127.127.28.0 time1 +0.593 refid GPS
66
67# Fix False tickers
68tos mindist 0.5
69
70# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
71# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
72# might also be helpful.
73#
74# Note that "restrict" applies to both servers and clients, so a configuration
75# that might be intended to block requests from certain clients could also end
76# up blocking replies from your own upstream servers.
77
78# By default, exchange time with everybody, but don't allow configuration.
79restrict -4 default kod notrap nomodify nopeer noquery limited
80restrict -6 default kod notrap nomodify nopeer noquery limited
81
82# Local users may interrogate the ntp server more closely.
83restrict 127.0.0.1
84restrict ::1
85
86# Needed for adding pool entries
87restrict source notrap nomodify noquery
88
89# Clients from this (example!) subnet have unlimited access, but only if
90# cryptographically authenticated.
91#restrict 192.168.123.0 mask 255.255.255.0 notrust
92
93
94# If you want to provide time to your local subnet, change the next line.
95# (Again, the address is an example only.)
96#broadcast 192.168.123.255
97
98# If you want to listen to time broadcasts on your local subnet, de-comment the
99# next lines. Please do this only if you trust everybody on the network!
100#disable auth
101#broadcastclient
102#+END_EXAMPLE
103
104**** TODO Integreate References
105- Some explanations for ~time1~, ~flag1~, ~flag3~, ~refid~, etc. strings in ntp.conf: [[http://doc.ntp.org/4.2.8/drivers/driver28.html][link]].
106- NTP Basics (what "system peer" means): [[https://kb.meinbergglobal.com/kb/time_sync/ntp/ntp_basics][link]].
107- GPSD guide indicating PPS signals should be preferred over GPS signals: [[https://gpsd.gitlab.io/gpsd/gpsd-time-service-howto.html#_feeding_ntpd_from_gpsd][link]]
108
6bdc2473
SBS
109** Narrative
110The ~ninfacyzga-01~ device is equipped with an Ozzmaker BerryGPS-IMU
111module which provides time and location data to ~gpsd~. The time is
112provided by GPS satellites which themselves are [[https://science.nasa.gov/science-news/science-at-nasa/2002/08apr_atomicclock/][equipped]] with atomic
113clocks. This extremely accurate set of clocks are needed since a GPS
114receiver calculates its position in space using a General Relativity
115calculation that uses the small variations in the time stamps received
116from each satellite. This means that ~gpsd~ may be used to set the
117system clock without a need for an internet connection to a default
118Debian time server; ~ninfacyzga-01~ can be its own time server.
119** Description
120*** Hardware
121Ozzmaker BerryGPS-IMU, Version 3
122*** Software
123This guide describes steps that may be used to convert a Raspberry Pi
124into a time server using ~gpsd~.
125** Operating Procedures
126*** Initial Startup
127**** Install Raspbian 10 (Buster) onto a Raspberry Pi Zero W.
128**** Install Hardware
129See [[https://ozzmaker.com/forums/topic/connecting-gps-pps-pin/][this]] Ozzmaker forum topic about connecting the BerryGPS-IMU
130~T_PULSE~ pin to GPIO 18.
131
132Connect the ~T_PULSE~ connection on the BerryGPS-IMU-3 to GPIO pin 18
aafe11cf
SBS
133(ex: with solder and wire) in order to provide the PPS data signal
134generated by the BerryGPS-IMU to the Raspberry Pi. Processing of this
135data signal is handled by adding a line to ~/boot/config.txt~ in the
136next section ("Install Software").
6bdc2473
SBS
137
138**** Install Software
6bdc2473
SBS
139These instructions assume that ~gpsd~ has already been setup to
140provide NMEA sentences to ~gpspipe~ for location. See the ~README.org~
141in ~doc/location~ for details. Basically, ~gpsd~ needs to be told via
aafe11cf 142its ~/etc/default/gpsd~ configuration file of which ~/dev/ttyS0~ will
6bdc2473
SBS
143provide the raw GPS module data.
144
aafe11cf
SBS
145***** Install packages via ~apt~
146Run the following command to install the required packages.
147: $ sudo apt install usbmount eject gpsd gpsd-clients python-gps pps-tools ntp
148
149***** Modify ~/boot/config.txt~
150In order to tell the Raspberry Pi to expect PPS data on ~BCM 18~ (pin
151number 12; see [[https://pinout.xyz/][RaspPi pinout]]), add the following line to
152~/boot/config.txt~ as described on [[https://ozzmaker.com/forums/topic/problems-with-pps-on-a-pi0w-running-raspian-and-attached-to-a-berrygps-imuv3/][this Ozzmaker page]]:
153
154: dtoverlay=pps-gpio,gpiopin=18
155
156PPS data can be confirmed by running:
157
158#+BEGIN_EXAMPLE
159$ sudo su -
160# ppstest /dev/pps0
161trying PPS source "/dev/pps0"
162found PPS source "/dev/pps0"
163ok, found 1 source(s), now start fetching data...
164source 0 - assert 1595708074.003644641, sequence: 219 - clear 0.000000000, sequence: 0
165source 0 - assert 1595708075.003709620, sequence: 220 - clear 0.000000000, sequence: 0
166source 0 - assert 1595708076.003779580, sequence: 221 - clear 0.000000000, sequence: 0
167source 0 - assert 1595708077.003850580, sequence: 222 - clear 0.000000000, sequence: 0
168#+END_EXAMPLE
169
170***** Add udev rule
171As per [[https://www.slsmk.com/how-to-setup-a-gps-pps-ntp-time-server-on-raspberry-pi/][the slsmk.com]] guide, create symbolic links expected by ~ntp~
172pointing to the PPS device. This may be performed by creating the file:
173
174: /etc/udev/rules.d/09-pps.rules
175
176with the contents:
177
178#+BEGIN_EXAMPLE
179KERNEL=="ttyAMA0", SUBSYSTEM=="tty", DRIVER=="", OWNER=="root", GROUP=="tty", MODE=="0777", SYMLINK+="gps0"
180#+END_EXAMPLE
181
182***** Modify ~/etc/modules~
183For older versions of Raspberry Pi, it may be necessary to explicitly
184require the ~pps-gpio~ module to be loaded by making sure
185~/etc/modules~ contains the line:
186
187: pps-gpio
188
189According to [[https://www.raspberrypi.org/forums/viewtopic.php?p=757747#p757747][this]] post on 2015-05-13T09:14 by [[https://www.raspberrypi.org/forums/memberlist.php?mode=viewprofile&u=31454][ame]] on the Raspberry Pi
190forums,
191
192#+BEGIN_QUOTE
193rowlandski wrote:
194> Hi,
195>
196> I want the RPi to load/probe the w1-gpio module on boot.
197>
198> I have added:
199>
200> sudo modprobe w1-gpio
201>
202> To the etc/modules file, but on boot it is not loaded.
203> I have checked this by the lsmod command. If i then enter the above line manually and then check it's there loaded.
204>
205> What's wrong with my line on code in the modules file?
206>
207> Thanks
208
209You no longer need to load modules for some devices. It's handled by devicetree.
210
211Search for "devicetree" on the forum, or start here:
212https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314
213#+END_QUOTE
214
215As of 2020-07-25, using Raspbian Buster 10 with a BerryGPS-IMU v3,
216~/etc/modules~ did not need to be modified.
217
218***** Remove DHCP client hooks
219As per [[https://www.slsmk.com/how-to-setup-a-gps-pps-ntp-time-server-on-raspberry-pi/][this]] guide, "remove ntp DHCP hook (so that it doesn't override ntp settings)".
220
221This can be performed by running the following command (shown in
222script form for readability):
223
224#+BEGIN_EXAMPLE
225if [ -f "/etc/dhcp/dhclient-exit-hooks.d/ntp" ]; then
226 mv /etc/dhcp/dhclient-exit-hooks.d/ntp /etc/dhcp/dhclient-exit-hooks.d/xxxntp-orig;
227else
228 echo "NTP exit hook does not exist";
229fi;
230#+END_EXAMPLE
231
6bdc2473
SBS
232*** Normal Startup
233*** Normal Operation
234*** Normal Shutdown
235*** Unscheduled Shutdown
236
237