File tree Expand file tree Collapse file tree 5 files changed +26
-10
lines changed
Expand file tree Collapse file tree 5 files changed +26
-10
lines changed Original file line number Diff line number Diff line change 1+ #ifndef IPUtils_h
2+ #define IPUtils_h
3+
4+ #include < IPAddress.h>
5+
6+ const IPAddress IP_NOT_SET = IPAddress(INADDR_NONE);
7+
8+ class IPUtils {
9+ public:
10+ static bool isSet (const IPAddress& ip) {
11+ return ip != IP_NOT_SET;
12+ }
13+ static bool isNotSet (const IPAddress& ip) {
14+ return ip == IP_NOT_SET;
15+ }
16+ };
17+
18+ #endif // end IPUtils_h
Original file line number Diff line number Diff line change 22#define JsonUtils_h
33
44#include < Arduino.h>
5- #include < IPAddress .h>
5+ #include < IPUtils .h>
66#include < ArduinoJson.h>
77
88class JsonUtils {
@@ -20,7 +20,7 @@ class JsonUtils {
2020 }
2121 }
2222 static void writeIP (JsonObject& root, const String& key, const IPAddress& ip) {
23- if (ip != INADDR_NONE ) {
23+ if (IPUtils::isSet (ip) ) {
2424 root[key] = ip.toString ();
2525 }
2626 }
Original file line number Diff line number Diff line change 2424
2525#define WIFI_RECONNECTION_DELAY 1000 * 30
2626
27- const IPAddress IP_NOT_SET = IPAddress(INADDR_NONE);
28-
2927class WiFiSettings {
3028 public:
3129 // core wifi configuration
@@ -70,16 +68,16 @@ class WiFiSettings {
7068 JsonUtils::readIP (root, " dns_ip_2" , settings.dnsIP2 );
7169
7270 // Swap around the dns servers if 2 is populated but 1 is not
73- if (settings.dnsIP1 == IP_NOT_SET && settings.dnsIP2 != IP_NOT_SET ) {
71+ if (IPUtils::isNotSet ( settings.dnsIP1 ) && IPUtils::isSet ( settings.dnsIP2 ) ) {
7472 settings.dnsIP1 = settings.dnsIP2 ;
7573 settings.dnsIP2 = INADDR_NONE;
7674 }
7775
7876 // Turning off static ip config if we don't meet the minimum requirements
7977 // of ipAddress, gateway and subnet. This may change to static ip only
8078 // as sensible defaults can be assumed for gateway and subnet
81- if (settings.staticIPConfig &&
82- (settings. localIP == IP_NOT_SET || settings. gatewayIP == IP_NOT_SET || settings.subnetMask == IP_NOT_SET )) {
79+ if (settings.staticIPConfig && ( IPUtils::isNotSet (settings. localIP ) || IPUtils::isNotSet (settings. gatewayIP ) ||
80+ IPUtils::isNotSet ( settings.subnetMask ) )) {
8381 settings.staticIPConfig = false ;
8482 }
8583 return StateUpdateResult::CHANGED;
Original file line number Diff line number Diff line change @@ -63,10 +63,10 @@ void WiFiStatus::wifiStatus(AsyncWebServerRequest* request) {
6363 root[" gateway_ip" ] = WiFi.gatewayIP ().toString ();
6464 IPAddress dnsIP1 = WiFi.dnsIP (0 );
6565 IPAddress dnsIP2 = WiFi.dnsIP (1 );
66- if (dnsIP1 != INADDR_NONE ) {
66+ if (IPUtils::isSet ( dnsIP1) ) {
6767 root[" dns_ip_1" ] = dnsIP1.toString ();
6868 }
69- if (dnsIP2 != INADDR_NONE ) {
69+ if (IPUtils::isSet ( dnsIP2) ) {
7070 root[" dns_ip_2" ] = dnsIP2.toString ();
7171 }
7272 }
Original file line number Diff line number Diff line change 1212#include < ArduinoJson.h>
1313#include < AsyncJson.h>
1414#include < ESPAsyncWebServer.h>
15- #include < IPAddress .h>
15+ #include < IPUtils .h>
1616#include < SecurityManager.h>
1717
1818#define MAX_WIFI_STATUS_SIZE 1024
You can’t perform that action at this time.
0 commit comments