From 57c636f9725c00c9eca41decb506b72523e4191a Mon Sep 17 00:00:00 2001
From: francois <francois@clever.amilab.irit.fr>
Date: Wed, 11 Jan 2023 09:46:04 +0100
Subject: [PATCH] update

---
 neosensor/libraries/boards/neosensor.h | 21 +++++++++++++++++++-
 neosensor/neosensor.ino                | 27 +++++++++++++-------------
 tests/WiFi_simple/WiFi_simple.ino      |  1 +
 3 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/neosensor/libraries/boards/neosensor.h b/neosensor/libraries/boards/neosensor.h
index 0859ec37..971207e1 100644
--- a/neosensor/libraries/boards/neosensor.h
+++ b/neosensor/libraries/boards/neosensor.h
@@ -12,6 +12,8 @@
  *  - noise detector (8bits DAC MCP4706)
  * ---
  *
+ * F.Thieolt    Jan.23  added option to force 802.11b WiFi protocol
+ *                      in order to overcome the DHCP issue
  * F.Thiebolt   Nov.21  esp32 added serial link definition
  * F.Thiebolt   Jul.21  esp32 added PIR sensor @ GPIO4
  *                      esp32 added switch INCR_SW @ GPIO18
@@ -42,7 +44,24 @@
  */
 #define BOARD_NAME          "neOSensor"
 #define BOARD_REVISION      1.2
-#define BOARD_FWREV         230109          // Firmware revision <year><month><day> in 2 digits each
+#define BOARD_FWREV         230111          // Firmware revision <year><month><day> in 2 digits each
+
+
+
+/* #############################################################################
+ * ###                                                                       ###
+ * ###                      WiFi protocol enforcement                        ###
+ * ###                                                                       ###
+ *      [Jan.23] ESP SDK bug activated by WiFi GWs firmware upgrades
+ *      We offer the opportunity to FORCE a specific WiFi protocol
+ *      [WARNING]: this is reboot PERSISTANT i.e once set you need to manually
+ *      set another value
+ * 
+ * #############################################################################
+ */
+#ifndef FORCE_WIFI_PROTOCOL
+#define FORCE_WIFI_PROTOCOL     1
+#endif // FORCE_WIFI_PROTOCOL
 
 
 /* #############################################################################
diff --git a/neosensor/neosensor.ino b/neosensor/neosensor.ino
index 1e3cfb2a..97821960 100644
--- a/neosensor/neosensor.ino
+++ b/neosensor/neosensor.ino
@@ -9,9 +9,6 @@
  * (c) F.Thiebolt / neOCampus operation - Université Toulouse 3
  * 
  * ---
- * WARNING: [jan.23] WiFiManager 2.0.15-rc1 does not list WiFi networks available !?!?!
- *          ==> UPGRADE WiFiManager for bsp_update branch <==
- * ---
  * NOTES:
  * - you need to 'deploy' our boards definitions (run the deploy.sh script)
  * - select your board from the Arduino IDE boards menu (located end of list)
@@ -646,7 +643,8 @@ void display_wifi_protocol( wifi_interface_t ifx=WIFI_IF_STA ) {
     return;
   }
   
-  log_debug(F("\nWIFI protocols = 0x"));log_debug(cur_protocols,HEX);log_flush();
+  log_debug(F("\n# WIFI protocols = 0x"));log_debug(cur_protocols,HEX);log_flush();
+
   if( cur_protocols & WIFI_PROTOCOL_11N ) {
     log_debug(F("\n\tWiFi_Protocol_11n"));
   }
@@ -670,15 +668,18 @@ void earlySetup( void ) {
    *  we decided to set WiFi physical mode explicitly
    *  BEWARE IT IS PERSISTENT across reboot, flash ...
    */
-#if defined(ESP8266)
-  WiFi.setPhyMode(WIFI_PHY_MODE_11B);   // [jan.23] 11B or 11G SOLVED OUR DHCP issue !!!
-#elif defined(ESP32)
-  // set PERSISTANT mode for station
-  WiFi.mode(WIFI_STA);
-  esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B);  // maybe check ret_code ?
-  //esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G);
-  //esp_wifi_config_11b_rate(WIFI_IF_STA,true); // to suppress 802.11B
-#endif
+#ifdef FORCE_WIFI_PROTOCOL
+  #warning "WiFi protocol enforcement is active !!"
+  #if defined(ESP8266)
+    WiFi.setPhyMode(WIFI_PHY_MODE_11B);   // [jan.23] 11B or 11G SOLVED OUR DHCP issue !!!
+  #elif defined(ESP32)
+    // set PERSISTANT mode for station
+    WiFi.mode(WIFI_STA);
+    esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B);  // maybe check ret_code ?
+    //esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G);
+    //esp_wifi_config_11b_rate(WIFI_IF_STA,true); // to suppress 802.11B
+  #endif
+#endif /* FORCE_WIFI_PROTOCOL */
 
   // WiFi.disconnect(true); // to erase default credentials
   WiFi.setAutoReconnect(false);
diff --git a/tests/WiFi_simple/WiFi_simple.ino b/tests/WiFi_simple/WiFi_simple.ino
index 08012c99..9c2d7daa 100644
--- a/tests/WiFi_simple/WiFi_simple.ino
+++ b/tests/WiFi_simple/WiFi_simple.ino
@@ -18,6 +18,7 @@
 #define SET_WIFI_PROTOCOL   1
 
 /* Global variables */
+#error "Change SSID/passwd !!"
 const char* ssid = "neOCampus";
 const char* password = "XXXXXXX";
 esp_err_t _err;
-- 
GitLab