mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
merge ipaddress fix from esp8266-react
This commit is contained in:
18
lib/framework/IPUtils.h
Normal file
18
lib/framework/IPUtils.h
Normal 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
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
|
#include <IPUtils.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
class JsonUtils {
|
class JsonUtils {
|
||||||
@@ -20,7 +21,7 @@ class JsonUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void writeIP(JsonObject & root, const String & key, const IPAddress & ip) {
|
static void writeIP(JsonObject & root, const String & key, const IPAddress & ip) {
|
||||||
if (ip != INADDR_NONE) {
|
if (IPUtils::isSet(ip)) {
|
||||||
root[key] = ip.toString();
|
root[key] = ip.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class NetworkSettings {
|
|||||||
JsonUtils::readIP(root, "dns_ip_2", settings.dnsIP2);
|
JsonUtils::readIP(root, "dns_ip_2", settings.dnsIP2);
|
||||||
|
|
||||||
// Swap around the dns servers if 2 is populated but 1 is not
|
// 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.dnsIP1 = settings.dnsIP2;
|
||||||
settings.dnsIP2 = INADDR_NONE;
|
settings.dnsIP2 = INADDR_NONE;
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ class NetworkSettings {
|
|||||||
// Turning off static ip config if we don't meet the minimum requirements
|
// 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
|
// of ipAddress, gateway and subnet. This may change to static ip only
|
||||||
// as sensible defaults can be assumed for gateway and subnet
|
// 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;
|
settings.staticIPConfig = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ void NetworkStatus::networkStatus(AsyncWebServerRequest * request) {
|
|||||||
root["gateway_ip"] = ETH.gatewayIP().toString();
|
root["gateway_ip"] = ETH.gatewayIP().toString();
|
||||||
IPAddress dnsIP1 = ETH.dnsIP(0);
|
IPAddress dnsIP1 = ETH.dnsIP(0);
|
||||||
IPAddress dnsIP2 = ETH.dnsIP(1);
|
IPAddress dnsIP2 = ETH.dnsIP(1);
|
||||||
if (dnsIP1 != INADDR_NONE) {
|
if (IPUtils::isSet(dnsIP1)) {
|
||||||
root["dns_ip_1"] = dnsIP1.toString();
|
root["dns_ip_1"] = dnsIP1.toString();
|
||||||
}
|
}
|
||||||
if (dnsIP2 != INADDR_NONE) {
|
if (IPUtils::isSet(dnsIP2)) {
|
||||||
root["dns_ip_2"] = dnsIP2.toString();
|
root["dns_ip_2"] = dnsIP2.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
|
#include <IPUtils.h>
|
||||||
#include <SecurityManager.h>
|
#include <SecurityManager.h>
|
||||||
|
|
||||||
#define MAX_NETWORK_STATUS_SIZE 1024
|
#define MAX_NETWORK_STATUS_SIZE 1024
|
||||||
|
|||||||
Reference in New Issue
Block a user