Linux utilities

從GPS NMEA data 同步Linux 系統時間

今天被詢問到如何讀取GPS時間資料並且更新系統時間.

步驟如下(以Debian 為例):

1. 安裝 gpsd, gpsd-client (apt-get install gpsd gpsd-client)

2. 設定gpsd 設定檔 (/etc/default/gpsd), 填入GPS port

3. 啟動gpsd.

4. 執行下列script~ 大功告成

[code language=”bash”]
# fetch GPS time from NMEA data
time=`gpspipe -R 127.0.0.1 -n20 | grep GPRMC | awk -F"," ‘{print $10" "$2}’`
# convert GPS time to date format
date="20${time:4:2}-${time:2:2}-${time:0:2} ${time:7:2}:${time:9:2}:${time:11:2}"
# Sync. with system time.
date -us "$date"
[/code]

有關GPRMC或者其他NMEA data的意義可參照下列網站~
ref: http://aprs.gids.nl/nmea/#rmc

2015-06-03_181307

發表迴響