| 1 | * Time Tracking |
| 2 | This 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 |
| 4 | was updated by Steven Baltakatei Sandoval on ~2020-10-13T18:02Z~ |
| 5 | |
| 6 | ** Development Task list |
| 7 | *** Set up prototype unit |
| 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] |
| 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~. |
| 15 | - [[https://raspberryautomation.com/connect-multiple-ds18b20-temperature-sensors-to-a-raspberry-pi/][Raspberry Autom]] article on specifying custom GPIO pin. |
| 16 | *** Document prototype unit |
| 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 | |
| 22 | Explanation: |
| 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 | |
| 32 | **** TODO Integrate DHCP details from gregledet tutorial |
| 33 | http://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 | |
| 39 | driftfile /var/lib/ntp/ntp.drift |
| 40 | logfile /var/log/ntp.log |
| 41 | |
| 42 | # Leap seconds definition provided by tzdata |
| 43 | leapfile /usr/share/zoneinfo/leap-seconds.list |
| 44 | |
| 45 | # Enable this if you want statistics to be logged. |
| 46 | statsdir /var/log/ntpstats/ |
| 47 | |
| 48 | statistics loopstats peerstats clockstats |
| 49 | filegen loopstats file loopstats type day enable |
| 50 | filegen peerstats file peerstats type day enable |
| 51 | filegen 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 |
| 56 | server time.nist.gov iburst minpoll 5 maxpoll 5 |
| 57 | server tick.usno.navy.mil iburst minpoll 5 maxpoll 5 |
| 58 | server 0.us.pool.ntp.org iburst minpoll 5 maxpoll 5 |
| 59 | server 0.us.pool.ntp.org iburst minpoll 5 maxpoll 5 |
| 60 | server 0.us.pool.ntp.org iburst minpoll 5 maxpoll 5 |
| 61 | server 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 |
| 72 | server 127.127.22.0 minpoll 4 maxpoll 4 true |
| 73 | fudge 127.127.22.0 flag3 1 refid kPPS |
| 74 | |
| 75 | # GPS PPS reference (NTP2) |
| 76 | server 127.127.28.2 minpoll 4 maxpoll 4 |
| 77 | fudge 127.127.28.2 refid SHM2 |
| 78 | |
| 79 | # GPS Serial data reference (NTP0) |
| 80 | server 127.127.28.0 minpoll 4 maxpoll 4 prefer |
| 81 | fudge 127.127.28.0 time1 +0.593 refid GPS |
| 82 | |
| 83 | # Fix False tickers |
| 84 | tos 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. |
| 95 | restrict -4 default kod notrap nomodify nopeer noquery limited |
| 96 | restrict -6 default kod notrap nomodify nopeer noquery limited |
| 97 | |
| 98 | # Local users may interrogate the ntp server more closely. |
| 99 | restrict 127.0.0.1 |
| 100 | restrict ::1 |
| 101 | |
| 102 | # Needed for adding pool entries |
| 103 | restrict 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 | |
| 125 | ** Narrative |
| 126 | The ~ninfacyzga-01~ device is equipped with an Ozzmaker BerryGPS-IMU |
| 127 | module which provides time and location data to ~gpsd~ and ~ntp~. The |
| 128 | time is provided by GPS satellites which themselves are |
| 129 | equipped [fn:nasa_20020408_atomicclock] with atomic clocks. This |
| 130 | extremely accurate set of clocks are needed since a GPS receiver |
| 131 | calculates its position in space using a General Relativity |
| 132 | calculation that uses the small variations in the time stamps received |
| 133 | from each satellite. This means that ~gpsd~ may be used to set the |
| 134 | system clock without a need for an internet connection to a default |
| 135 | Debian time server; ~ninfacyzga-01~ can be its own time server. |
| 136 | |
| 137 | [fn:nasa_20020408_atomicclock] Title:[[https://science.nasa.gov/science-news/science-at-nasa/2002/08apr_atomicclock/][Tick-Tock Atomic Clock]]; |
| 138 | Date: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: |
| 139 | 2010-04-29 |
| 140 | |
| 141 | ** Description |
| 142 | *** Hardware |
| 143 | Ozzmaker BerryGPS-IMU, Version 3 |
| 144 | *** Software |
| 145 | This guide describes steps that may be used to convert a Raspberry Pi |
| 146 | into a time server using ~gpsd~. |
| 147 | ** Operating Procedures |
| 148 | *** Initial Startup |
| 149 | **** Install Raspbian 10 (Buster) onto a Raspberry Pi Zero W. |
| 150 | |
| 151 | |
| 152 | **** Install Hardware |
| 153 | See [[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 | |
| 156 | Connect the ~T_PULSE~ connection on the BerryGPS-IMU-3 to GPIO pin 18 |
| 157 | (ex: with solder and wire) in order to provide the PPS data signal |
| 158 | generated by the BerryGPS-IMU to the Raspberry Pi. Processing of this |
| 159 | data signal is handled by adding a line to ~/boot/config.txt~ in the |
| 160 | next section ("Install Software"). |
| 161 | |
| 162 | **** Install Software |
| 163 | These instructions assume that ~gpsd~ has already been setup to |
| 164 | provide NMEA sentences to ~gpspipe~ for location. See the ~README.org~ |
| 165 | in ~doc/location~ for details. Basically, ~gpsd~ needs to be told via |
| 166 | its ~/etc/default/gpsd~ configuration file of which ~/dev/ttyS0~ will |
| 167 | provide the raw GPS module data. |
| 168 | |
| 169 | ***** Install packages via ~apt~ |
| 170 | Run 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~ |
| 174 | In order to tell the Raspberry Pi to expect PPS data on ~BCM 18~ (pin |
| 175 | number 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 | |
| 180 | PPS data can be confirmed by running: |
| 181 | |
| 182 | #+BEGIN_EXAMPLE |
| 183 | $ sudo su - |
| 184 | # ppstest /dev/pps0 |
| 185 | trying PPS source "/dev/pps0" |
| 186 | found PPS source "/dev/pps0" |
| 187 | ok, found 1 source(s), now start fetching data... |
| 188 | source 0 - assert 1595708074.003644641, sequence: 219 - clear 0.000000000, sequence: 0 |
| 189 | source 0 - assert 1595708075.003709620, sequence: 220 - clear 0.000000000, sequence: 0 |
| 190 | source 0 - assert 1595708076.003779580, sequence: 221 - clear 0.000000000, sequence: 0 |
| 191 | source 0 - assert 1595708077.003850580, sequence: 222 - clear 0.000000000, sequence: 0 |
| 192 | #+END_EXAMPLE |
| 193 | |
| 194 | ***** Add udev rule |
| 195 | As 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~ |
| 196 | pointing to the PPS device. This may be performed by creating the file: |
| 197 | |
| 198 | : /etc/udev/rules.d/09-pps.rules |
| 199 | |
| 200 | with the contents: |
| 201 | |
| 202 | #+BEGIN_EXAMPLE |
| 203 | KERNEL=="ttyAMA0", SUBSYSTEM=="tty", DRIVER=="", OWNER=="root", GROUP=="tty", MODE=="0777", SYMLINK+="gps0" |
| 204 | #+END_EXAMPLE |
| 205 | |
| 206 | ***** Modify ~/etc/modules~ |
| 207 | For older versions of Raspberry Pi, it may be necessary to explicitly |
| 208 | require the ~pps-gpio~ module to be loaded by making sure |
| 209 | ~/etc/modules~ contains the line: |
| 210 | |
| 211 | : pps-gpio |
| 212 | |
| 213 | According 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 |
| 214 | forums, |
| 215 | |
| 216 | #+BEGIN_QUOTE |
| 217 | rowlandski 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 | |
| 233 | You no longer need to load modules for some devices. It's handled by devicetree. |
| 234 | |
| 235 | Search for "devicetree" on the forum, or start here: |
| 236 | https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314 |
| 237 | #+END_QUOTE |
| 238 | |
| 239 | As 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 |
| 243 | As 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 | |
| 245 | This can be performed by running the following command (shown in |
| 246 | script form for readability): |
| 247 | |
| 248 | #+BEGIN_EXAMPLE |
| 249 | if [ -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; |
| 251 | else |
| 252 | echo "NTP exit hook does not exist"; |
| 253 | fi; |
| 254 | #+END_EXAMPLE |
| 255 | |
| 256 | *** Normal Startup |
| 257 | *** Normal Operation |
| 258 | *** Normal Shutdown |
| 259 | *** Unscheduled Shutdown |
| 260 | |
| 261 | |