From c682d950b9628147c5506d5cd57f865f0a34a62f Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 17 Mar 2024 14:19:57 -0400 Subject: [PATCH 1/3] Added support for manually configured Primary and secondary DNS addresses used while in Static IP mode. --- ESPixelStick/src/ConstNames.cpp | 2 ++ ESPixelStick/src/ConstNames.hpp | 2 ++ ESPixelStick/src/network/EthernetDriver.cpp | 16 +++++++-- ESPixelStick/src/network/EthernetDriver.hpp | 2 ++ ESPixelStick/src/network/WiFiDriver.cpp | 22 ++++++++++++- ESPixelStick/src/network/WiFiDriver.hpp | 8 +++-- html/index.html | 36 +++++++++++++++++++++ html/script.js | 6 +++- 8 files changed, 87 insertions(+), 7 deletions(-) diff --git a/ESPixelStick/src/ConstNames.cpp b/ESPixelStick/src/ConstNames.cpp index c12034774..25eff2c61 100644 --- a/ESPixelStick/src/ConstNames.cpp +++ b/ESPixelStick/src/ConstNames.cpp @@ -63,6 +63,8 @@ const CN_PROGMEM char CN_Default [] = "Default"; const CN_PROGMEM char CN_device [] = "device"; const CN_PROGMEM char CN_dhcp [] = "dhcp"; const CN_PROGMEM char CN_Disabled [] = "Disabled"; +const CN_PROGMEM char CN_dnsp [] = "dnsp"; +const CN_PROGMEM char CN_dnss [] = "dnss"; const CN_PROGMEM char CN_DMX [] = "DMX"; const CN_PROGMEM char CN_Dotfseq [] = ".fseq"; const CN_PROGMEM char CN_Dotjson [] = ".json"; diff --git a/ESPixelStick/src/ConstNames.hpp b/ESPixelStick/src/ConstNames.hpp index ba9ddff8c..60c9611dd 100644 --- a/ESPixelStick/src/ConstNames.hpp +++ b/ESPixelStick/src/ConstNames.hpp @@ -72,6 +72,8 @@ extern const CN_PROGMEM char CN_device []; extern const CN_PROGMEM char CN_dhcp []; extern const CN_PROGMEM char CN_Default []; extern const CN_PROGMEM char CN_Disabled []; +extern const CN_PROGMEM char CN_dnsp []; +extern const CN_PROGMEM char CN_dnss []; extern const CN_PROGMEM char CN_Dotfseq []; extern const CN_PROGMEM char CN_Dotjson []; extern const CN_PROGMEM char CN_Dotpl []; diff --git a/ESPixelStick/src/network/EthernetDriver.cpp b/ESPixelStick/src/network/EthernetDriver.cpp index cb6b18d51..cbdbdd035 100644 --- a/ESPixelStick/src/network/EthernetDriver.cpp +++ b/ESPixelStick/src/network/EthernetDriver.cpp @@ -131,6 +131,8 @@ void c_EthernetDriver::GetConfig (JsonObject& json) json[CN_ip] = ip.toString (); json[CN_netmask] = netmask.toString (); json[CN_gateway] = gateway.toString (); + json[CN_dnsp] = primaryDns.toString (); + json[CN_dnss] = secondaryDns.toString (); json[CN_dhcp] = UseDhcp; json[CN_type] = phy_type; @@ -321,10 +323,14 @@ bool c_EthernetDriver::SetConfig (JsonObject & json) String sIP = ip.toString (); String sGateway = gateway.toString (); String sNetmask = netmask.toString (); + String sDnsp = primaryDns.toString (); + String sDnss = secondaryDns.toString (); ConfigChanged |= setFromJSON (sIP, json, CN_ip); ConfigChanged |= setFromJSON (sNetmask, json, CN_netmask); ConfigChanged |= setFromJSON (sGateway, json, CN_gateway); + ConfigChanged |= setFromJSON (sDnsp, json, CN_dnsp); + ConfigChanged |= setFromJSON (sDnss, json, CN_dnss); ConfigChanged |= setFromJSON (UseDhcp, json, CN_dhcp); ConfigChanged |= setFromJSON (phy_addr, json, CN_addr); @@ -339,7 +345,9 @@ bool c_EthernetDriver::SetConfig (JsonObject & json) ip.fromString (sIP); gateway.fromString (sGateway); netmask.fromString (sNetmask); - + primaryDns.fromString (sDnsp); + secondaryDns.fromString (sDnss); + // DEBUG_V (String (" sip: ") + ip.toString ()); // DEBUG_V (String ("sgateway: ") + gateway.toString ()); // DEBUG_V (String ("snetmask: ") + netmask.toString ()); @@ -397,10 +405,14 @@ void c_EthernetDriver::SetUpIp () // DEBUG_V ("netmask: " + netmask.toString ()); // DEBUG_V ("gateway: " + gateway.toString ()); + if(primaryDns == INADDR_NONE) + { + primaryDns = gateway; + } // We didn't use DNS, so just set it to our configured gateway // https://github.com/espressif/arduino-esp32/issues/5733 - add delay delay(100); - ETH.config (ip, gateway, netmask, gateway); + ETH.config (ip, gateway, netmask, primaryDns, secondaryDns); logcon (F ("Connecting to Ethernet with Static IP")); diff --git a/ESPixelStick/src/network/EthernetDriver.hpp b/ESPixelStick/src/network/EthernetDriver.hpp index dd6e35264..861187c91 100644 --- a/ESPixelStick/src/network/EthernetDriver.hpp +++ b/ESPixelStick/src/network/EthernetDriver.hpp @@ -88,6 +88,8 @@ class c_EthernetDriver IPAddress ip = INADDR_NONE; IPAddress netmask = INADDR_NONE; IPAddress gateway = INADDR_NONE; + IPAddress primaryDns = INADDR_NONE; + IPAddress secondaryDns = INADDR_NONE; bool UseDhcp = true; uint32_t phy_addr = DEFAULT_ETH_ADDR; gpio_num_t power_pin = DEFAULT_ETH_POWER_PIN; diff --git a/ESPixelStick/src/network/WiFiDriver.cpp b/ESPixelStick/src/network/WiFiDriver.cpp index 231c875b5..da2ebbbba 100644 --- a/ESPixelStick/src/network/WiFiDriver.cpp +++ b/ESPixelStick/src/network/WiFiDriver.cpp @@ -327,10 +327,16 @@ void c_WiFiDriver::GetConfig (JsonObject& json) json[CN_netmask] = Temp.toString (); Temp = gateway; json[CN_gateway] = Temp.toString (); + Temp = primaryDns; + json[CN_dnsp] = Temp.toString (); + Temp = secondaryDns; + json[CN_dnss] = Temp.toString (); #else json[CN_ip] = ip.toString (); json[CN_netmask] = netmask.toString (); json[CN_gateway] = gateway.toString (); + json[CN_dnsp] = primaryDns.toString (); + json[CN_dnss] = secondaryDns.toString (); #endif // !def ARDUINO_ARCH_ESP8266 json[CN_StayInApMode] = StayInApMode; @@ -481,11 +487,16 @@ bool c_WiFiDriver::SetConfig (JsonObject & json) String sIp = ip.toString (); String sGateway = gateway.toString (); String sNetmask = netmask.toString (); + String sdnsp = primaryDns.toString (); + String sdnss = secondaryDns.toString (); + ConfigChanged |= setFromJSON (ssid, json, CN_ssid); ConfigChanged |= setFromJSON (passphrase, json, CN_passphrase); ConfigChanged |= setFromJSON (sIp, json, CN_ip); ConfigChanged |= setFromJSON (sNetmask, json, CN_netmask); ConfigChanged |= setFromJSON (sGateway, json, CN_gateway); + ConfigChanged |= setFromJSON (sdnsp, json, CN_dnsp); + ConfigChanged |= setFromJSON (sdnss, json, CN_dnss); ConfigChanged |= setFromJSON (UseDhcp, json, CN_dhcp); ConfigChanged |= setFromJSON (ap_ssid, json, CN_ap_ssid); ConfigChanged |= setFromJSON (ap_passphrase, json, CN_ap_passphrase); @@ -507,6 +518,8 @@ bool c_WiFiDriver::SetConfig (JsonObject & json) ip.fromString (sIp); gateway.fromString (sGateway); netmask.fromString (sNetmask); + primaryDns.fromString (sdnsp); + secondaryDns.fromString (sdnss); if((passphrase.length() < 8) && (passphrase.length() > 0)) { @@ -591,8 +604,15 @@ void c_WiFiDriver::SetUpIp () // correct IP is already set break; } + + // use gateway if primary DNS is not defined + if(primaryDns == INADDR_NONE) + { + primaryDns = gateway; + } + // We didn't use DNS, so just set it to our configured gateway - WiFi.config (ip, gateway, netmask, gateway); + WiFi.config (ip, gateway, netmask, primaryDns, secondaryDns); logcon (F ("Using Static IP")); diff --git a/ESPixelStick/src/network/WiFiDriver.hpp b/ESPixelStick/src/network/WiFiDriver.hpp index 31bab0825..1628fc9ba 100644 --- a/ESPixelStick/src/network/WiFiDriver.hpp +++ b/ESPixelStick/src/network/WiFiDriver.hpp @@ -105,9 +105,11 @@ class c_WiFiDriver String passphrase; String ap_ssid; String ap_passphrase; - IPAddress ip = IPAddress ((uint32_t)0); - IPAddress netmask = IPAddress ((uint32_t)0); - IPAddress gateway = IPAddress ((uint32_t)0); + IPAddress ip = INADDR_NONE; + IPAddress netmask = INADDR_NONE; + IPAddress gateway = INADDR_NONE; + IPAddress primaryDns = INADDR_NONE; + IPAddress secondaryDns = INADDR_NONE; bool UseDhcp = true; uint8_t ap_channelNumber = 1; bool ap_fallbackIsEnabled = true; diff --git a/html/index.html b/html/index.html index ff023c63e..31dc8a8f5 100644 --- a/html/index.html +++ b/html/index.html @@ -471,6 +471,24 @@ value="0.0.0.0" title="Static Gateway"> +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+