merge ipaddress fix from esp8266-react

This commit is contained in:
proddy
2021-03-08 12:54:44 +01:00
parent 9d5bd11d26
commit 0aefaaef55
5 changed files with 25 additions and 5 deletions

18
lib/framework/IPUtils.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef IPUtils_h
#define IPUtils_h
#include <IPAddress.h>
const IPAddress IP_NOT_SET = IPAddress(INADDR_NONE);
class IPUtils {
public:
static bool isSet(const IPAddress & ip) {
return ip != IP_NOT_SET;
}
static bool isNotSet(const IPAddress & ip) {
return ip == IP_NOT_SET;
}
};
#endif // end IPUtils_h

View File

@@ -3,6 +3,7 @@
#include <Arduino.h>
#include <IPAddress.h>
#include <IPUtils.h>
#include <ArduinoJson.h>
class JsonUtils {
@@ -20,7 +21,7 @@ class JsonUtils {
}
}
static void writeIP(JsonObject & root, const String & key, const IPAddress & ip) {
if (ip != INADDR_NONE) {
if (IPUtils::isSet(ip)) {
root[key] = ip.toString();
}
}

View File

@@ -71,7 +71,7 @@ class NetworkSettings {
JsonUtils::readIP(root, "dns_ip_2", settings.dnsIP2);
// Swap around the dns servers if 2 is populated but 1 is not
if (settings.dnsIP1 == (IPAddress)INADDR_NONE && settings.dnsIP2 != INADDR_NONE) {
if (IPUtils::isNotSet(settings.dnsIP1) && IPUtils::isSet(settings.dnsIP2)) {
settings.dnsIP1 = settings.dnsIP2;
settings.dnsIP2 = INADDR_NONE;
}
@@ -79,7 +79,7 @@ class NetworkSettings {
// Turning off static ip config if we don't meet the minimum requirements
// of ipAddress, gateway and subnet. This may change to static ip only
// as sensible defaults can be assumed for gateway and subnet
if (settings.staticIPConfig && (settings.localIP == (IPAddress)INADDR_NONE || settings.gatewayIP == (IPAddress)INADDR_NONE || settings.subnetMask == (IPAddress)INADDR_NONE)) {
if (settings.staticIPConfig && (IPUtils::isNotSet(settings.localIP) || IPUtils::isNotSet(settings.gatewayIP) || IPUtils::isNotSet(settings.subnetMask))) {
settings.staticIPConfig = false;
}

View File

@@ -46,10 +46,10 @@ void NetworkStatus::networkStatus(AsyncWebServerRequest * request) {
root["gateway_ip"] = ETH.gatewayIP().toString();
IPAddress dnsIP1 = ETH.dnsIP(0);
IPAddress dnsIP2 = ETH.dnsIP(1);
if (dnsIP1 != INADDR_NONE) {
if (IPUtils::isSet(dnsIP1)) {
root["dns_ip_1"] = dnsIP1.toString();
}
if (dnsIP2 != INADDR_NONE) {
if (IPUtils::isSet(dnsIP2)) {
root["dns_ip_2"] = dnsIP2.toString();
}
}

View File

@@ -10,6 +10,7 @@
#include <AsyncJson.h>
#include <ESPAsyncWebServer.h>
#include <IPAddress.h>
#include <IPUtils.h>
#include <SecurityManager.h>
#define MAX_NETWORK_STATUS_SIZE 1024