Thursday, September 26, 2024

GPS NTP Server - Raspberry Pi

There are already a lot of tutorials out there that explain how to set up NTP and GPSd on a Raspberry i. This is a short blog with my results and additions.

The GPS module I am using is a GT-U7 compatible met NEO-6M. The main chip is a U-blox 7 (UBX-G7020-KT).


Set hostname

/etc/hostname

Setup sudo

/etc/sudoers:
Defaults:%sudo env_keep += "SSH_AGENT_PID SSH_AUTH_SOCK"

Disable serial terminal

raspi-config

  • 5. Interface
  • P6. Serial
  • Shell: no
  • Port enabled: yes

Connect PINs

  • VCC - 3v3 (1)
  • GND - GND (6)
  • RX -TX (8)
  • TX - RX (10)
  • PPS - GPIO 18 (12)

GPSd

Reboot

Check if data available on serial:

$ cat /dev/ttyAMA0

Install GPSd

$ sudo apt install gpsd

Configure settings:

/etc/default/gpsd:
GPSD_OPTIONS="-n -G"
DEVICES="/dev/ttyAMA0 /dev/pps0"
USBAUTO="false"


Enable and start gpsd

sudo systemctl enable gpsd
sudo systemctl start gpsd

Check results with gpsmon and cgps

$ gpsmon $ cgps

Enable PPS

/boot/config.txt: dtoverlay=pps-gpio,gpiopin=18

/etc/modules-load.d/modules.conf:
pps-gpio

/etc/ntp/ntp.conf:
# GPS as source
server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 time1 0.127 stratum 2 refid GPS
server 127.127.28.2 minpoll 4 maxpoll 4 prefer
fudge 127.127.28.2 refid PPS

Monitoring with Telegraf

Telegraf monitoring (GPU access):

sudo usermod -a -G video telegraf

Telegraf sensors (CPU temp)

sudo apt install lm-sensors

/etc/telegraf/telegraf.conf

[global_tags]
[agent]
interval = "30s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = "0s"
hostname = ""
omit_hostname = false
[[outputs.influxdb]]
urls = ["http://influx:8086"]
database = "telegraf"
username = "telegraf"
password = "ASDFASDFASDFASDFASDFASDF"
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
core_tags = false
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
[[inputs.diskio]]
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.processes]]
[[inputs.swap]]
[[inputs.system]]
[[inputs.ntpq]]
options = "-p -n"
[[inputs.sensors]]
[inputs.sensors.tagdrop]
feature = ["in0"]
#[[inputs.temp]]
[[inputs.exec]]
commands = ["/usr/bin/vcgencmd measure_temp"]
name_override = "sensors"
data_format = "grok"
grok_patterns = ["%{NUMBER:temp_input:float}"]

# tag:feature = "temp_gpu"
[inputs.exec.tags]
feature = "temp_gpu"

GPSd socket enable remote access

/lib/systemd/system/gpsd.socket

# To allow gpsd remote access, start gpsd with the -G option and
# uncomment the next two lines:
ListenStream=[::]:2947
ListenStream=0.0.0.0:2947

Start gpsd after pps1 becomes available

/lib/systemd/system/gpsd.service Under [Service] add:

ExecStartPre=/usr/bin/test -c /dev/pps1
ExecStart=/usr/sbin/gpsd $GPSD_OPTIONS $OPTIONS $DEVICES
RestartSec=10s
Restart=on-failure

Influxdb monitoring of gpsd: as root:

# apt install python3-influxdb
# cd /opt
# git clone https://github.com/qistoph/gpsd-influx
# cd gpsd-influx
# cp gpsd-influx.service /etc/systemd/system
# systemctl daemon-reload
# systemctl enable gpsd-influx
# systemctl start gpsd-influx


I²C Display

Enable I2C Interface:
raspi-config

Wiring (display - rpi):
  • GND - GND
  • VCC - 3V3
  • SDA - SDA (3)
  • SCL - SCL (5)
Install packages:
# apt install i2c-tools python3-luma.oled

Run ntp-gps-oled.py

Remaining

Apparently there is a bug in gpsd on Raspbian Bookworm which makes gpsd instable. My issues was that gpsd stopped reporting the correct location after the initial fix, of using ublox. Forcing a reset of the GPS module enabled NMEA and made gpsd recover. Until a reboot.

Compiling gpsd 3.25 from source fixed that.

Note that for Raspbian I did need to include sudo scons udev-install, to install the systemd service.

No comments:

Post a Comment