beta-tester / RPi-GPS-PPS-StratumOne

setup a Raspberry Pi as a Stratum One time server (GPS with PPS)
GNU General Public License v3.0
123 stars 27 forks source link

Setup Trouble on Pi Zero 2 W with MAX-M8Q GNSS HAT #10

Closed AlexLandherr closed 2 years ago

AlexLandherr commented 2 years ago

Hi,

I tried setting up this solution for my NTP server running on a Pi Zero 2 W and using the MAX-M8Q GNSS HAT. I am following this guide: NEO-M8T_GNSS_TIMING_HAT, NTP_Server

The setup shell script runs fine but when I run: watch -n1 chronyc sourcestats -v

I get this: Skärmbild (17)

What could I be doing wrong?

beta-tester commented 2 years ago

hi, the guide is not from me.

it looks to my they use the wrong serial port. it must be /dev/ttyAMA0 when it is using the GPIO pins for serial port and i use GPIO pin 4for PPS, but your module is using GPIO pin 18. aou have to disable bluetooth. you have to enable Serial Port but disable serial console.

normally all this my script is doing ecxept of the GPIO pin 18. but my script expects a fresh RasPi OS installation.

please try to use a fresh RasPi OS Bullseye installation, clone my project and run it. in the /boot/config.txt file you have to change
dtoverlay=pps-gpio,gpiopin=4 # /dev/pps0 to dtoverlay=pps-gpio,gpiopin=18 # /dev/pps0

AlexLandherr commented 2 years ago

Ok, thanks! I'll try it tomrrow.

AlexLandherr commented 2 years ago

Can I still set a static IPv4 address on the Pi Zero 2 W for my other computers on the same network so they can get the time from it?

beta-tester commented 2 years ago

yes, the script needs a working internet connection to install packages. once everything of GPS and PPS is working it does not need internet anymore but you still can use it if you want. the NTP service should be available to use for the other computers.

i told only to start with a fresh RasPi OS, because i don't know what changes were done on the system already. if you still have problems, it is easier to find a solution.

once everything is running, you can also change/install other things...

AlexLandherr commented 2 years ago

I tried a fresh install of Raspberry Pi OS Lite 32-bit (release date 2021-10-30) and in the official imager used Ctrl+Shift+X to open the advanced settings menu to enable SSH and password for it along with the system time zone which I set to "Etc/UTC".

Upon having successfully logged in I ran sudo apt update and sudo apt full-upgrade and let those processes complete. After that I installed git and cloned your repository, made the installation shell script executable and ran it allowing it to finish.

Subsequently I changed the line you said in /boot/config.txt to dtoverlay=pps-gpio,gpiopin=18 # /dev/pps0 as per instructions.

Then I set a static IPv4 address for the Pi according to this guide: raspberry-pi-static-ip-address

And after that I rebooted.

When I ran watch -n1 chronyc sourcestats -v I got this again: Skärmbild (19)

Based on my retelling of events should I just try again or am I missing something in your instructions?

beta-tester commented 2 years ago

do you get any output when you type in gpsmon ? if you don't get coordinates from the gps there, please try to specify the baud rate of your gps manually in the /etc/default/gpsd file. there is the line GPSD_OPTIONS="-n -r -b" append it with the -s <speed> (e.g. for a speed of 9600 baud) GPSD_OPTIONS="-n -r -b -s 9600" (if your GPS module uses a different speed, change the value according your device)

i guess the gpsd version of the distro is a one with broken autobaud mechanism.

to restart the gpsd and chrony services to take effect of the changes (without requireing rebooting the whole system):

sudo systemctl stop --now gpsd.{service,socket} && \
sudo systemctl restart --now chrony && \
sudo systemctl start --now gpsd
AlexLandherr commented 2 years ago

I got this from gpsmon: Skärmbild (21)

beta-tester commented 2 years ago

