Browse code

fixed bug in NTP clock synchronization

Gandolf authored on 12/02/2019 02:42:25
Showing 1 changed files
... ...
@@ -2,14 +2,14 @@
2 2
  Background Radiation Monitor - Web Server
3 3
  
4 4
  A simple web server that makes available to clients over the Internet
5
- readings from a MightyOhm Geiger counter. The MightyOhm is connected to
6
- an Arduino Uno with attached Ethernet shield.  This software module
5
+ readings from a MightyOhm Geiger counter. The MightyOhm is connected
6
+ to an Arduino Uno with attached Ethernet shield.  This software module
7 7
  runs on the Arduino Uno an embedded HTTP server by which Internet
8 8
  applications can query the MightyOhm for Geiger counter readings.
9 9
  Also, this software runs a Network Time Protocol (NTP) client, that
10 10
  periodically synchronizes the local system clock to network time.
11
- Included is a simple command line interface that may be used to change the
12
- network interface IP address, NTP server address, or configure a
11
+ Included is a simple command line interface that may be used to change
12
+ the network interface IP address, NTP server address, or configure a
13 13
  verbose output mode.
14 14
  
15 15
  Copyright 2018 Jeff Owrey
... ...
@@ -75,6 +75,13 @@
75 75
          NTP address set to "pool.ntp.org" per ntp.org request to use
76 76
          (in order to facilitate load balancing) the fully qualified
77 77
          domain name instead of individual server IP addresses.
78
+   * v18 released 01 Nov 2019 by J L Owrey
79
+       - fixed a bug in NTP time synchronization whereby the network time
80
+         synchronization would only occur during boot up.  Thereafter NTP 
81
+         time synchronization would fail to happen, resulting in a large 
82
+         amount of clock drift.
83
+
84
+12345678901234567890123456789012345678901234567890123456789012345678901234567890         
78 85
 */
79 86
 
80 87
 /***  PREPROCESSOR DEFINES  ***/
... ...
@@ -85,8 +92,8 @@
85 92
  Define the header and version number displayed at startup
86 93
  and also by the 'view settings' command.
87 94
 */
88
-#define STARTUP_HEADER "\n\rRadmon v1.7 (c) 2019\n"
89
-#define RADMON_VERSION "v1.7"
95
+#define STARTUP_HEADER "\n\rRadmon v1.8 (c) 2019"
96
+#define RADMON_VERSION "v1.8"
90 97
 /*
91 98
  The following define sets the MAC address of the device.  This
92 99
  address is a permanent attribute of the device's Ethernet interface,
... ...
@@ -95,7 +102,7 @@
95 102
  specific instance of the Ethernet shield.  This MAC address should
96 103
  be shown on a label affixed to the device housing.
97 104
 */
98
-#define ETHERNET_MAC_ADDRESS 0xNN, 0xNN, 0xNN, 0xNN, 0xNN, 0xNN
105
+#define ETHERNET_MAC_ADDRESS 0x90, 0xA2, 0xDA, 0x0D, 0x84, 0xF6
99 106
 /*
100 107
  The following defines an APIPA default address in the event that
101 108
  DHCP mode is ON and a DHCP address cannot be obtained.
... ...
@@ -106,7 +113,7 @@
106 113
  out over the device's USB port.  This heartbeat consists of a serial
107 114
  data string containing the current radiation reading and GM time.
108 115
 */
109
-#define SERIAL_UPDATE_INTERVAL 5000  //milli-seconds
116
+#define SERIAL_UPDATE_INTERVAL 1000  //milli-seconds
110 117
 /*
111 118
  The following define sets the port number the HTTP service will use to
112 119
  listen for requests from Internet clients.  Normally HTTP requests use
... ...
@@ -116,18 +123,19 @@
116 123
 /*
117 124
  The following defines are for configuring a local NTP client
118 125
  for synchronizing the local system clock to network time.
119
- Note that the default setting is the IP address of the following
120
- time server:
121
-              time-c-b.nist.gov
126
+ Note that the ntp server address should be sent to the local
127
+ server pool of the country where the radmon will be used.  See
128
+ the web site 'ntp.org' for details. Users in the USA should set
129
+ the ntp server to 'us.pool.ntp.org'.
122 130
 */
123 131
 #define DEFAULT_NTP_SERVER_ADDR "pool.ntp.org"
124 132
 #define NTP_PORT 8888
125
-#define NTP_PACKET_SIZE 48 // NTP time stamp is in the first 48 bytes of the message
133
+#define NTP_PACKET_SIZE 48 // NTP time in the first 48 bytes of the message
126 134
 /*
127 135
  The following defines how often the system clock gets synchronized
128 136
  to network time.
129 137
 */
130
-#define NET_SYNCH_INTERVAL 21600 //number in seconds - 4 times a day
138
+#define NTP_SYNCH_INTERVAL 43200 // number in seconds - 2 times a day
131 139
 /*
132 140
  Number of retries if first time server request fails.
133 141
 */
... ...
@@ -190,7 +198,7 @@ SoftwareSerial MightyOhmTxOut(5, 6);
190 <