diff --git a/src/etc.cpp b/src/etc.cpp index 7bbc6e4..c621682 100644 --- a/src/etc.cpp +++ b/src/etc.cpp @@ -380,9 +380,67 @@ void nmDeactivate() setLedsDisable(); } +IPAddress savedWifiDNS; +IPAddress savedEthDNS; + +void checkDNS(bool setup = false) +{ + const char *wifiKey = "WiFi"; + const char *ethKey = "ETH"; + + if (networkCfg.wifiEnable) + { + IPAddress currentWifiDNS = WiFi.dnsIP(); + if (setup) + { + savedWifiDNS = currentWifiDNS; + LOGI("Saved %s DNS - %s", wifiKey, savedWifiDNS.toString().c_str()); + } + else + { + if (currentWifiDNS != savedWifiDNS) + { + WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), savedWifiDNS); + LOGI("Updated %s DNS - %s", wifiKey, savedWifiDNS.toString().c_str()); + } + else + { + //LOGD("No update on %s DNS", wifiKey); + } + } + } + + if (networkCfg.ethEnable) + { + IPAddress currentEthDNS = ETH.dnsIP(); + if (setup) + { + savedEthDNS = currentEthDNS; + LOGI("Saved %s DNS - %s", ethKey, savedEthDNS.toString().c_str()); + } + else + { + if (currentEthDNS != savedEthDNS) + { + ETH.config(ETH.localIP(), ETH.gatewayIP(), ETH.subnetMask(), savedEthDNS); + LOGI("Updated %s DNS - %s", ethKey, savedEthDNS.toString().c_str()); + } + else + { + //LOGD("No update on %s DNS", ethKey); + } + } + } +} + +void reCheckDNS() +{ + checkDNS(); +} + void setupCron() { - // Cron.create(const_cast("0 */1 * * * *"), cronTest, false); + Cron.create(const_cast("0 */1 * * * *"), reCheckDNS, false); Cron.create(const_cast("0 0 */1 * * *"), checkEspUpdateAvail, false); @@ -482,7 +540,7 @@ char *convertTimeToCron(const String &time) static char formattedTime[16]; int hours, minutes; - char timeArray[6]; + char timeArray[6]; time.toCharArray(timeArray, sizeof(timeArray)); sscanf(timeArray, "%d:%d", &hours, &minutes); diff --git a/src/etc.h b/src/etc.h index 1b803a6..89c9343 100644 --- a/src/etc.h +++ b/src/etc.h @@ -27,6 +27,7 @@ void factoryReset(); void setLedsDisable(bool all = false); void cronTest(); void nmActivate(); +void checkDNS(bool setup); void setupCron(); void setClock(void *pvParameters); diff --git a/src/main.cpp b/src/main.cpp index d4fbea6..d52724a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -237,14 +237,16 @@ void NetworkEvent(WiFiEvent_t event) break; case ARDUINO_EVENT_ETH_GOT_IP: // 22: // SYSTEM_EVENT_ETH_GOT_IP: startServers(); - LOGI("%s MAC: %s, IP: %s, Mask: %s, Gw: %s, %dMbps", ethKey, + LOGI("%s MAC: %s, IP: %s, Mask: %s, Gw: %s, DNS: %s, %dMbps", ethKey, ETH.macAddress().c_str(), ETH.localIP().toString().c_str(), ETH.subnetMask().toString().c_str(), ETH.gatewayIP().toString().c_str(), + ETH.dnsIP().toString().c_str(), ETH.linkSpeed()); vars.connectedEther = true; + checkDNS(true); // ConfigSettings.disconnectEthTime = 0; break; case ARDUINO_EVENT_ETH_DISCONNECTED: // 21: //SYSTEM_EVENT_ETH_DISCONNECTED: @@ -268,11 +270,13 @@ void NetworkEvent(WiFiEvent_t event) break; case ARDUINO_EVENT_WIFI_STA_GOT_IP: // SYSTEM_EVENT_STA_GOT_IP: startServers(); - LOGI("%s MAC: %s, IP: %s, Mask: %s, Gw: %s", wifiKey, + LOGI("%s MAC: %s, IP: %s, Mask: %s, Gw: %s, DNS: %s", wifiKey, WiFi.macAddress().c_str(), WiFi.localIP().toString().c_str(), WiFi.subnetMask().toString().c_str(), - WiFi.gatewayIP().toString().c_str()); + WiFi.gatewayIP().toString().c_str(), + WiFi.dnsIP().toString().c_str()); + checkDNS(true); break; case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: // SYSTEM_EVENT_STA_DISCONNECTED: LOGD("%s STA DISCONNECTED", wifiKey); @@ -316,7 +320,7 @@ void startAP(const bool start) WiFi.disconnect(); WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); WiFi.softAP(vars.deviceId); //, WIFIPASS); - + // if DNSServer is started with "*" for domain name, it will reply with // provided IP to all DNS request dnsServer.setErrorReplyCode(DNSReplyCode::NoError); diff --git a/src/web.cpp b/src/web.cpp index 425d47b..1a7ed39 100644 --- a/src/web.cpp +++ b/src/web.cpp @@ -351,13 +351,17 @@ void handleEspUpdateUpload() } } -void handleEvents() { - if (is_authenticated()) { - if (eventsClient) { +void handleEvents() +{ + if (is_authenticated()) + { + if (eventsClient) + { eventsClient.stop(); } eventsClient = serverWeb.client(); - if (eventsClient) { + if (eventsClient) + { eventsClient.println("HTTP/1.1 200 OK"); eventsClient.println("Content-Type: text/event-stream;"); eventsClient.println("Connection: close"); @@ -369,8 +373,10 @@ void handleEvents() { } } -void sendEvent(const char *event, const uint8_t evsz, const String data) { - if (eventsClient) { +void sendEvent(const char *event, const uint8_t evsz, const String data) +{ + if (eventsClient) + { char evnmArr[10 + evsz]; snprintf(evnmArr, sizeof(evnmArr), "event: %s\n", event); eventsClient.print(evnmArr); @@ -1156,6 +1162,14 @@ void handleSerial() { doc["115200"] = checked; } + else if (systemCfg.serialSpeed == 230400) + { + doc["230400"] = checked; + } + else if (systemCfg.serialSpeed == 460800) + { + doc["460800"] = checked; + } else { doc["115200"] = checked; diff --git a/src/websrc/html/PAGE_ZIGBEE.html b/src/websrc/html/PAGE_ZIGBEE.html index 70cbbb2..d843609 100644 --- a/src/websrc/html/PAGE_ZIGBEE.html +++ b/src/websrc/html/PAGE_ZIGBEE.html @@ -61,6 +61,8 @@ + +