0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

NTP ST1(GPS)サーバの自動起動

Last updated at Posted at 2022-03-28

GPSなST1も自動起動にしてみました。

getnema.rb
#!/usr/local/bin/mruby

port = "/dev/cuau0"

ser = SerialPort.new(port, 9600, 8, 1, 0)
ser.flow_control=0

ser.flush

getutc = 0

while getutc == 0 do
  line = ser.gets
  para = line.split(",")
  if para[0] == "$GPZDA"
    print para[4] + para[3] + para[2] + para[1].slice(0,4) + "." + para[1].slice(4,2)
    getutc = 1
  end
  if para[0] == "$GPRMC"
    print para[9].slice(4,2) + para[9].slice(2,2) + para[9].slice(0,2) + para[1].slice(0,4) + "." + para[1].slice(4,2)
    getutc = 1
  end
end

これで拾ったUTC時間をdate -uで設定したあとにntpdを起動します。

ST2は以下のようにしました。

#!/bin/sh

while :
do
	ntpdate 10.0.1.22
	if [ $? == 0 ]; then
		break
	fi
	ntpdate 10.0.1.20
	if [ $? == 0 ]; then
		break
	fi
done

ntpd -p /var/run/ntpd.pid

ST1から日時を拾えてからntpdを起動します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?