{"id":456,"date":"2014-12-24T13:38:03","date_gmt":"2014-12-24T05:38:03","guid":{"rendered":"http:\/\/blog.yaojun.sg\/?p=456"},"modified":"2017-08-12T20:31:31","modified_gmt":"2017-08-12T12:31:31","slug":"ntp-yaojun-sg-stratum-1-ntp-server-on-a-raspberry-pi","status":"publish","type":"post","link":"https:\/\/blog.yaojun.sg\/?p=456","title":{"rendered":"ntp.yaojun.sg &#8211; Stratum-1 NTP server on a Raspberry Pi"},"content":{"rendered":"<p>I have been running ntp.yaojun.sg for NTP service on a Raspberry PI for a while. This is service is part of pool.ntp.org and responds to sg.pool.ntp.org and asia.pool.ntp.org. However, my\u00a0SD card decided to give up recently\u00a0when\u00a0I wanted to explore SNMP\u00a0tools for monitoring purposes.<\/p>\n<p>The <a href=\"http:\/\/ava.upuaut.net\/store\/index.php?route=product\/product&amp;path=59_60&amp;product_id=95\">GPS module<\/a> I am using is from HAB. I gotten this particular\u00a0module late last year built specifically for the older Raspberry Pi Model B. My NTP service was made public\u00a0around March 2014 using a ready made <a href=\"http:\/\/ntpi.openchaos.org\/downloads\/\">image<\/a>. However, just\u00a0looking at how 2014 turn out, it is important to keep both\u00a0base system and NTP patched. In addition, it is not advisable to just run a &#8220;BlackBox&#8221; because you never know what&#8217;s going on inside it. So here I am restoring the service from a clean Raspbian image.<\/p>\n<p>Do note that the module requires a GPS 3D lock for PPS to work, so remember to connect your antenna. I was scratching my head on why my PPS was not working and had to contact the friendly vendor to ask if I have a dead card.<\/p>\n<p>Installing Raspbian into Raspberry Pi is a straight forward process. After the basic configuration (resizing the File System, locale, timezone and etc), remember to configure Rasbian to <span style=\"text-decoration: underline;\">disable the serial shell under the advanced settings<\/span><em>. <\/em>Also\u00a0update and patch the system.<\/p>\n<pre>apt-get update\r\napt-get dist-upgrade\r\nrpi-update<\/pre>\n<p>Recent development in Raspbian allows the use of PPS devices without recompiling the kernel. We need to configure the system to use the PPS on the GPIO port.<\/p>\n<p>Edit \/boot\/config.txt add the following line,<\/p>\n<pre>dtoverlay=pps-gpio,gpiopin=18<\/pre>\n<p>Add the following line to\u00a0\/etc\/modules,<\/p>\n<pre>pps-gpio<\/pre>\n<p>Install the GPS and PPS tools<\/p>\n<pre>apt-get install pps-tools libcap-dev <span style=\"line-height: 1.5;\">gpsd gpsd-clients python-gps<\/span><\/pre>\n<p>Configure gpsd to use the GPS sensor at\u00a0<em>\/dev\/ttyAMA0<\/em> and enable <em>-n<\/em> as a option using dpkg-reconfigure to allow ntpd to use the GPS clock and remember to enable the gpsd daemon<\/p>\n<pre>systemctl enable gpsd.socket\r\ndpkg-reconfigure gpsd<\/pre>\n<p>and you will be able to see your GPS data using<\/p>\n<pre>cgps -s<\/pre>\n<p>Check that your PPS clock is working<\/p>\n<pre>ppstest \/dev\/pps0<\/pre>\n<p>Remove default NTP client (which does not work with the GPS and PPS)<\/p>\n<pre>apt-get remove ntp<\/pre>\n<p>Install NTP dependencies to ensure successful build of NTP from source<\/p>\n<pre>apt-get install libbsd-dev libssl-dev<\/pre>\n<p>Install <em>checkinstall<\/em> to compile source to binaries safely<\/p>\n<pre>apt-get install checkinstall<\/pre>\n<p>Get the latest NTP source code\u00a0from\u00a0<a href=\"http:\/\/www.ntp.org\/downloads.html\">www.ntp.org<\/a>, untar and compile. This is not a fancy high speed CPU so compiling will take some time (estimate 30 minutes).<\/p>\n<pre>.\/configure --enable-linuxcaps --with-NMEA --with-ATOM\r\nmake \r\ncheckinstall<\/pre>\n<p>Follow through <em>checkinstall<\/em> wizard.<\/p>\n<p>Symbolically link compiled binaries to well defined paths,<\/p>\n<pre>ln -s \/usr\/local\/bin\/ntp* \/usr\/bin\/\r\nln -s \/usr\/local\/sbin\/ntp* \/usr\/sbin\/<\/pre>\n<p>Edit \/etc\/init.d\/ntp to use the compiled binaries,<\/p>\n<pre>#PATH=\/sbin:\/bin:\/usr\/sbin:\/usr\/bin\r\nPATH=\/usr\/local\/bin:\/sbin:\/bin:\/usr\/sbin:\/usr\/bin<\/pre>\n<pre class=\"p1\">#DAEMON=\/usr\/sbin\/ntpd\r\nDAEMON=\/usr\/local\/sbin\/ntpd<\/pre>\n<p>Edit \/etc\/ntp.conf to use PPS and GPS as Stratum-0 and Stratum-1. This will make PPS disciplined by GPS and verified by other NTP servers.<\/p>\n<pre class=\"p1\"># pps-gpio on \/dev\/pps0\r\nserver 127.127.22.0 minpoll 4 maxpoll 4\r\nfudge 127.127.22.0 refid PPS\r\nfudge 127.127.22.0 flag3 1\u00a0 # enable kernel PLL\/FLL clock discipline<\/pre>\n<pre class=\"p1\"># gpsd shared memory clock\r\nserver 127.127.28.0 minpoll 4 maxpoll 4 prefer\u00a0 # PPS requires at least one preferred peer\r\nfudge 127.127.28.0 refid GPSD\r\nfudge 127.127.28.0 time1 +0.150 stratum 1 # coarse processing delay offset<\/pre>\n<p>Lock the ntp binaries to prevent apt from overwriting from packages<\/p>\n<pre>apt-make hold ntp<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have been running ntp.yaojun.sg for NTP service on a Raspberry PI for a while. This is service is part of pool.ntp.org and responds to sg.pool.ntp.org and asia.pool.ntp.org. However, my\u00a0SD card decided to give up recently\u00a0when\u00a0I wanted to explore SNMP\u00a0tools for monitoring purposes. The GPS module I am using is from HAB. I gotten this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[12,17,20,21],"class_list":["post-456","post","type-post","status-publish","format-standard","hentry","category-tech","tag-linux","tag-ntp","tag-raspberrypi","tag-raspbian"],"_links":{"self":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts\/456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=456"}],"version-history":[{"count":3,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":474,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts\/456\/revisions\/474"}],"wp:attachment":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}