Add JSON API for AP toggle

This commit is contained in:
Blaz Kristan 2023-12-10 09:59:36 +01:00
parent 27532a4237
commit 6f3b5fc559
2 changed files with 21 additions and 5 deletions

View File

@ -466,6 +466,19 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
} }
} }
JsonObject wifi = root[F("wifi")];
if (!wifi.isNull()) {
bool apMode = getBoolVal(wifi[F("ap")], apActive);
if (!apActive && apMode) WLED::instance().initAP(); // start AP mode immediately
else if (apActive && !apMode) { // stop AP mode immediately
dnsServer.stop();
WiFi.softAPdisconnect(true);
apActive = false;
}
//bool restart = wifi[F("restart")] | false;
//if (restart) forceReconnect = true;
}
stateUpdated(callMode); stateUpdated(callMode);
if (presetToRestore) currentPreset = presetToRestore; if (presetToRestore) currentPreset = presetToRestore;

View File

@ -889,11 +889,14 @@ void WLED::handleConnection()
DEBUG_PRINTLN(F("Not connected AP.")); DEBUG_PRINTLN(F("Not connected AP."));
initAP(); // start AP only within first 5min initAP(); // start AP only within first 5min
} }
} if (apActive && apBehavior == AP_BEHAVIOR_BOOT_NO_CONN_5MIN && now > 300000 && stac == 0) { // disconnect AP after 5min } if (apActive && apBehavior == AP_BEHAVIOR_BOOT_NO_CONN_5MIN && now > 300000 && stac == 0) { // disconnect AP after 5min if no clients connected
dnsServer.stop(); // if AP was enabled more than 10min after boot or if client was connected more than 10min after boot do not disconnect AP mode
WiFi.softAPdisconnect(true); if (now < 600000) {
apActive = false; dnsServer.stop();
DEBUG_PRINTLN(F("Access point disabled (after 5min).")); WiFi.softAPdisconnect(true);
apActive = false;
DEBUG_PRINTLN(F("Access point disabled (after 5min)."));
}
} }
} else if (!interfacesInited) { //newly connected } else if (!interfacesInited) { //newly connected
DEBUG_PRINTLN(""); DEBUG_PRINTLN("");