mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
fallback to AP when Ethernet is dropped
This commit is contained in:
@@ -22,22 +22,20 @@ void APSettingsService::reconfigureAP() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void APSettingsService::loop() {
|
void APSettingsService::loop() {
|
||||||
// if we have an ETH connection, quit
|
|
||||||
if (emsesp::EMSESP::system_.ethernet_connected()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
unsigned long currentMillis = uuid::get_uptime();
|
unsigned long currentMillis = uuid::get_uptime();
|
||||||
unsigned long manageElapsed = (uint32_t)(currentMillis - _lastManaged);
|
unsigned long manageElapsed = (uint32_t)(currentMillis - _lastManaged);
|
||||||
if (manageElapsed >= MANAGE_NETWORK_DELAY) {
|
if (manageElapsed >= MANAGE_NETWORK_DELAY) {
|
||||||
_lastManaged = currentMillis;
|
_lastManaged = currentMillis;
|
||||||
manageAP();
|
manageAP();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDNS();
|
handleDNS();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APSettingsService::manageAP() {
|
void APSettingsService::manageAP() {
|
||||||
WiFiMode_t currentWiFiMode = WiFi.getMode();
|
WiFiMode_t currentWiFiMode = WiFi.getMode();
|
||||||
if (_state.provisionMode == AP_MODE_ALWAYS || (_state.provisionMode == AP_MODE_DISCONNECTED && WiFi.status() != WL_CONNECTED)) {
|
bool network_connected = (emsesp::EMSESP::system_.ethernet_connected() || (WiFi.status() == WL_CONNECTED));
|
||||||
|
if (_state.provisionMode == AP_MODE_ALWAYS || (_state.provisionMode == AP_MODE_DISCONNECTED && !network_connected)) {
|
||||||
if (_reconfigureAp || currentWiFiMode == WIFI_OFF || currentWiFiMode == WIFI_STA) {
|
if (_reconfigureAp || currentWiFiMode == WIFI_OFF || currentWiFiMode == WIFI_STA) {
|
||||||
startAP();
|
startAP();
|
||||||
}
|
}
|
||||||
@@ -48,13 +46,12 @@ void APSettingsService::manageAP() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void APSettingsService::startAP() {
|
void APSettingsService::startAP() {
|
||||||
// Serial.println(F("Starting software access point"));
|
emsesp::EMSESP::logger().info(F("Starting software Access Point"));
|
||||||
WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask);
|
WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask);
|
||||||
WiFi.softAP(_state.ssid.c_str(), _state.password.c_str());
|
WiFi.softAP(_state.ssid.c_str(), _state.password.c_str());
|
||||||
if (!_dnsServer) {
|
if (!_dnsServer) {
|
||||||
IPAddress apIp = WiFi.softAPIP();
|
IPAddress apIp = WiFi.softAPIP();
|
||||||
// Serial.print(F("Starting captive portal on "));
|
emsesp::EMSESP::logger().info(F("Starting captive portal on %s"), apIp.toString().c_str());
|
||||||
// Serial.println(apIp);
|
|
||||||
_dnsServer = new DNSServer;
|
_dnsServer = new DNSServer;
|
||||||
_dnsServer->start(DNS_PORT, "*", apIp);
|
_dnsServer->start(DNS_PORT, "*", apIp);
|
||||||
}
|
}
|
||||||
@@ -62,12 +59,12 @@ void APSettingsService::startAP() {
|
|||||||
|
|
||||||
void APSettingsService::stopAP() {
|
void APSettingsService::stopAP() {
|
||||||
if (_dnsServer) {
|
if (_dnsServer) {
|
||||||
// Serial.println(F("Stopping captive portal"));
|
emsesp::EMSESP::logger().info(F("Stopping captive portal"));
|
||||||
_dnsServer->stop();
|
_dnsServer->stop();
|
||||||
delete _dnsServer;
|
delete _dnsServer;
|
||||||
_dnsServer = nullptr;
|
_dnsServer = nullptr;
|
||||||
}
|
}
|
||||||
// Serial.println(F("Stopping software access point"));
|
emsesp::EMSESP::logger().info(F("Stopping software Access Point"));
|
||||||
WiFi.softAPdisconnect(true);
|
WiFi.softAPdisconnect(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user