File tree 5 files changed +26
-10
lines changed 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 2
2
#define JsonUtils_h
3
3
4
4
#include < Arduino.h>
5
- #include < IPAddress .h>
5
+ #include < IPUtils .h>
6
6
#include < ArduinoJson.h>
7
7
8
8
class JsonUtils {
@@ -20,7 +20,7 @@ class JsonUtils {
20
20
}
21
21
}
22
22
static void writeIP (JsonObject& root, const String& key, const IPAddress& ip) {
23
- if (ip != INADDR_NONE ) {
23
+ if (IPUtils::isSet (ip) ) {
24
24
root[key] = ip.toString ();
25
25
}
26
26
}
Original file line number Diff line number Diff line change 24
24
25
25
#define WIFI_RECONNECTION_DELAY 1000 * 30
26
26
27
- const IPAddress IP_NOT_SET = IPAddress(INADDR_NONE);
28
-
29
27
class WiFiSettings {
30
28
public:
31
29
// core wifi configuration
@@ -70,16 +68,16 @@ class WiFiSettings {
70
68
JsonUtils::readIP (root, " dns_ip_2" , settings.dnsIP2 );
71
69
72
70
// 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 ) ) {
74
72
settings.dnsIP1 = settings.dnsIP2 ;
75
73
settings.dnsIP2 = INADDR_NONE;
76
74
}
77
75
78
76
// Turning off static ip config if we don't meet the minimum requirements
79
77
// of ipAddress, gateway and subnet. This may change to static ip only
80
78
// 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 ) )) {
83
81
settings.staticIPConfig = false ;
84
82
}
85
83
return StateUpdateResult::CHANGED;
Original file line number Diff line number Diff line change @@ -63,10 +63,10 @@ void WiFiStatus::wifiStatus(AsyncWebServerRequest* request) {
63
63
root[" gateway_ip" ] = WiFi.gatewayIP ().toString ();
64
64
IPAddress dnsIP1 = WiFi.dnsIP (0 );
65
65
IPAddress dnsIP2 = WiFi.dnsIP (1 );
66
- if (dnsIP1 != INADDR_NONE ) {
66
+ if (IPUtils::isSet ( dnsIP1) ) {
67
67
root[" dns_ip_1" ] = dnsIP1.toString ();
68
68
}
69
- if (dnsIP2 != INADDR_NONE ) {
69
+ if (IPUtils::isSet ( dnsIP2) ) {
70
70
root[" dns_ip_2" ] = dnsIP2.toString ();
71
71
}
72
72
}
Original file line number Diff line number Diff line change 12
12
#include < ArduinoJson.h>
13
13
#include < AsyncJson.h>
14
14
#include < ESPAsyncWebServer.h>
15
- #include < IPAddress .h>
15
+ #include < IPUtils .h>
16
16
#include < SecurityManager.h>
17
17
18
18
#define MAX_WIFI_STATUS_SIZE 1024
You can’t perform that action at this time.
0 commit comments