ok, then the communication with the GPS module is not working. did you already tried to specify the speed in the /etc/default/gpsd file ?

AlexLandherr commented 2 years ago

Yes, per the info here (I got the module from thepihut.com): MAX-M8Q_GNSS_HAT_for_RaspberryPi-_Specifications.pdf

And ran this version of your restart command: sudo systemctl stop --now gpsd.{service,socket} && sudo systemctl restart --now chrony && sudo systemctl start --now gpsd

beta-tester commented 2 years ago

the speed of 9600 baud for serial port should be good or did you set it up to another speed previously?

and you restarted the gpsd and chrony services / rebooted the system, and still no gps data?

AlexLandherr commented 2 years ago

I hadn't set it to another speed previously. And after restarting and running gpsmon I got the same result as per the image. A few weeks back I did remove the little battery holder for the HAT (with a soldering iron) as otherwise it wouldn't fit on the Pi Zero 2 W which has a little heatsink on it.

I did restart gpsd and chrony.

beta-tester commented 2 years ago

ok, without a battery i think it will always use the default 9600 baud. can you check if you get a PPS signal at least... with sudo ppstest /dev/pps0 you should get a periodic output (one line per second)

AlexLandherr commented 2 years ago

I got this recently: pi@raspberrypi:~ $ sudo ppstest /dev/pps0 trying PPS source "/dev/pps0" found PPS source "/dev/pps0" ok, found 1 source(s), now start fetching data... time_pps_fetch() error -1 (Connection timed out) time_pps_fetch() error -1 (Connection timed out) ^C

It might take a while for a lock.

beta-tester commented 2 years ago

can you stop the gpsd service and socket to free the serial port with: sudo systemctl stop --now gpsd.{service,socket}

and type in

stty -F /dev/ttyAMA0 9600 raw cs8 -cstopb -parenb
cat /dev/ttyAMA0

if you get some outout if not, hit Ctrl-C to abort and try to change the baud rate to 115200 another common value

ComputerSmiths commented 2 years ago

On Dec 27, 2021, at 1:23 PM, beta-tester @.***> wrote:

without a battery i think it will always use the default 9600 baud.

Also, without a battery Time To First Fix may take a long time, as it has to re-aquire the almanac, which is transmitted every 12.5 minutes.

73, Willie N1JBJ

AlexLandherr commented 2 years ago

I got this after waiting some 20 minutes: Skärmbild (23)

I even tried the extremes of the data rates listed here: MAX-M8Q_GNSS_HAT_for_RaspberryPi-_Specifications.pdf

beta-tester commented 2 years ago

slowly i run out of ideas. i don't have a RPi Zero v2. maybe there is something different according serial port.

you can install the package minicom to try to get output from your serial port. but i guess your system is now running without the correct time/date, becacuse chrony is not using the internet to sync the system time with my configuration. so maybe installing packages is not possible anymore, because the time difference is too big.

to tell chrony to use time servers from the internet as well, please run the following commands:

sudo mv /etc/chrony/stratum1/20-ntp-servers.conf{.disabled,}
sudo systemctl restart --now chrony
sleep 10
chronyc -m tracking sources

as output you should see four additional sources from the internet

then sudo apt install minicom to install the minicom package and run minicom -D /dev/ttyAMA0 try to get GPS output by changing the speed of the serial port

with [Ctrl]+[A],[Z] you can open the menu with [Ctrl]+[A],[P] you can open the serial setup (to change the speed) with [Ctrl]+[A],[X] you can cancel the program

AlexLandherr commented 2 years ago

The commands for minicom doesn't seem to be working over SSH. My SSH client on Windows 10 is PuTTY. Skärmbild (25)

beta-tester commented 2 years ago

oh, as @ComputerSmiths told, without a battery on your GPS module at each powercycle it may take a very long time to get a gps fix. PPS will work only with a fix, NMEA data will normally come immediately with at least "empty" data items until a fix.

The commands for minicom doesn't seem to be working over SSH. My SSH client on Windows 10 is PuTTY.

then try to change the serial port speed in minicom, hit the keys [Ctrl] and [A] then [P].

AlexLandherr commented 2 years ago

The problem is that I get no response or indication that anything has happened on the SSH output window. Just that blank look and the row at the bottom. And I have not rebooted it for the last 1.5 - 2 hours.

AlexLandherr commented 2 years ago

If none of this works do you have a recommended Pi Zero W-friendly GPS HAT for your timing setup?

beta-tester commented 2 years ago

maybe the [Ctrl] key is not passing through Putty to the RPi. are there setting to pass through all control keys? maybe you have more luck with the free version of MobaXTerm or you try to start minicom with the speed given at commandline like: minicom -D /dev/ttyAMA0 -b 9600 -8 and try out different speeds.

your GPS module has TX, PPS or FIX indicator LED and do they lit up or are flashing?

AlexLandherr commented 2 years ago

It has a PPS LED, a TXD LED, a RXD LED and a PWR LED. The PPS one is not blinking.

beta-tester commented 2 years ago

If none of this works do you have a recommended Pi Zero W-friendly GPS HAT for your timing setup?

form the form-factor i would expect that your module IS already RPi Zero friendly.

It has a PPS LED, a TXD LED, a RXD LED and a PWR LED. The PPS one is not blinking.

but TXD should blinking otherwise i would not expect data comming from the GPS module. to the RPi.

there is another option to connect the GPS module via USB. if you have a cable you may connect the GPS to your windows PC i think Putty can also manage COM ports - only to see if you get any serial output and at what baud rate.

AlexLandherr commented 2 years ago

I'm going to try to redo the entire installation and check the physical connections. Will return tomorrow.

beta-tester commented 2 years ago

ok, i hope you will have luck tomorrow.

i updated my script and set up the speed to 9600 baud in the /etc/default/gpsd file and i enabled chrony to also take internet servers as source (to get at least the time from internet in case GPS and PPS is not working).

AlexLandherr commented 2 years ago

Thanks for your perseverance! If I fail with this one I might order another module. I would REALLY like this to work as the ping times to the closest NTP servers in Sweden where I live is around 40 milliseconds.

beta-tester commented 2 years ago

i just saw pictures of the GPS modules like you have and it seems there are different versions. does your module has jumpers on the top to select the output mode A: USB-GNSS, B: Pi-GNSS, C: Pi-USB. if you have such a module i think the jumpers have to be in mode B. both jumpers upright in the middle position if i see it right on the pictures. Screenshot from 2021-12-27 21-49-30

AlexLandherr commented 2 years ago

They have jumpers that sit like this: image0

AlexLandherr commented 2 years ago

The case is 3D-printed.

beta-tester commented 2 years ago

oh, looks like your module is in mode A: USB-GNSS so you will not getting serial output via GPIO

AlexLandherr commented 2 years ago

Ok! I'll shut it down and move the jumpers.

beta-tester commented 2 years ago

yes, move the jumpers one position to the right on your picture to mode B: Pi - GNSS. hope your will get serial output immediately on gpsmon when you start up everything again.

AlexLandherr commented 2 years ago

I got the PPS LED BLINKING!

Please excuse the All Caps. :)

beta-tester commented 2 years ago

does it work now? do you get something ao gpsmon and ppstest /dev/pps0... ?

AlexLandherr commented 2 years ago

Image confirming sucess (I hope): Skärmbild (27)

AlexLandherr commented 2 years ago

I have a few more questions if you don't mind?

beta-tester commented 2 years ago

:D ok everything is allright now. good that you showed me your picture, otherwise we would fail tomorrow as well.... ;)

beta-tester commented 2 years ago

yes, ask me if you have questions.

AlexLandherr commented 2 years ago
  1. Does the "PPS0" row at "Offset" say how many nanoseconds off the Pi:s system time is from UTC?

  2. Sort of ties into question 1: Does your solution/setup make sure I get UTC time on the Pi? And not GPS time which I understand is a couple of seconds off from UTC time.

  3. Since I've set a static IPv4 address on the Pi for my local home network could I now use that very address in how-to-set-custom-ntp-servers-in-recent-raspbian-stretch-systems to set the time on other Pi:s (my laptop has it's own GPS receiver for time syncing)?

  4. To make sure future me and others who find this thread understands the solution for this particular HAT: I needed to move the jumpers to position B --> clone the repository, make executable and run the shell script --> and run the watch -n1 chronyc sourcestats -v?

AlexLandherr commented 2 years ago

In comparison to the Waveshare guide this HAT is much cheaper than the NEO-M8T HAT. Somehow the timing HAT is much more expensive, by ~70 GBP.

AlexLandherr commented 2 years ago

One new issue when I ran ntpdate on another Pi on the same network: pi@raspberrypi:~ $ sudo ntpdate 192.168.1.12 27 Dec 22:16:35 ntpdate[19720]: no server suitable for synchronization found pi@raspberrypi:~ $

Why is this?

beta-tester commented 2 years ago
  1. Does the "PPS0" row at "Offset" say how many nanoseconds off the Pi:s system time is from UTC?

it is the offset between the current system time and the received PPS0 signal as far as i understand. use the commant chronyc tracking to see more detailed information about how accurate your system time is according to the reference source.

2. Sort of ties into question 1: Does your solution/setup make sure I get UTC time on the Pi? And not GPS time which I understand is a couple of seconds off from UTC time.

i think you mean the GPS time of the satellites are different over time, because they don't have/accumulate leap seconds. they are about 19 seconds up to now i think. your server uses and serves the correct UTC time not the GPS time. you can also see it in your chronyc output when you compare the offsets with the other internet time sources. if your system would be GPS time instead of UTC then the offset yourd be around 19 seconds off.

3. Since I've set a static IPv4 address on the Pi for my local home network could I now use that very address in [https://raspberrypi.stackexchange.com/questions/85670/how-to-set-custom-ntp-servers-in-recent-raspbian-stretch-systems](url)
   to set the time on other Pi:s (my laptop has it's own GPS receiver for time syncing)?

yes, put the ip address of your RPi Zero as NTP server to your other RPi's and Laptop and they sould be syncing thier time against your RPi Zero. on windows you can use w32tm /stripchart /computer:192.168.1.4 (replace the ip with yours) to show the how off your windows time is compared to your RPi. if your RPi has avahi running it should also be visibly by its ost name in your local network like "hostname.local" if you don't like using the ip address. (e.g. try ping zero.local from other coumputers in case your hostname is zero)

4. To make sure future me and others who find this thread understands the solution for this particular HAT: I needed to move the jumpers to position B --> clone the repository, make executable and run the shell script --> and run the `watch -n1 chronyc sourcestats -v`?

YES,

  1. the module must be in mode B: Pi - GNSS Screenshot from 2021-12-27 21-49-30
  2. clone the project git clone https://github.com/beta-tester/RPi-GPS-PPS-StratumOne
  3. and run the script bash install-gps-pps.sh
  4. adjust the PPS pin in the /boot/config.txt file from dtoverlay=pps-gpio,gpiopin=4 # /dev/pps0 to dtoverlay=pps-gpio,gpiopin=18 # /dev/pps0
  5. is your GPS module running at another speed than 9600 baud, you have to adjust the speed in the /etc/default/gpsd file. the option -s <speed> has to be adjusted in the line: GPSD_OPTIONS="-n -r -b -s 9600"
  6. reboot your RPi
  7. check if chrony is getting its time synced against one of the PPS0, PSM0 or PST0 sources at least after few minutes after your GPS has a fix.

PS.: do you power your RPi and your GPS module separately from USB? i think you only need to power one of both. the other will get its power over HAT connector.

PPS.: take a look to Stratum One servers to add a stratum one server near by you. here is am example of a Stratum one time server in sweden you can add it to your /etc/chrony/stratum1/20-ntp-servers.conf file:

# SP Technical Research Institute of Sweden, Stockholm Sweden 
server  ntp3.sptime.se  iburst  minpoll 4  maxpoll 4

and comment out the pool.ntp.org entry at the top of the file. the public community ntp servers are not always stratum one servers and less accurate.

beta-tester commented 2 years ago

One new issue when I ran ntpdate on another Pi on the same network: pi@raspberrypi:~ $ sudo ntpdate 192.168.1.12 27 Dec 22:16:35 ntpdate[19720]: no server suitable for synchronization found pi@raspberrypi:~ $

Why is this?

i don't know. where is that ntpdate command coming from?

the ntpdate program is to be retired from this distribution. ... ntpdate/stable 1:4.2.8p15+dfsg-1 armhf client for setting system time from NTP servers (deprecated)

depending on how your system is syncing its time systemd-timesyncd, chrony, ntpd, (depending what is installed)... you have to use its own mechanism to check its status.

sudo systemctl status systemd-timedated
sudo systemctl status chrony
sudo systemctl status ntpd

sudo journalctl -xe -u systemd-timedated
sudo journalctl -xe -u chrony
sudo journalctl -xe -u ntpd

man systemd-timedated
man chronyd
man ntpd

there should be only one single service running on the system to sync the time.

systemd-timesyncd is the default at RasPi OS Bullseye & Buster. systemd-timesyncd deactivates itself if chrony or ntpd is installed.

EDIT: a random and not too old link Command to sync time with NTP server in Linux

AlexLandherr commented 2 years ago

Results of suggested commands on the Pi I was trying to set the time on (not the same as the Pi Zero 2 W with the GPS):

> pi@raspberrypi:~ $ sudo systemctl status systemd-timedated
● systemd-timedated.service - Time & Date Service
     Loaded: loaded (/lib/systemd/system/systemd-timedated.service; static)
     Active: inactive (dead)
       Docs: man:systemd-timedated.service(8)
             man:localtime(5)
             man:org.freedesktop.timedate1(5)
pi@raspberrypi:~ $ sudo systemctl status chrony
Unit chrony.service could not be found.
pi@raspberrypi:~ $ sudo systemctl status ntpd
Unit ntpd.service could not be found.
pi@raspberrypi:~ $ sudo journalctl -xe -u systemd-timedated
~
-- Journal begins at Sat 2000-01-01 00:24:31 UTC, ends at Mon 2021-12-27 23:59:49 UTC. --
-- No entries --
pi@raspberrypi:~ $ sudo journalctl -xe -u chrony
~
-- Journal begins at Sat 2000-01-01 00:24:31 UTC, ends at Tue 2021-12-28 00:00:25 UTC. --
-- No entries --
pi@raspberrypi:~ $ sudo journalctl -xe -u ntpd
~
-- Journal begins at Sat 2000-01-01 00:24:31 UTC, ends at Tue 2021-12-28 00:00:40 UTC. --
-- No entries --
pi@raspberrypi:~ $
AlexLandherr commented 2 years ago

By the looks of chronyc tracking I'm about 17 nanoseconds behind UTC time?

pi@raspberrypi:~ $ chronyc tracking Reference ID : 50534D30 (PSM0) Stratum : 1 Ref time (UTC) : Tue Dec 28 00:04:29 2021 System time : 0.000000017 seconds slow of NTP time Last offset : -0.000000014 seconds RMS offset : 0.000000034 seconds Frequency : 4.179 ppm fast Residual freq : -0.000 ppm Skew : 0.001 ppm Root delay : 0.000000001 seconds Root dispersion : 0.000010140 seconds Update interval : 8.0 seconds Leap status : Normal pi@raspberrypi:~ $

beta-tester commented 2 years ago

Results of suggested commands on the Pi I was trying to set the time on (not the same as the Pi Zero 2 W with the GPS)

that's normal. most of them will give you nothing, because it is not installed. i thought you will see more from systemd-timedated. was/etc/systemd/timesyncd.conf already modified to use your RPi Zero's time server? what do you get with timedatectl

i realized, that i have also chrony installed (in client configuration) on my other RPi's i have. (just installed the package and added my local time server and one external stratum one server from the internet) so i can't remember what the above commands will show you normally.

By the looks of chronyc tracking I'm about 17 nanoseconds behind UTC time?

yes... kind of from the point of view of the RPi... at the time you was "looking" at tracking... plus some extra errors on top e.g. (i am no expert):

see also

oh, keep in mind, what you keep your time server + GNSS module at a constant temperature. e.g. when i open my window (specially in the winter) i can cleearly see it when i plot the tracking pps graph.

sudo gnuplot ~/RPi-GPS-PPS-StratumOne/gnuplot/chrony-tracking.gnuplot (you have to run it at the desktop)

beta-tester commented 2 years ago

i formated the link/url in your posts as they were put in a wrong format. the correct format is: [ <put the description to show here> ]( <put the url here> ) you put the url in the description part and the url part was nothing - so every time i clicked your url i got page not found. best is you write the url, select the full url and click to "Add a link" or Ctrl+K, then the url is correctly in the round brackets, you only has to fill the description to show in the square brackets.

i closed the issue, but you still can add comments if you have questons (i hopefully can answer correctly)

leave a star :star:, if you find my project useful ... :smiley:

EDIT: because you are also using Windows, this is maybe of interest for you: Configuring Systems for High Accuracy

AlexLandherr commented 2 years ago

Results of suggested commands on the Pi I was trying to set the time on (not the same as the Pi Zero 2 W with the GPS)

that's normal. most of them will give you nothing, because it is not installed. i thought you will see more from systemd-timedated. was/etc/systemd/timesyncd.conf already modified to use your RPi Zero's time server? what do you get with timedatectl

i realized, that i have also chrony installed (in client configuration) on my other RPi's i have. (just installed the package and added my local time server and one external stratum one server from the internet) so i can't remember what the above commands will show you normally.

By the looks of chronyc tracking I'm about 17 nanoseconds behind UTC time?

yes... kind of from the point of view of the RPi... at the time you was "looking" at tracking... plus some extra errors on top e.g. (i am no expert):

  • RPi's GPIO Pin 18 and calculation delay,
  • 12ns jitter in the PPS line of the GNSS modules specs,
  • 30..60ns of the GNSS module system (specs)
  • position of the GNSS antenna (skyview, number of satellites in view, reflection, length of the cable)
  • environmantal distortions that a "cheap" GNSS module can not compensate.
  • environmantal distortions that also an expensiv high quality GNSS module can not compensate.

see also

oh, keep in mind, what you keep your time server + GNSS module at a constant temperature. e.g. when i open my window (specially in the winter) i can cleearly see it when i plot the tracking pps graph.

sudo gnuplot ~/RPi-GPS-PPS-StratumOne/gnuplot/chrony-tracking.gnuplot (you have to run it at the desktop)

On the Pi I tried to run ntpdate the /etc/systemd/timesyncd.conf file was modified so that the main server/servers was ntp.se (an anycast address for Sweden's official NTP service) and the fallback was left at the RPi OS default.

And the result of timedatectl on the Pi I want to set the time on: Skärmbild (29)

AlexLandherr commented 2 years ago

How should I make it so that when other Pi:s query the Pi Zero 2 W they will get it and not some error message?

EDIT: Nevermind, I got the sudo ntpdate ip_address_of_server working now. As long as the Pi Zero 2 W that is acting as the server is within 1 microsecond of UTC I'm very happy considering the price of the components.