Access point fixes (#137)
* add lingering mode to access point fix bug which prevents active access point from being re-configured
This commit is contained in:
@ -4,7 +4,8 @@ APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityMan
|
||||
_httpEndpoint(APSettings::read, APSettings::update, this, server, AP_SETTINGS_SERVICE_PATH, securityManager),
|
||||
_fsPersistence(APSettings::read, APSettings::update, this, fs, AP_SETTINGS_FILE),
|
||||
_dnsServer(nullptr),
|
||||
_lastManaged(0) {
|
||||
_lastManaged(0),
|
||||
_reconfigureAp(false) {
|
||||
addUpdateHandler([&](const String& originId) { reconfigureAP(); }, false);
|
||||
}
|
||||
|
||||
@ -15,6 +16,7 @@ void APSettingsService::begin() {
|
||||
|
||||
void APSettingsService::reconfigureAP() {
|
||||
_lastManaged = millis() - MANAGE_NETWORK_DELAY;
|
||||
_reconfigureAp = true;
|
||||
}
|
||||
|
||||
void APSettingsService::loop() {
|
||||
@ -31,14 +33,14 @@ void APSettingsService::manageAP() {
|
||||
WiFiMode_t currentWiFiMode = WiFi.getMode();
|
||||
if (_state.provisionMode == AP_MODE_ALWAYS ||
|
||||
(_state.provisionMode == AP_MODE_DISCONNECTED && WiFi.status() != WL_CONNECTED)) {
|
||||
if (currentWiFiMode == WIFI_OFF || currentWiFiMode == WIFI_STA) {
|
||||
if (_reconfigureAp || currentWiFiMode == WIFI_OFF || currentWiFiMode == WIFI_STA) {
|
||||
startAP();
|
||||
}
|
||||
} else {
|
||||
if (currentWiFiMode == WIFI_AP || currentWiFiMode == WIFI_AP_STA) {
|
||||
stopAP();
|
||||
}
|
||||
} else if ((currentWiFiMode == WIFI_AP || currentWiFiMode == WIFI_AP_STA) &&
|
||||
(_reconfigureAp || !WiFi.softAPgetStationNum())) {
|
||||
stopAP();
|
||||
}
|
||||
_reconfigureAp = false;
|
||||
}
|
||||
|
||||
void APSettingsService::startAP() {
|
||||
@ -69,3 +71,12 @@ void APSettingsService::handleDNS() {
|
||||
_dnsServer->processNextRequest();
|
||||
}
|
||||
}
|
||||
|
||||
APNetworkStatus APSettingsService::getAPNetworkStatus() {
|
||||
WiFiMode_t currentWiFiMode = WiFi.getMode();
|
||||
bool apActive = currentWiFiMode == WIFI_AP || currentWiFiMode == WIFI_AP_STA;
|
||||
if (apActive && _state.provisionMode != AP_MODE_ALWAYS && WiFi.status() == WL_CONNECTED) {
|
||||
return APNetworkStatus::LINGERING;
|
||||
}
|
||||
return apActive ? APNetworkStatus::ACTIVE : APNetworkStatus::INACTIVE;
|
||||
}
|
||||
|
@ -30,6 +30,12 @@
|
||||
#define AP_SETTINGS_FILE "/config/apSettings.json"
|
||||
#define AP_SETTINGS_SERVICE_PATH "/rest/apSettings"
|
||||
|
||||
enum APNetworkStatus {
|
||||
ACTIVE = 0,
|
||||
INACTIVE,
|
||||
LINGERING
|
||||
};
|
||||
|
||||
class APSettings {
|
||||
public:
|
||||
uint8_t provisionMode;
|
||||
@ -43,17 +49,23 @@ class APSettings {
|
||||
}
|
||||
|
||||
static StateUpdateResult update(JsonObject& root, APSettings& settings) {
|
||||
settings.provisionMode = root["provision_mode"] | FACTORY_AP_PROVISION_MODE;
|
||||
APSettings newSettings = {};
|
||||
newSettings.provisionMode = root["provision_mode"] | FACTORY_AP_PROVISION_MODE;
|
||||
switch (settings.provisionMode) {
|
||||
case AP_MODE_ALWAYS:
|
||||
case AP_MODE_DISCONNECTED:
|
||||
case AP_MODE_NEVER:
|
||||
break;
|
||||
default:
|
||||
settings.provisionMode = AP_MODE_ALWAYS;
|
||||
newSettings.provisionMode = AP_MODE_ALWAYS;
|
||||
}
|
||||
settings.ssid = root["ssid"] | FACTORY_AP_SSID;
|
||||
settings.password = root["password"] | FACTORY_AP_PASSWORD;
|
||||
newSettings.ssid = root["ssid"] | FACTORY_AP_SSID;
|
||||
newSettings.password = root["password"] | FACTORY_AP_PASSWORD;
|
||||
if (newSettings.provisionMode == settings.provisionMode && newSettings.ssid.equals(settings.ssid) &&
|
||||
newSettings.password.equals(settings.password)) {
|
||||
return StateUpdateResult::UNCHANGED;
|
||||
}
|
||||
settings = newSettings;
|
||||
return StateUpdateResult::CHANGED;
|
||||
}
|
||||
};
|
||||
@ -64,6 +76,7 @@ class APSettingsService : public StatefulService<APSettings> {
|
||||
|
||||
void begin();
|
||||
void loop();
|
||||
APNetworkStatus getAPNetworkStatus();
|
||||
|
||||
private:
|
||||
HttpEndpoint<APSettings> _httpEndpoint;
|
||||
@ -73,7 +86,8 @@ class APSettingsService : public StatefulService<APSettings> {
|
||||
DNSServer* _dnsServer;
|
||||
|
||||
// for the mangement delay loop
|
||||
unsigned long _lastManaged;
|
||||
volatile unsigned long _lastManaged;
|
||||
volatile boolean _reconfigureAp;
|
||||
|
||||
void reconfigureAP();
|
||||
void manageAP();
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <APStatus.h>
|
||||
|
||||
APStatus::APStatus(AsyncWebServer* server, SecurityManager* securityManager) {
|
||||
APStatus::APStatus(AsyncWebServer* server, SecurityManager* securityManager, APSettingsService* apSettingsService) :
|
||||
_apSettingsService(apSettingsService) {
|
||||
server->on(AP_STATUS_SERVICE_PATH,
|
||||
HTTP_GET,
|
||||
securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1),
|
||||
@ -11,8 +12,7 @@ void APStatus::apStatus(AsyncWebServerRequest* request) {
|
||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_AP_STATUS_SIZE);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
WiFiMode_t currentWiFiMode = WiFi.getMode();
|
||||
root["active"] = (currentWiFiMode == WIFI_AP || currentWiFiMode == WIFI_AP_STA);
|
||||
root["status"] = _apSettingsService->getAPNetworkStatus();
|
||||
root["ip_address"] = WiFi.softAPIP().toString();
|
||||
root["mac_address"] = WiFi.softAPmacAddress();
|
||||
root["station_num"] = WiFi.softAPgetStationNum();
|
||||
|
@ -14,15 +14,17 @@
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <IPAddress.h>
|
||||
#include <SecurityManager.h>
|
||||
#include <APSettingsService.h>
|
||||
|
||||
#define MAX_AP_STATUS_SIZE 1024
|
||||
#define AP_STATUS_SERVICE_PATH "/rest/apStatus"
|
||||
|
||||
class APStatus {
|
||||
public:
|
||||
APStatus(AsyncWebServer* server, SecurityManager* securityManager);
|
||||
APStatus(AsyncWebServer* server, SecurityManager* securityManager, APSettingsService* apSettingsService);
|
||||
|
||||
private:
|
||||
APSettingsService* _apSettingsService;
|
||||
void apStatus(AsyncWebServerRequest* request);
|
||||
};
|
||||
|
||||
|
@ -13,7 +13,7 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs) :
|
||||
_wifiScanner(server, &_securitySettingsService),
|
||||
_wifiStatus(server, &_securitySettingsService),
|
||||
_ntpStatus(server, &_securitySettingsService),
|
||||
_apStatus(server, &_securitySettingsService),
|
||||
_apStatus(server, &_securitySettingsService, &_apSettingsService),
|
||||
_mqttStatus(server, &_mqttSettingsService, &_securitySettingsService),
|
||||
_systemStatus(server, &_securitySettingsService) {
|
||||
#ifdef PROGMEM_WWW
|
||||
|
Reference in New Issue
Block a user