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