8 #ifndef COMPONENTS_NETWORK_SRC_WIFIMANAGER_H_
9 #define COMPONENTS_NETWORK_SRC_WIFIMANAGER_H_
15 #include "freertos/FreeRTOS.h"
16 #include "freertos/task.h"
17 #include "freertos/queue.h"
18 #include "freertos/event_groups.h"
19 #include "freertos/semphr.h"
20 #include "esp_system.h"
22 #include "esp_event.h"
23 #include "esp_event_loop.h"
25 #include "esp_smartconfig.h"
26 #include "lwip/ip_addr.h"
27 #include "tcpip_adapter.h"
30 #include "nvs_flash.h"
33 #define WIFIMANAGER_DEFAULT_TIMEOUT 60000/portTICK_PERIOD_MS
52 WIFI_STATUS_STA_SMARTCONFIG
55 typedef std::function<void(system_event_t *event)> WifiEventCallback;
56 typedef std::function<void(bool)> WifiConnectedCallback;
57 typedef std::function<void()> WifiDisconnectedCallback;
58 typedef std::function<void(uint64_t elapsedTime, Status_t status)> WifiConnectingCallback;
69 esp_err_t
begin(wifi_mode_t mode = WIFI_MODE_STA,
bool autoConnect =
true);
70 esp_err_t connectToAP(
const char *ssid,
const char *pwd, uint32_t ticks_to_wait = WIFIMANAGER_DEFAULT_TIMEOUT);
75 esp_err_t
startSmartConfig(smartconfig_type_t sc_type = SC_TYPE_ESPTOUCH, uint32_t ticks_to_wait = WIFIMANAGER_DEFAULT_TIMEOUT);
81 tcpip_adapter_ip_info_t getStationIpInfo();
82 std::string getStationIpAddress();
84 void onWiFiEvent(WifiEventCallback cb) {
85 wifiEventCallback_ = cb;
88 void onWiFiConnected(WifiConnectedCallback cb) {
89 wifiConnectedCallback_ = cb;
92 void onWiFiDisconnected(WifiDisconnectedCallback cb) {
93 wifiDisconnectedCallback_ = cb;
96 void onWiFiConnecting(WifiConnectingCallback cb) {
97 wifiConnectingCallback_ = cb;
100 void notifyEvent(system_event_t *event);
108 wifi_mode_t currentMode_ = WIFI_MODE_NULL;
110 WifiEventCallback wifiEventCallback_ =
nullptr;
111 WifiConnectedCallback wifiConnectedCallback_ =
nullptr;
112 WifiDisconnectedCallback wifiDisconnectedCallback_ =
nullptr;
113 WifiConnectingCallback wifiConnectingCallback_ =
nullptr;
116 uint32_t connectTimeout_ = 0;
118 uint64_t lastConnectingCheckMicros_ = 0;
120 esp_err_t loadSavedStaConfig(wifi_sta_config_t *saved_sta_config);
121 esp_err_t saveStaConfig(wifi_sta_config_t *sta_config);
122 bool newConnection_ =
false;
123 wifi_sta_config_t *savedStaConfig = NULL;
Definition: WiFiManager.h:51
esp_err_t startSmartConfig(smartconfig_type_t sc_type=SC_TYPE_ESPTOUCH, uint32_t ticks_to_wait=WIFIMANAGER_DEFAULT_TIMEOUT)
Definition: WiFiManager.cpp:465
esp_err_t begin(wifi_mode_t mode=WIFI_MODE_STA, bool autoConnect=true)
Definition: WiFiManager.cpp:112
Definition: WiFiManager.h:49
void runAsync(void *taskData)
Body of the task to execute.
Definition: WiFiManager.cpp:405
WiFiManager class.
Definition: WiFiManager.h:45
Definition: WiFiManager.h:50
bool waitForConnection()
Definition: WiFiManager.cpp:326
Status_t
Definition: WiFiManager.h:48
Encapsulate a runnable task.
Definition: Task.h:34