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"
|
2019-06-04 20:13:55 +00:00
|
|
|
#define WIFI_RECONNECTION_DELAY 1000 * 60
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-05-29 22:48:16 +00:00
|
|
|
class WiFiSettingsService : public AdminSettingsService {
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-09-28 20:29:46 +00:00
|
|
|
WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
|
2018-02-26 00:11:31 +00:00
|
|
|
~WiFiSettingsService();
|
|
|
|
|
2019-09-30 20:28:24 +00:00
|
|
|
void begin();
|
2019-06-04 20:13:55 +00:00
|
|
|
void loop();
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void readFromJsonObject(JsonObject& root);
|
|
|
|
void writeToJsonObject(JsonObject& root);
|
|
|
|
void onConfigUpdated();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// connection settings
|
|
|
|
String _ssid;
|
|
|
|
String _password;
|
|
|
|
String _hostname;
|
|
|
|
bool _staticIPConfig;
|
|
|
|
|
2019-06-04 20:13:55 +00:00
|
|
|
// for the mangement delay loop
|
|
|
|
unsigned long _lastConnectionAttempt;
|
|
|
|
|
2018-02-26 00:11:31 +00:00
|
|
|
// optional configuration for static IP address
|
|
|
|
IPAddress _localIP;
|
|
|
|
IPAddress _gatewayIP;
|
|
|
|
IPAddress _subnetMask;
|
|
|
|
IPAddress _dnsIP1;
|
|
|
|
IPAddress _dnsIP2;
|
|
|
|
|
2019-06-04 23:05:16 +00:00
|
|
|
#if defined(ESP8266)
|
|
|
|
WiFiEventHandler _onStationModeDisconnectedHandler;
|
|
|
|
void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
|
|
|
|
#elif defined(ESP_PLATFORM)
|
|
|
|
void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
|
|
|
|
#endif
|
|
|
|
|
2018-02-26 00:11:31 +00:00
|
|
|
void readIP(JsonObject& root, String key, IPAddress& _ip);
|
|
|
|
void writeIP(JsonObject& root, String key, IPAddress& _ip);
|
2019-06-04 20:13:55 +00:00
|
|
|
void reconfigureWiFiConnection();
|
|
|
|
void manageSTA();
|
2018-04-01 09:35:23 +00:00
|
|
|
|
2018-02-26 00:11:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // end WiFiSettingsService_h
|