2018-02-26 00:11:31 +00:00
|
|
|
#ifndef WiFiSettingsService_h
|
|
|
|
#define WiFiSettingsService_h
|
|
|
|
|
2019-08-10 11:35:26 +00:00
|
|
|
#include <AdminSettingsService.h>
|
2018-11-11 16:36:41 +00:00
|
|
|
#include <IPAddress.h>
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
#define WIFI_SETTINGS_FILE "/config/wifiSettings.json"
|
2018-04-01 09:35:23 +00:00
|
|
|
#define WIFI_SETTINGS_SERVICE_PATH "/rest/wifiSettings"
|
2020-02-01 20:21:18 +00:00
|
|
|
#define WIFI_RECONNECTION_DELAY 1000 * 30
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2020-02-01 08:44:26 +00:00
|
|
|
class WiFiSettings {
|
|
|
|
public:
|
|
|
|
// core wifi configuration
|
|
|
|
String ssid;
|
|
|
|
String password;
|
|
|
|
String hostname;
|
|
|
|
bool staticIPConfig;
|
|
|
|
|
|
|
|
// optional configuration for static IP address
|
|
|
|
IPAddress localIP;
|
|
|
|
IPAddress gatewayIP;
|
|
|
|
IPAddress subnetMask;
|
|
|
|
IPAddress dnsIP1;
|
|
|
|
IPAddress dnsIP2;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WiFiSettingsService : public AdminSettingsService<WiFiSettings> {
|
2019-12-03 23:16:06 +00:00
|
|
|
public:
|
|
|
|
WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
|
|
|
|
~WiFiSettingsService();
|
|
|
|
|
|
|
|
void begin();
|
|
|
|
void loop();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void readFromJsonObject(JsonObject& root);
|
|
|
|
void writeToJsonObject(JsonObject& root);
|
|
|
|
void onConfigUpdated();
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned long _lastConnectionAttempt;
|
|
|
|
|
2019-12-24 11:19:19 +00:00
|
|
|
#ifdef ESP32
|
2020-02-01 20:21:18 +00:00
|
|
|
bool _stopping;
|
2019-12-24 11:19:19 +00:00
|
|
|
void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
|
2020-02-01 20:21:18 +00:00
|
|
|
void onStationModeStop(WiFiEvent_t event, WiFiEventInfo_t info);
|
2019-12-24 11:19:19 +00:00
|
|
|
#elif defined(ESP8266)
|
2019-12-03 23:16:06 +00:00
|
|
|
WiFiEventHandler _onStationModeDisconnectedHandler;
|
|
|
|
void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
|
2019-06-04 23:05:16 +00:00
|
|
|
#endif
|
2018-04-01 09:35:23 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
void readIP(JsonObject& root, String key, IPAddress& _ip);
|
|
|
|
void writeIP(JsonObject& root, String key, IPAddress& _ip);
|
|
|
|
void reconfigureWiFiConnection();
|
|
|
|
void manageSTA();
|
2018-02-26 00:11:31 +00:00
|
|
|
};
|
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
#endif // end WiFiSettingsService_h
|