From 9cb39288de8b3cf601265d9e3cc349e91ce4db70 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Wed, 28 Mar 2012 06:48:49 +1300 Subject: NTP bug - don't flood NTP requests every loop()! Instead, once every 60 secs till we get a response. Signed-off-by: Mike Beattie --- HouseControl.ino | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/HouseControl.ino b/HouseControl.ino index 2c6f70a..2dbf282 100644 --- a/HouseControl.ino +++ b/HouseControl.ino @@ -120,7 +120,8 @@ struct st_door garageDoor1; struct st_door garageDoor2; EthernetUDP NTPSocket; -time_t lastNTPtime = 0; +time_t lastNTPtime = 0; +time_t lastNTPquery = 0; //Server telnetServer(23); WebServer httpServer("", 80); @@ -174,6 +175,9 @@ bool str_to_mac(byte *buf, byte *mac) { // send an NTP request to the time server at the given address void sendNTPpacket() { + // update query time... + lastNTPquery = time; + // Packet buffer byte pb[48]; // set all bytes in the buffer to 0 @@ -512,7 +516,8 @@ void loop() { time = now(); - if ((time - lastNTPtime) >= 600) + // query time every 10 minutes, but only once a minute till we get a response + if ((((time - lastNTPtime) >= 600) || lastNTPtime == 0) && ((time - lastNTPquery) >= 60)) sendNTPpacket(); if (NTPSocket.parsePacket() >= 46) -- cgit v1.2.3