Compare commits

...

3 commits

Author SHA1 Message Date
Morgan 'ARR\!' Allen
826b652994 refactor event group 2023-09-12 14:27:46 -07:00
Morgan 'ARR\!' Allen
0fa2ec0b76 add event group bit for IP 2022-04-02 10:39:17 -07:00
Morgan 'ARR\!' Allen
0d0a7817ba cmake idf compatibility 2022-04-02 10:35:03 -07:00
3 changed files with 22 additions and 4 deletions

6
CMakeLists.txt Normal file
View file

@ -0,0 +1,6 @@
idf_component_register(SRCS
"main/esp32-wifi-manager.c"
INCLUDE_DIRS "include"
REQUIRES nvs_flash
)

View file

@ -12,12 +12,14 @@ void wifi_manager_reset_store();
#define AP_AVAILABLE (BIT2) #define AP_AVAILABLE (BIT2)
#define WIFI_IDLE (BIT3) #define WIFI_IDLE (BIT3)
#define WIFI_SCANNING (BIT4) #define WIFI_SCANNING (BIT4)
#define WM_GOT_IP (BIT7)
uint8_t wifi_manager_ap_count(); uint8_t wifi_manager_ap_count();
uint8_t wifi_manager_add_ap(char *essid, char *password); uint8_t wifi_manager_add_ap(char *essid, char *password);
void wifi_manager_connect(); 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(); int wifi_manager_bootstrap_config();

View file

@ -24,6 +24,7 @@
#define MAX_PASSWORD (64) #define MAX_PASSWORD (64)
static const char *TAG = "WM"; static const char *TAG = "WM";
static EventGroupHandle_t wm_event_group;
nvs_handle nvs; nvs_handle nvs;
typedef struct wifi_manager_ap_info { typedef struct wifi_manager_ap_info {
@ -40,7 +41,10 @@ typedef struct ap_store_base {
} ap_store_t; } ap_store_t;
ap_store_t ap_store; 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() { uint8_t wifi_manager_ap_count() {
return ap_store.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, "SYSTEM_EVENT_STA_GOT_IP");
ESP_LOGI(TAG, "Got IP: %s\n", ESP_LOGI(TAG, "Got IP: %s\n",
ip4addr_ntoa(&event->ip_info.ip)); ip4addr_ntoa(&event->ip_info.ip));
xEventGroupSetBits(wm_event_group, WM_GOT_IP);
} else if(event_id == SYSTEM_EVENT_STA_DISCONNECTED) { } else if(event_id == SYSTEM_EVENT_STA_DISCONNECTED) {
wifi_event_sta_disconnected_t *event = ( wifi_event_sta_disconnected_t*)event_data; 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); 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)); ESP_ERROR_CHECK(nvs_open("wm-config", NVS_READWRITE, &nvs));
wm_event_group = xEventGroupCreate(); wm_event_group = xEventGroupCreate();
@ -266,7 +272,11 @@ EventGroupHandle_t wifi_manager_start() {
ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default()); 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(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();