@@ -22,22 +22,20 @@ void APSettingsService::reconfigureAP() {
22
22
}
23
23
24
24
void APSettingsService::loop () {
25
- // if we have an ETH connection, quit
26
- if (emsesp::EMSESP::system_.ethernet_connected ()) {
27
- return ;
28
- }
29
25
unsigned long currentMillis = uuid::get_uptime ();
30
26
unsigned long manageElapsed = (uint32_t )(currentMillis - _lastManaged);
31
27
if (manageElapsed >= MANAGE_NETWORK_DELAY) {
32
28
_lastManaged = currentMillis;
33
29
manageAP ();
34
30
}
31
+
35
32
handleDNS ();
36
33
}
37
34
38
35
void APSettingsService::manageAP () {
39
- WiFiMode_t currentWiFiMode = WiFi.getMode ();
40
- if (_state.provisionMode == AP_MODE_ALWAYS || (_state.provisionMode == AP_MODE_DISCONNECTED && WiFi.status () != WL_CONNECTED)) {
36
+ WiFiMode_t currentWiFiMode = WiFi.getMode ();
37
+ bool network_connected = (emsesp::EMSESP::system_.ethernet_connected () || (WiFi.status () == WL_CONNECTED));
38
+ if (_state.provisionMode == AP_MODE_ALWAYS || (_state.provisionMode == AP_MODE_DISCONNECTED && !network_connected)) {
41
39
if (_reconfigureAp || currentWiFiMode == WIFI_OFF || currentWiFiMode == WIFI_STA) {
42
40
startAP ();
43
41
}
@@ -48,26 +46,25 @@ void APSettingsService::manageAP() {
48
46
}
49
47
50
48
void APSettingsService::startAP () {
51
- // Serial.println (F("Starting software access point "));
49
+ emsesp::EMSESP::logger (). info (F (" Starting software Access Point " ));
52
50
WiFi.softAPConfig (_state.localIP , _state.gatewayIP , _state.subnetMask );
53
51
WiFi.softAP (_state.ssid .c_str (), _state.password .c_str ());
54
52
if (!_dnsServer) {
55
53
IPAddress apIp = WiFi.softAPIP ();
56
- // Serial.print(F("Starting captive portal on "));
57
- // Serial.println(apIp);
54
+ emsesp::EMSESP::logger ().info (F (" Starting captive portal on %s" ), apIp.toString ().c_str ());
58
55
_dnsServer = new DNSServer;
59
56
_dnsServer->start (DNS_PORT, " *" , apIp);
60
57
}
61
58
}
62
59
63
60
void APSettingsService::stopAP () {
64
61
if (_dnsServer) {
65
- // Serial.println (F("Stopping captive portal"));
62
+ emsesp::EMSESP::logger (). info (F (" Stopping captive portal" ));
66
63
_dnsServer->stop ();
67
64
delete _dnsServer;
68
65
_dnsServer = nullptr ;
69
66
}
70
- // Serial.println (F("Stopping software access point "));
67
+ emsesp::EMSESP::logger (). info (F (" Stopping software Access Point " ));
71
68
WiFi.softAPdisconnect (true );
72
69
}
73
70
0 commit comments