refactor event group
This commit is contained in:
parent
0fa2ec0b76
commit
826b652994
2 changed files with 13 additions and 4 deletions
|
@ -18,7 +18,8 @@ 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();
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -259,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();
|
||||||
|
@ -268,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();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue