Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

  1. #ifndef WiFiSettingsService_h
  2. #define WiFiSettingsService_h
  3. #include <AdminSettingsService.h>
  4. #include <IPAddress.h>
  5. #define WIFI_SETTINGS_FILE "/config/wifiSettings.json"
  6. #define WIFI_SETTINGS_SERVICE_PATH "/rest/wifiSettings"
  7. #define WIFI_RECONNECTION_DELAY 1000 * 60
  8. class WiFiSettingsService : public AdminSettingsService {
  9. public:
  10. WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
  11. ~WiFiSettingsService();
  12. void begin();
  13. void loop();
  14. protected:
  15. void readFromJsonObject(JsonObject& root);
  16. void writeToJsonObject(JsonObject& root);
  17. void onConfigUpdated();
  18. private:
  19. // connection settings
  20. String _ssid;
  21. String _password;
  22. String _hostname;
  23. bool _staticIPConfig;
  24. // for the mangement delay loop
  25. unsigned long _lastConnectionAttempt;
  26. // optional configuration for static IP address
  27. IPAddress _localIP;
  28. IPAddress _gatewayIP;
  29. IPAddress _subnetMask;
  30. IPAddress _dnsIP1;
  31. IPAddress _dnsIP2;
  32. #if defined(ESP8266)
  33. WiFiEventHandler _onStationModeDisconnectedHandler;
  34. void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
  35. #elif defined(ESP_PLATFORM)
  36. void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
  37. #endif
  38. void readIP(JsonObject& root, String key, IPAddress& _ip);
  39. void writeIP(JsonObject& root, String key, IPAddress& _ip);
  40. void reconfigureWiFiConnection();
  41. void manageSTA();
  42. };
  43. #endif // end WiFiSettingsService_h