GPS
chrony
NanoPi

NanoPI NEO2にGPSをつなぐ(PPSなし)簡易編

はじめに

NanoPI NEO2にGPSを繋ぎ時計合わせを行いました。とりあえずPPSは繋がず、シリアルインターフェースのGPSをUSBシリアルアダプタでつないだ簡易編です。
PPSを接続したい場合はNanoPI NEO2にGPSをつなぐ(PPS編)に記しました。けれども、簡易編の上に積み上げる形で作りますのでこちらを読んでからお読みください。

材料

前提

NanoPI Neo2にdebian (armbian) をこちらからいただきました。
それを拙著の方法でSSD化してあります。NAS Kitにしたのでアルミケースのシールド効果でGPS内蔵は絶望的です。そこでUSBに挿して延長も効く方法にしました。

手順

RTCを繋ぐ

USB-serialをケーブルでGPSに繋ぎます。

  • +5V --- +5V
  • TxD --- TxD
  • RxD --- RxD
  • GND --- GND です。 間違えると壊します。慎重にやりましょう。 USBシリアルのTxD, RxDの表記はまちまちです。「TxDを繋ぐ端子(入力)」の意味で書かれている場合と「自分が送信するのでTxD(出力)]の両方があるのです。まるで逆です。へたに繋ぐと壊しますので、取説をよく読み分からなければオシロスコープで見るか、10kΩぐらいの抵抗を直列に入れて試します。

gpsdの導入

apt install gpsd gpsd-clients
mkdir /etc/gpsd

/etc/gpsd/gpsd.confの設定

START_DAEMON="true"
USBAUTO="false"
DEVICES="/dev/ttyUSB0"
GPSD_OPTIONS="-n"

/lib/systemd/system/gpsd.serviceの設定

[Unit]
Description=GPS (Global Positioning System) Daemon
Requires=gpsd.socket
# Needed with chrony SOCK refclock
After=chronyd.service

[Service]
EnvironmentFile=-/etc/gpsd/gpsd.conf
ExecStart=/usr/sbin/gpsd -N $GPSD_OPTIONS $DEVICES

[Install]
Also=gpsd.socket

自動起動

update-rc.d gpsd enable

chronydの導入または設定変更

Chronydは、ntpdより新しいntp serverです。ntpdに不満を持った方が作りました。

atp install chrony

/etc/chrony/chrony.confの設定変更

次の3行を改変します。

# information about usuable directives.
pool ntp.jst.mfeed.ad.jp
refclock SHM 0  delay 0.5 refid NEMA

chronydの再起動

systemctl restart chrony

動作確認

gpsmonでそれなりの値が取れることを確認します。

tcp://localhost:2947          NMEA0183>
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
xTime: n/a                      Lat: n/a               Lon: n/a                x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq Cooked TPV qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x GPGGA GPGSA GPRMC GPZDA GPGRS GPGST GPGSV                                    x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq Sentences qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
lqqqqqqqqqqqqqqqqqqklqqqqqqqqqqqqqqqqqqqqqqqqqqqqklqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
xCh PRN  Az El S/N xxTime:      003303.799       xxTime:      003303.799       x
x 0                xxLatitude:                   xxLatitude:                   x
x 1                xxLongitude:                  xxLongitude:                  x
x 2                xxSpeed:     0.00             xxAltitude:                   x
0.00               xxCourse:                     xxQuality:   0   Sats:  0     x
V 4                xxStatus:            FAA: N   xxHDOP:                       x
x 5                xxMagVar:                     xxGeoid:                      x
x 6                xmqqqqqqqqqqq RMC qqqqqqqqqqqqjmqqqqqqqqqqq GGA qqqqqqqqqqqqj
x 7                xlqqqqqqqqqqqqqqqqqqqqqqqqqqqqklqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x 8                xxMode: A1 Sats:              xxUTC: 003303.799RMS: 0.000   x
      V=           xxDOP: H=      V=      P=     xxMAJ: 99999     MIN: 99999   x
x10                xxTOFF:                       xxORI: 00.0      LAT: 99999   x
x11                xxPPS:                        xxLON: 99999     ALT: 99999   x
mqqqqqq GSV qqqqqqqjmqqqqqqqq GSA + PPS qqqqqqqqqjmqqqqqqqqqqq GST qqqqqqqqqqqqj

chronycで同期状態を見ます。

# chronyc
chrony version 3.0
Copyright (C) 1997-2003, 2007, 2009-2017 Richard P. Curnow and others
chrony comes with ABSOLUTELY NO WARRANTY.  This is free software, and
you are welcome to redistribute it under certain conditions.  See the
GNU General Public License version 2 for details.

chronyc> sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
#? NEMA                          0   4     0     -     +0ns[   +0ns] +/-    0ns
^+ ntp1.jst.mfeed.ad.jp          2   6   377    16   -238us[ -238us] +/-   93ms
^+ ntp3.jst.mfeed.ad.jp          2   6   377    15   +373us[ +373us] +/-  119ms
^* ntp2.jst.mfeed.ad.jp          2   6   377    16  +2151ns[ +111us] +/-   87ms
chronyc>

注意

この用途でGPS基板に電池を載せるのは無駄です。

結論

今回もあっさりGPS Time Serverが出来上がりました。
次にPPSを繋いでStratum-1を目指そうと思います。