Merge remote-tracking branch 'libmaster/master'

This commit is contained in:
lukas 2021-06-17 17:12:50 +02:00
commit e0cbb4acb6
5 changed files with 26 additions and 8 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

@ -2,7 +2,7 @@
#define JsonUtils_h
#include <Arduino.h>
#include <IPAddress.h>
#include <IPUtils.h>
#include <ArduinoJson.h>
class JsonUtils {
@ -20,7 +20,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

@ -68,7 +68,7 @@ class WiFiSettings {
JsonUtils::readIP(root, "dns_ip_2", settings.dnsIP2);
// Swap around the dns servers if 2 is populated but 1 is not
if (settings.dnsIP1 == INADDR_NONE && settings.dnsIP2 != INADDR_NONE) {
if (IPUtils::isNotSet(settings.dnsIP1) && IPUtils::isSet(settings.dnsIP2)) {
settings.dnsIP1 = settings.dnsIP2;
settings.dnsIP2 = INADDR_NONE;
}
@ -76,8 +76,8 @@ class WiFiSettings {
// 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 == INADDR_NONE || settings.gatewayIP == INADDR_NONE || settings.subnetMask == INADDR_NONE)) {
if (settings.staticIPConfig && (IPUtils::isNotSet(settings.localIP) || IPUtils::isNotSet(settings.gatewayIP) ||
IPUtils::isNotSet(settings.subnetMask))) {
settings.staticIPConfig = false;
}
return StateUpdateResult::CHANGED;

View File

@ -63,10 +63,10 @@ void WiFiStatus::wifiStatus(AsyncWebServerRequest* request) {
root["gateway_ip"] = WiFi.gatewayIP().toString();
IPAddress dnsIP1 = WiFi.dnsIP(0);
IPAddress dnsIP2 = WiFi.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

@ -12,7 +12,7 @@
#include <ArduinoJson.h>
#include <AsyncJson.h>
#include <ESPAsyncWebServer.h>
#include <IPAddress.h>
#include <IPUtils.h>
#include <SecurityManager.h>
#define MAX_WIFI_STATUS_SIZE 1024