Skip to content

Commit 2a070ef

Browse files
committed
fallback to AP when Ethernet is dropped
1 parent 0c17e8d commit 2a070ef

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

lib/framework/APSettingsService.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,20 @@ void APSettingsService::reconfigureAP() {
2222
}
2323

2424
void APSettingsService::loop() {
25-
// if we have an ETH connection, quit
26-
if (emsesp::EMSESP::system_.ethernet_connected()) {
27-
return;
28-
}
2925
unsigned long currentMillis = uuid::get_uptime();
3026
unsigned long manageElapsed = (uint32_t)(currentMillis - _lastManaged);
3127
if (manageElapsed >= MANAGE_NETWORK_DELAY) {
3228
_lastManaged = currentMillis;
3329
manageAP();
3430
}
31+
3532
handleDNS();
3633
}
3734

3835
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)) {
4139
if (_reconfigureAp || currentWiFiMode == WIFI_OFF || currentWiFiMode == WIFI_STA) {
4240
startAP();
4341
}
@@ -48,26 +46,25 @@ void APSettingsService::manageAP() {
4846
}
4947

5048
void APSettingsService::startAP() {
51-
// Serial.println(F("Starting software access point"));
49+
emsesp::EMSESP::logger().info(F("Starting software Access Point"));
5250
WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask);
5351
WiFi.softAP(_state.ssid.c_str(), _state.password.c_str());
5452
if (!_dnsServer) {
5553
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());
5855
_dnsServer = new DNSServer;
5956
_dnsServer->start(DNS_PORT, "*", apIp);
6057
}
6158
}
6259

6360
void APSettingsService::stopAP() {
6461
if (_dnsServer) {
65-
// Serial.println(F("Stopping captive portal"));
62+
emsesp::EMSESP::logger().info(F("Stopping captive portal"));
6663
_dnsServer->stop();
6764
delete _dnsServer;
6865
_dnsServer = nullptr;
6966
}
70-
// Serial.println(F("Stopping software access point"));
67+
emsesp::EMSESP::logger().info(F("Stopping software Access Point"));
7168
WiFi.softAPdisconnect(true);
7269
}
7370

0 commit comments

Comments
 (0)