Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Ntpd / gps need some love part II

    Scheduled Pinned Locked Moved Development
    85 Posts 7 Posters 20.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      charliem
      last edited by

      @robi:

      Can you please attach your modified /etc/inc/rrd.inc?

      How about a patch?

      [2.2-ALPHA][root@pfsense.localdomain]/etc/inc(47): diff -ub rrd.inc rrd_new.inc
      --- rrd.inc     2014-04-29 11:57:57.000000000 -0400
      +++ rrd_new.inc 2014-05-28 12:50:48.000000000 -0400
      @@ -849,7 +849,7 @@
                      /* NTP, set up the ntpd rrd file */
                      if (isset($config['ntpd']['statsgraph'])) {
                              /* set up the ntpd rrd file */
      -                       if (!file_exists("$rrddbpath$ifname$ntpd")) {
      +                       if (!file_exists("$rrddbpath$ntpd")) {
                                      $rrdcreate = "$rrdtool create $rrddbpath$ntpd --step $rrdntpdinterval ";
                                      $rrdcreate .= "DS:offset:GAUGE:$ntpdvalid:0:1000 ";
                                      $rrdcreate .= "DS:sjit:GAUGE:$ntpdvalid:0:1000 ";
      @@ -876,7 +876,7 @@
      
                              /* enter UNKNOWN values in the RRD so it knows we rebooted. */
                              if($g['booting']) {
      -                               mwexec("$rrdtool update $rrddbpath$ntpd N:U");
      +                               mwexec("$rrdtool update $rrddbpath$ntpd N:U:U:U:U:U:U");
                              }
      
                              /* the ntp stats gathering function. */
      
      
      1 Reply Last reply Reply Quote 0
      • R
        robi
        last edited by

        Nice catch 8) Seems to work.

        1 Reply Last reply Reply Quote 0
        • R
          robi
          last edited by

          Here's the entire patch updated and the zipped pack too.
          I'll submit it to GitHub too.

          ntp_gps_full_pack_213c.zip.jpg
          ntpd_love_patch_213c.txt

          1 Reply Last reply Reply Quote 0
          • peteP
            pete
            last edited by

            Thank-you Rob.

            What adjustments do these commands do? Why did you have to change them? There's a mistake for sure for example on the second line, checksum for that is not 23 but 2D. Didn't check all of them, but PMTK301,2 has the correct checksum of 2E, not 20.

            I thought when you tested the checksum in the box below that the correct value would show.  Each of the above commands had a different checksum so I changed them all from default.

            Apologies; just noticed that I had typed an extra character to one side fat fingering it.  Checksum numbers match fine.

            Actually I use default settings (the ones which come when you select the model in the GPS pulldown), they all have already correct checksums precalculated. I'd say you should delete the whole thing, select "Generic" from the pulldown, then select "SureGPS" again, to re-load the defaults and press Save.

            Will do.

            Don't know about the php error you see on that page, have you done any other modifications to your pfSense system? I use this patch on several machines in production, none of them shows this.

            I have not done any modifications.  I did rebuild it from scratch and instead of uploading old configuration I added my stuff manually (rules and all).

            Yeah I do not see it all of the time and thought it might be a Firefox thing.

            Tried it on a couple of other PCs running Firefox and GUI looks fine on them.

            • Pete

            Auto mater
            23.09.1-RELEASE (amd64)
            built on Mon Dec 11 12:24:00 CST 2023
            FreeBSD 14.0-CURRENT
            PFSense + Qotom - Master
            PFSense + Jetway - Backup
            PFSense + Jetway - Backup
            PFSense + Generic - Backup

            1 Reply Last reply Reply Quote 0
            • peteP
              pete
              last edited by

              Saw the error in the GUI come up again after I saved configuration.

              Warning: substr_count(): Empty substring in /etc/inc/system.inc on line 1457 Warning: substr_count(): Empty substring in /etc/inc/system.inc on line 1458

              • Pete

              Auto mater
              23.09.1-RELEASE (amd64)
              built on Mon Dec 11 12:24:00 CST 2023
              FreeBSD 14.0-CURRENT
              PFSense + Qotom - Master
              PFSense + Jetway - Backup
              PFSense + Jetway - Backup
              PFSense + Generic - Backup

              1 Reply Last reply Reply Quote 0
              • R
                robi
                last edited by

                @pete:

                Saw the error in the GUI come up again after I saved configuration.

                Warning: substr_count(): Empty substring in /etc/inc/system.inc on line 1457 Warning: substr_count(): Empty substring in /etc/inc/system.inc on line 1458

                In the NTP configuration, on the NTP page, do you have any NTP servers configured? Also, in General Setup, what do you see in the "NTP time server" textbox?

                1 Reply Last reply Reply Quote 0
                • peteP
                  pete
                  last edited by

                  In the NTP configuration, on the NTP page, do you have any NTP servers configured?

                  no

                  Also, in General Setup, what do you see in the "NTP time server" textbox?

                  pool.ntp.org

                  • Pete

                  Auto mater
                  23.09.1-RELEASE (amd64)
                  built on Mon Dec 11 12:24:00 CST 2023
                  FreeBSD 14.0-CURRENT
                  PFSense + Qotom - Master
                  PFSense + Jetway - Backup
                  PFSense + Jetway - Backup
                  PFSense + Generic - Backup

                  1 Reply Last reply Reply Quote 0
                  • R
                    robi
                    last edited by

                    Thanks, I found the problem for your weirdness and fixed it, attachments below.

                    It's hardcoded in pfSense's system.php that if for some reason no NTP server is present in the config file, pool.ntp.org is used by default. That's why you were seeing it in General Setup, and when you press Save there, pool.ntp.org goes into the config file.
                    However, in NTP settings, you could delete all the NTP servers from the list, but the code expects in return when parsing the config file, to exist at least one. That's what generated your error.
                    I fixed it by adding the same pool.ntp.org server as last resort, if someone deletes all the servers. If you delete all the servers and press Save, the system will automatically add pool.ntp.org, and you will see that in the first row.

                    This results in keeping the original idea in pfSense, that you can't run without at least one NTP server configured. If one still wants to run without any external NTP servers, I guess he/she can use 'localhost' instead or some any dummy IP address or hostname which cannot be resolved. Not too nice though.

                    ntpd_love_patch_213d.txt
                    ntp_gps_full_pack_213d.zip.jpg

                    1 Reply Last reply Reply Quote 0
                    • R
                      robi
                      last edited by

                      It's worth a discussion and a decision with pfSense's main devs, to allow no external NTP servers configured, IF there's a local GPS time source. That would involve a simple logic to check if a GPS time source is already configured, and in both NTP settings and in General Setup allow to have empty list of servers.

                      Moreover, it could even be decided to completely remove the "NTP time server" option from General Setup, since the NTP page already contains advanced configuration for NTP stuff.

                      Also there's still present the "Default" type of GPS receiver in the list, which is copied from the original pfSense 2.1's code. Dagorlad has put this text on the page:

                      Note: Default is the configuration of pfSense 2.1 and earlier (not recommended). Select Generic if your GPS is not listed.)

                      I think we should clear this up, what was the type/model of the GPS receiver used originally when Serial GPS was originally added to pfSense 2.1? I'd add the correct name to reduce confusion and remove the warning text.

                      Jimp? Can you please consider the above?

                      1 Reply Last reply Reply Quote 0
                      • C
                        charliem
                        last edited by

                        @robi:

                        This results in keeping the original idea in pfSense, that you can't run without at least one NTP server configured. If one still wants to run without any external NTP servers, I guess he/she can use 'localhost' instead or some any dummy IP address or hostname which cannot be resolved. Not too nice though.

                        I don't remember seeing this documented as a requirement!  While it's certainly a good recommendation, should it actually be required?

                        1 Reply Last reply Reply Quote 0
                        • peteP
                          pete
                          last edited by

                          Thank-you Robi!

                          I am fine using one external NTP server as a failover.  A NTP internal only switch that worked would also be a nice thing to have.

                          Its been a few years here but started initially with an old "surplus" Trimble GPS (well it was made to be inside of a tank) using this one for many years went to using the SureGPS until the USB power port fell off of the board.  I baked the board last year and was able to get it to work.

                          BTW still got some errors using GGA such that I went back to using ZDA/ZDG.

                          IE: I was seeing bad data using GGA here.

                          ntpq> cv
                          assID=0 status=0012 clk_okay, last_clk_18,
                          device="NMEA GPS Clock", timecode="$GPZDA,123914.000,29,05,2014,,*53",
                          poll=7, noreply=0, badformat=1, baddata=0, fudgetime2=400.000,
                          stratum=0, refid=GPS, flags=5

                          • Pete

                          Auto mater
                          23.09.1-RELEASE (amd64)
                          built on Mon Dec 11 12:24:00 CST 2023
                          FreeBSD 14.0-CURRENT
                          PFSense + Qotom - Master
                          PFSense + Jetway - Backup
                          PFSense + Jetway - Backup
                          PFSense + Generic - Backup

                          1 Reply Last reply Reply Quote 0
                          • C
                            charliem
                            last edited by

                            @robi:

                            Also there's still present the "Default" type of GPS receiver in the list, which is copied from the original pfSense 2.1's code. Dagorlad has put this text on the page:

                            Note: Default is the configuration of pfSense 2.1 and earlier (not recommended). Select Generic if your GPS is not listed.)

                            I think we should clear this up, what was the type/model of the GPS receiver used originally when Serial GPS was originally added to pfSense 2.1? I'd add the correct name to reduce confusion and remove the warning text.

                            Jimp? Can you please consider the above?

                            It's for a GPS with a uBlox chipset; I mentioned it in my first post about GPS bugs here:
                            https://forum.pfsense.org/index.php?topic=67189.msg367460#msg367460  I believe JimP later posted that it was added because it was funded by a customer.  IMHO it should not be there by default

                            Another outstanding 'design' question is whether we should be saving clockstats by default.  They are not used by any installed program or available package AFAIK, and grow without bounds, as there's no cron job to compress/remove/consolidate them.  I think anyone who wants them can certainly turn them on.  I first brought it up here:
                            https://forum.pfsense.org/index.php?topic=67189.msg373669#msg373669 and more here:
                            https://forum.pfsense.org/index.php?topic=67189.msg373841#msg373841

                            1 Reply Last reply Reply Quote 0
                            • stephenw10S
                              stephenw10 Netgate Administrator
                              last edited by

                              @pete:

                              A NTP internal only switch that worked would also be a nice thing to have.

                              +1 on that. If said check box is only on the GPS settings page it's only ever likely to be set by people who understand what they're doing (or think they do  ;)).

                              I thought the clockstats thing had been taken care of? Hmm, clearly I'm not paying enough attention. There was a manual tweak to disable it though right? That didn't make it into the package?

                              Steve

                              1 Reply Last reply Reply Quote 0
                              • R
                                robi
                                last edited by

                                @pete:

                                BTW still got some errors using GGA such that I went back to using ZDA/ZDG.

                                IE: I was seeing bad data using GGA here.

                                It seems to me that badformat error is due to a bug in ntp, the SureGPS sends the sentences with an extra empty line between them, and it seems to me that the nmea driver gets confused by this. It should either be fixed in ntp-nmea driver, or the SureGPS firmware.

                                However, the number of badformats is rather small (got about 26 during a day), and since the PPS signal is the actual source for exact timing, I wouldn't worry about it. The time is kept very exact anyway.

                                1 Reply Last reply Reply Quote 0
                                • peteP
                                  pete
                                  last edited by

                                  Thanks Robi.

                                  Will do.

                                  Thinking a while back did play with the firmware on the SureGPS and had a dialog going with company about the device.

                                  Personally just the integration of using a GPS/PPS into PFSense is a neato thing for me as I had initially just an autonomous running NTP server with a GPS on the network here.  Its my home such that its not a big deal.

                                  • Pete

                                  Auto mater
                                  23.09.1-RELEASE (amd64)
                                  built on Mon Dec 11 12:24:00 CST 2023
                                  FreeBSD 14.0-CURRENT
                                  PFSense + Qotom - Master
                                  PFSense + Jetway - Backup
                                  PFSense + Jetway - Backup
                                  PFSense + Generic - Backup

                                  1 Reply Last reply Reply Quote 0
                                  • R
                                    robi
                                    last edited by

                                    @charliem:

                                    It's for a GPS with a uBlox chipset; I mentioned it in my first post about GPS bugs here:
                                    https://forum.pfsense.org/index.php?topic=67189.msg367460#msg367460  I believe JimP later posted that it was added because it was funded by a customer.  IMHO it should not be there by default

                                    Well, if it works for others too, why remove it? I noticed it's an uBlox, but it's init commands differ from the standard uBlox.

                                    "Default":

                                    $PUBX,40,GSV,0,0,0,059
                                    $PUBX,40,GLL,0,0,0,0
                                    5C
                                    $PUBX,40,ZDA,0,0,0,044
                                    $PUBX,40,VTG,0,0,0,0
                                    5E
                                    $PUBX,40,GSV,0,0,0,059
                                    $PUBX,40,GSA,0,0,0,0
                                    4E
                                    $PUBX,40,GGA,0,0,0,0
                                    $PUBX,40,TXT,0,0,0,0
                                    $PUBX,40,RMC,0,0,0,0*46
                                    $PUBX,41,1,0007,0003,4800,0
                                    $PUBX,40,ZDA,1,1,1,1

                                    "U-Blox":

                                    $PUBX,40,GGA,1,1,1,1,0,05A
                                    $PUBX,40,GLL,1,1,1,1,0,0
                                    5C
                                    $PUBX,40,GSA,0,0,0,0,0,04E
                                    $PUBX,40,GSV,0,0,0,0,0,0
                                    59
                                    $PUBX,40,RMC,1,1,1,1,0,047
                                    $PUBX,40,VTG,0,0,0,0,0,0
                                    5E
                                    $PUBX,40,GRS,0,0,0,0,0,05D
                                    $PUBX,40,GST,0,0,0,0,0,0
                                    5B
                                    $PUBX,40,ZDA,1,1,1,1,0,044
                                    $PUBX,40,GBS,0,0,0,0,0,0
                                    4D
                                    $PUBX,40,DTM,0,0,0,0,0,046
                                    $PUBX,40,GPQ,0,0,0,0,0,0
                                    5D
                                    $PUBX,40,TXT,0,0,0,0,0,043
                                    $PUBX,40,THS,0,0,0,0,0,0
                                    54
                                    $PUBX,41,1,0007,0003,4800,0*13

                                    Which one is the real uBlox then? Maybe we should just rename "Default" to the real name of it, since although it may be an uBlox, it may implement some other commands too. Could be useful for somebody…

                                    @charliem:

                                    Another outstanding 'design' question is whether we should be saving clockstats by default.  They are not used by any installed program or available package AFAIK, and grow without bounds, as there's no cron job to compress/remove/consolidate them.  I think anyone who wants them can certainly turn them on.  I first brought it up here:
                                    https://forum.pfsense.org/index.php?topic=67189.msg373669#msg373669 and more here:
                                    https://forum.pfsense.org/index.php?topic=67189.msg373841#msg373841

                                    clockstats are not saved by default. I just checked the interface, on the NTP page at the bottom (Statistics logging section) there's a ckeckbox named "Enable logging of reference clock statistics (default: disabled).". The php code behind it acts as it should, I just tested. If it's not checked, the /var/log/ntp stays empty. If it's checked, it creates the files.

                                    1 Reply Last reply Reply Quote 0
                                    • C
                                      charliem
                                      last edited by

                                      @robi:

                                      It seems to me that badformat error is due to a bug in ntp, the SureGPS sends the sentences with an extra empty line between them, and it seems to me that the nmea driver gets confused by this. It should either be fixed in ntp-nmea driver, or the SureGPS firmware.

                                      It was fixed by the ntp devs a few days after reporting: http://bugs.ntp.org/show_bug.cgi?id=2140

                                      So, the fix should be in pfSense 2.2 which uses ntpd 4.2.7p440, but I don't think it's in 2.1.3 which uses an earlier version of ntpd (4.2.6 somthing, IIRC).  I do not see the issue on my Sure Electronics boards, but I do see it on another GPS.

                                      But you are right, it's a small problem, unless I find it is related to the spikes I'm observing.  But that's an ntp issue, not for a pfSense forum.

                                      1 Reply Last reply Reply Quote 0
                                      • R
                                        robi
                                        last edited by

                                        I think that was a different issue, having millions of badformats under Windows build. We have only a couple tens, so I tend to think it's either a different thing, or the bug still not fixed properly.
                                        It's ntpd 4.2.7p411 in my 2.1.3 boxes here.

                                        1 Reply Last reply Reply Quote 0
                                        • C
                                          charliem
                                          last edited by

                                          @robi:

                                          Well, if it works for others too, why remove it? I noticed it's an uBlox, but it's init commands differ from the standard uBlox.

                                          $PUBX is proprietary to uBlox.  Hopefully your Garmin or trimble would ignore these …  IMHO it's better to send nothing by default, just open the serial port and look for one of the NMEA sentences.  Only send something if the user has chosen a unit.

                                          "Default":

                                          $PUBX,40,GSV,0,0,0,059
                                          $PUBX,40,GLL,0,0,0,0
                                          5C
                                          $PUBX,40,ZDA,0,0,0,044
                                          $PUBX,40,VTG,0,0,0,0
                                          5E
                                          $PUBX,40,GSV,0,0,0,059
                                          $PUBX,40,GSA,0,0,0,0
                                          4E
                                          $PUBX,40,GGA,0,0,0,0
                                          $PUBX,40,TXT,0,0,0,0
                                          $PUBX,40,RMC,0,0,0,0*46
                                          $PUBX,41,1,0007,0003,4800,0
                                          $PUBX,40,ZDA,1,1,1,1

                                          "U-Blox":

                                          $PUBX,40,GGA,1,1,1,1,0,05A
                                          $PUBX,40,GLL,1,1,1,1,0,0
                                          5C
                                          $PUBX,40,GSA,0,0,0,0,0,04E
                                          $PUBX,40,GSV,0,0,0,0,0,0
                                          59
                                          $PUBX,40,RMC,1,1,1,1,0,047
                                          $PUBX,40,VTG,0,0,0,0,0,0
                                          5E
                                          $PUBX,40,GRS,0,0,0,0,0,05D
                                          $PUBX,40,GST,0,0,0,0,0,0
                                          5B
                                          $PUBX,40,ZDA,1,1,1,1,0,044
                                          $PUBX,40,GBS,0,0,0,0,0,0
                                          4D
                                          $PUBX,40,DTM,0,0,0,0,0,046
                                          $PUBX,40,GPQ,0,0,0,0,0,0
                                          5D
                                          $PUBX,40,TXT,0,0,0,0,0,043
                                          $PUBX,40,THS,0,0,0,0,0,0
                                          54
                                          $PUBX,41,1,0007,0003,4800,0*13

                                          Which one is the real uBlox then? Maybe we should just rename "Default" to the real name of it, since although it may be an uBlox, it may implement some other commands too. Could be useful for somebody…

                                          I documented many common commands in this message:
                                          https://forum.pfsense.org/index.php?topic=67189.msg373885#msg373885

                                          clockstats are not saved by default. I just checked the interface, on the NTP page at the bottom (Statistics logging section) there's a ckeckbox named "Enable logging of reference clock statistics (default: disabled).". The php code behind it acts as it should, I just tested. If it's not checked, the /var/log/ntp stays empty. If it's checked, it creates the files.

                                          Sorry, my bad!  Good job!

                                          [edit: add link to gps commands]

                                          1 Reply Last reply Reply Quote 0
                                          • R
                                            robi
                                            last edited by

                                            OK, thanks, maybe it's a different uBlox model.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.