From 634992a8ddbdda4f0be3a1db440bd6bfa3606aa0 Mon Sep 17 00:00:00 2001
From: francois <francois@clever.amilab.irit.fr>
Date: Tue, 5 Mar 2024 08:45:45 +0100
Subject: [PATCH] add sntp_init and set 3 NTP servers

---
 arduinoIDE_esp32_boards/opt.h |  2 +-
 neosensor/neosensor.ino       | 32 +++++++++++++++++++-------------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/arduinoIDE_esp32_boards/opt.h b/arduinoIDE_esp32_boards/opt.h
index 2e4dbf72..df302dad 100644
--- a/arduinoIDE_esp32_boards/opt.h
+++ b/arduinoIDE_esp32_boards/opt.h
@@ -961,7 +961,7 @@
  * The maximum of NTP servers requested
  */
 #if !defined LWIP_DHCP_MAX_NTP_SERVERS || defined __DOXYGEN__
-#define LWIP_DHCP_MAX_NTP_SERVERS       1
+#define LWIP_DHCP_MAX_NTP_SERVERS       3
 #endif
 
 /**
diff --git a/neosensor/neosensor.ino b/neosensor/neosensor.ino
index cf6939e9..31796e5f 100644
--- a/neosensor/neosensor.ino
+++ b/neosensor/neosensor.ino
@@ -151,12 +151,12 @@
  *  This stems from tha fact that UT3 network's DNS does NOT resolve IRIT IPs
  *  and vice-versa ... hence leading to numerous DNS failures !
  */
-#define NTP_DEFAULT_SERVER1       "pool.ntp.org"      // DNS location aware
-//#define NTP_DEFAULT_SERVER2       "time.nist.gov"     // DNS location aware
-#define NTP_DEFAULT_SERVER2       "141.115.4.2"       // [feb.24] to avoid 'ntp.irit.fr' DNS resolution that fails at UT3
+#define NTP_DEFAULT_SERVER1       "time.nist.gov"     // DNS location aware
+#define NTP_DEFAULT_SERVER2       "pool.ntp.org"      // DNS location aware
+//#define NTP_DEFAULT_SERVER2       "141.115.4.42"      // [feb.24] to avoid 'ntp.irit.fr' DNS resolution that fails at UT3
 //#define NTP_DEFAULT_SERVER2       "ntp.irit.fr"       // UT3-IRIT specific
-//#define NTP_DEFAULT_SERVER3       "0.fr.pool.ntp.org" // DNS location aware
-#define NTP_DEFAULT_SERVER3       "ntp.univ-tlse3.fr" // UT3 specific
+#define NTP_DEFAULT_SERVER3       "europe.pool.ntp.org" // DNS location aware
+//#define NTP_DEFAULT_SERVER3       "ntp.univ-tlse3.fr" // UT3 specific
 
 
 /*
@@ -238,7 +238,7 @@ DynamicJsonDocument sharedRoot(MODULES_SHARED_JSON_SIZE);   // heap allocation
 // --- Functions ---------------------------------------------------------------
 void setupSerial( void ) {
 #ifdef SERIAL_BAUDRATE
-  delay(3000);  // time for USB serial link to come up anew
+  delay(5000);  // time for USB serial link to come up anew
   Serial.begin(SERIAL_BAUDRATE); // Start serial for output
 
   // Arduino libs v2.4.1, to enable printf and debug messages output
@@ -559,6 +559,10 @@ bool setupNTP( void ) {
   // [may.23] esp32/8266 unified API
   configTzTime( MYTZ, NTP_DEFAULT_SERVER1, NTP_DEFAULT_SERVER2, NTP_DEFAULT_SERVER3 );
 
+  // enable and start ...
+  sntp_servermode_dhcp(1);
+  sntp_init();
+
   log_flush();
   // the end ...
   return true;
@@ -826,13 +830,6 @@ void setup() {
   }
 
 
-  /*
-   * WiFiManager to activate the network :)
-   * - we added a 'sensOCampus' check box to enable/disable sensOCampus sandbox mode
-   */
-  setupWiFi( &wifiParameters );
-
-
   /*
    * setupNTP
    * Configure Timezone & DST
@@ -841,6 +838,15 @@ void setup() {
   setupNTP();
 
 
+  /*
+   * WiFiManager to activate the network :)
+   * - we added a 'sensOCampus' check box to enable/disable sensOCampus sandbox mode
+   */
+//  sntp_servermode_dhcp(1); //try to get the ntp server from dhcp
+//  sntp_init();
+  setupWiFi( &wifiParameters );
+
+
   /*
    * Disable led blinking for WiFI setup mode since we're already connected
    */
-- 
GitLab