Compare commits
3 commits
8286b2e3ce
...
developmen
Author | SHA1 | Date | |
---|---|---|---|
|
826b652994 | ||
|
0fa2ec0b76 | ||
|
0d0a7817ba |
3 changed files with 22 additions and 4 deletions
6
CMakeLists.txt
Normal file
6
CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
idf_component_register(SRCS
|
||||
"main/esp32-wifi-manager.c"
|
||||
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES nvs_flash
|
||||
)
|
|
@ -12,12 +12,14 @@ void wifi_manager_reset_store();
|
|||
#define AP_AVAILABLE (BIT2)
|
||||
#define WIFI_IDLE (BIT3)
|
||||
#define WIFI_SCANNING (BIT4)
|
||||
#define WM_GOT_IP (BIT7)
|
||||
|
||||
uint8_t wifi_manager_ap_count();
|
||||
uint8_t wifi_manager_add_ap(char *essid, char *password);
|
||||
|
||||
void wifi_manager_connect();
|
||||
EventGroupHandle_t wifi_manager_start();
|
||||
EventGroupHandle_t wifi_manager_start(char *hostname);
|
||||
EventGroupHandle_t wifi_manager_get_event_group();
|
||||
|
||||
int wifi_manager_bootstrap_config();
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#define MAX_PASSWORD (64)
|
||||
|
||||
static const char *TAG = "WM";
|
||||
static EventGroupHandle_t wm_event_group;
|
||||
nvs_handle nvs;
|
||||
|
||||
typedef struct wifi_manager_ap_info {
|
||||
|
@ -40,7 +41,10 @@ typedef struct ap_store_base {
|
|||
} ap_store_t;
|
||||
|
||||
ap_store_t ap_store;
|
||||
static EventGroupHandle_t wm_event_group;
|
||||
|
||||
EventGroupHandle_t wifi_manager_get_event_group() {
|
||||
return wm_event_group;
|
||||
}
|
||||
|
||||
uint8_t wifi_manager_ap_count() {
|
||||
return ap_store.count;
|
||||
|
@ -61,6 +65,8 @@ static esp_err_t wifi_event_handler(void* arg, esp_event_base_t event_base, int3
|
|||
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP");
|
||||
ESP_LOGI(TAG, "Got IP: %s\n",
|
||||
ip4addr_ntoa(&event->ip_info.ip));
|
||||
|
||||
xEventGroupSetBits(wm_event_group, WM_GOT_IP);
|
||||
} else if(event_id == SYSTEM_EVENT_STA_DISCONNECTED) {
|
||||
wifi_event_sta_disconnected_t *event = ( wifi_event_sta_disconnected_t*)event_data;
|
||||
|
||||
|
@ -257,7 +263,7 @@ void wifi_manager_load_config() {
|
|||
ESP_LOGI(TAG, "AP: %s", ap_store.aps[i].ssid);
|
||||
};
|
||||
|
||||
EventGroupHandle_t wifi_manager_start() {
|
||||
EventGroupHandle_t wifi_manager_start(char *hostname) {
|
||||
ESP_ERROR_CHECK(nvs_open("wm-config", NVS_READWRITE, &nvs));
|
||||
|
||||
wm_event_group = xEventGroupCreate();
|
||||
|
@ -266,7 +272,11 @@ EventGroupHandle_t wifi_manager_start() {
|
|||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_create_default_wifi_sta();
|
||||
esp_netif_t *netif = esp_netif_create_default_wifi_sta();
|
||||
|
||||
if(hostname != NULL) {
|
||||
esp_netif_set_hostname(netif, hostname);
|
||||
}
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
|
|
Loading…
Reference in a new issue