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.

Sunday, July 21, 2024

Crowdsec - Grafana Dashboard and Telegraf/InfluxDB import

 

 

For a while my Crowdsec dashboard in Grafana was broken. Finally making some time to get it back up and happy to share my configuration with you here. Without additional explanation for now, but feel free to ask questions in the comments.

https://gist.github.com/qistoph/82b3beecffe2914694eb7f4b7d465047

 

Tuesday, October 17, 2023

"Find" without deeper hits

Sometimes I want find to ignore any deeper laying hits. Basically I want to find all the directories and files containing `subject` unless a high directory is also a hit.

Say I would want to find all my projects touching on subject I often use the command below and get the following result.

 $ find . -iname '*subject*'
./some_project/subject.h
./another_project/file_with_subject.txt
./subject_project ./subject_project/subject_main.c
./subject_project/subject_other.c
./subject_project/subject_data.bin
./subject_project/file_with_subject.txt
./last_project/touching_subject.yaml

Todat I finally looked into this and found the answer:

$ find . -iname '*subject*' -prune
./some_project/subject.h
./another_project/file_with_subject.txt
./subject_project
./last_project/touching_subject.yaml

From the man page on -prune: ¨if the file is a directory, do not descend into it."

Friday, August 26, 2022

Switch Logitech Bolt mouse along with keyboard

 A follow-up to my last post. The "integrated" solution with my Logitech Bolt does, unfortunately, not include switching them together using the buttons on the keyboard.

On one of the computers (1) using Bolt I'm not allowed to add software. On the other one (2) I am. With Solaar I am now at least able to switch from (2) to (1) from the keyboard and have the mouse follow suit.

Enable the Host Switch Channel 1 Diversion:

Add a rule, triggered on Host Switch Channel 1 and then Change Host to 1 for both devices.

Remains the challenge to make this work from (1) to (2) too.