NTP GPS

Материал из Wiren Board
Версия от 17:31, 14 июля 2020; Brainroot (обсуждение | вклад) (Более простой способ без сборки ntpq, все из пакетов.)

Статья носит рекомендательный характер и не предназначена для конечных пользователей.

Рабочий вариант от freemanon https://support.wirenboard.com/t/nastrojka-modulya-gps/5353/9

Варианты с NMEA Reference Clock Driver (с драйвером 20 - 127.127.20.0) так и не заработали, работающее решение нашлось здесь https://blog.rapid7.com/2015/07/27/adding-a-gps-time-source-to-ntpd/. Используется SHM Reference Clock (с драйвером 28 - 127.127.28.0)

У меня получилось следующее:

1. ставим пакеты

apt install ntp gpsd gpsd-clients

2. настраиваем gpsd

/etc/default/gpsd:
DEVICES="/dev/ttyMOD3"
GPSD_OPTIONS="-n"

3. настраиваем ntpd на всякий случай оставил локальный сервер со stratum 10

/etc/ntp.conf:
# local
server 127.127.1.0
fudge 127.127.1.0 stratum 10

# GPS
server 127.127.28.0 minpoll 4 maxpoll 4 prefer
fudge 127.127.28.0 time1 0.0 refid GPS
driftfile /var/lib/ntp/ntp.drift
restrict default nomodify notrust
disable auth

4. проверяем работу

root@wirenboard-AP2OY26Z:~# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 LOCAL(0)        .LOCL.          10 l  388   64  100    0.000    0.000   0.002
*SHM(0)          .GPS.            0 l    7   16  377    0.000    9.404  20.126



Устаревшее Инструкция от пользователя. Что сделать для сборки правильного нтп:

Поставить libcap-dev – без него не будет работать нтп с настройками, которые по умолчанию в системе и после ребута все сломается и придется через дебаг консоль убирать из загрузки нтп. Через apt-get не получилось – ставил через dpkg брал тут: https://packages.debian.org/wheezy/armel/libcap-dev/download Качаем отсюда нпт http://www.ntp.org/downloads.html (Production 4.2.8p6) tar zxvf ntp-4.2.8p6.tar.gz cd ntp-4.2.8p6 ./configure —enable-linuxcaps # для этого и нужен libcap-dev make make install service ntp stop cp /usr/local/bin/ntp* /usr/bin/ && sudo cp /usr/local/sbin/ntp* /usr/sbin/ #заменяем системный нтп новым улучшенным

Далее настраиваем нтп – надо создать алиалсы для драйвера 20 (https://www.eecis.udel.edu/~mills/ntp/html/drivers/driver20.html)

vi /etc/udev/rules.d/10-gps.rules

KERNEL=="ttyAPP2",NAME="%k",SYMLINK+="gps0",MODE="0660",GROUP="ntp"
KERNEL==“pps0",NAME="%k",SYMLINK+="gpspps0",MODE="0660",GROUP="ntp"

Можно еще использовать драйвер 22 – нтп + драйвер 20 (нмеа) или 28 (гпсд) Но 20 и так умеет ппс (flag1 1) и экспериментально я остановился на нем. (https://www.eecis.udel.edu/~mills/ntp/html/refclock.html)

Правим /etc/ntp.conf:

server 127.127.20.0 mode 17 minpoll 4 maxpoll 4 iburst prefer
fudge 127.127.20.0 flag1 1 flag2 0 time2 1.0 refid GPSP

time2 1.0 - это смещение времени гпс от ппс тк гпс и ппс асинхронны и если нет смещения то нтп отбранкует драйвер 20 – подбирается экспериментально по методике ниже (но думаю что для всех виренбордов 5 будет 1.0 (для пи2 у меня получилось 0.7)) https://support.ntp.org/bin/view/Support/ConfiguringNMEARefclocks

if you want a good estimation for fudge time2 (perhaps because PPS is not an option for you) you could use the following procedure:

Switch off the PPS processing for the NMEA driver and mark the clock as noselect. Set the fudge time2 to zero. Add a few good public time servers or another clock; here in Germany I can use my DCF77 radio clock for that purpose. Disable all output sentences of the GPS18x LVC but the GPRMC sentence. Restart the daemon and watch the offset for the NMEA clock. When the value gets stable, use the absolute value of the offset as fudge time2 for the NMEA driver. Optionally restart ntpd and verify that the offset remains small. Note the jitter, which is probably in the order of 5-10msec. If the offset is small enough (better than 2ms is doable, but takes a long time to stabilise), go to the next step. Otherwise fine-tune fudge time2 and repeat this step. Enable PPS processing again if you can. After restarting ntpd jitter and offset should decrease rather fast.

Finally, remove the noselect statement and enjoy your fast-locking NMEA clock with a Garmin GPS18x LVC!

Перезагружаемся и смотрим что есть наши алиасы

root@wirenboard:~# ls /dev/gps* 
/dev/gps0  /dev/gpspps0

Далее ждем минут 10 и ntpq -nc peer -c as -c rl Буква о у 127.127.20.0 – значит что последняя синхронизации с ппс (http://citrin.ru/net:ntpq)

root@wirenboard:~#  ntpq -nc peer -c as -c rl
remote           refid      st t when poll reach   delay   offset  jitter
==================================================================
o127.127.20.0    .GPSP.           0 l    8   16  377    0.000    0.000   0.008
*185.22.60.71    212.20.50.208    2 u   21   64  377    3.510   -0.048   0.132
+95.104.192.10   194.190.168.1    2 u   55   64  377   18.911   -1.880   0.093
-144.76.115.197  131.188.3.221    2 u    4   64  377   51.630   -6.302   0.509
+89.111.54.85    194.29.130.252   2 u   46   64  377   25.978    0.225   0.088
ind assid status  conf reach auth condition  last_event cnt
===============================================
1 30454  974a   yes   yes  none  pps.peer    sys_peer  4
2 30455  963a   yes   yes  none  sys.peer    sys_peer  3
3 30456  9424   yes   yes  none candidate   reachable  2
4 30457  933d   yes   yes  none   outlier              3
5 30458  943a   yes   yes  none candidate    sys_peer  3
associd=0 status=0415 leap_none, sync_uhf_radio, 1 event, clock_sync,
version="ntpd 4.2.8p6@1.3265 Wed Apr  6 16:13:39 UTC 2016 (2)",
processor="armv5tejl", system="Linux/4.1.15-imxv5-x0.1", leap=00,
stratum=1, precision=-17, rootdelay=0.000, rootdisp=1.120, refid=GPSP,
reftime=dab9e00e.9c7d01b8  Thu, Apr 14 2016  9:23:26.611,
clock=dab9e016.a2b1d422  Thu, Apr 14 2016  9:23:34.635, peer=30454, tc=4,
mintc=3, offset=0.000121, frequency=91.858, sys_jitter=0.007629,
clk_jitter=0.008, clk_wander=0.000

Это чтобы посмотреть ошибки и что выдает гпс

root@wirenboard:~# ntpq -c clockvar
associd=0 status=0011 1 event, clk_no_reply,
device="NMEA GPS Clock",
timecode="$GNRMC,092359.000,A,5549.0526,N,03735.1798,E,0.00,172.16,140416,,,A*78",
poll=3426, noreply=1, badformat=0, baddata=0, fudgetime2=1000.000,
stratum=0, refid=GPSP, flags=1

Дальше настраиваем нтп как нам надо – кому что можно откуда и так далее.