diff options
Diffstat (limited to 'main/net.cpp')
-rw-r--r-- | main/net.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/main/net.cpp b/main/net.cpp index f927390..bc9a31c 100644 --- a/main/net.cpp +++ b/main/net.cpp @@ -40,6 +40,10 @@ static const char *TAG_STA = "net Sta"; /* FreeRTOS event group to signal when we are connected/disconnected */ static EventGroupHandle_t s_wifi_event_group; +/** + * Handles wifi station events + * re-enabling the access point if connection is lost to allow reconfiguration + */ static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { @@ -73,6 +77,10 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, ESP_LOGI(TAG_STA, "%s, %li", event_base, event_id); } +/** + * Spins up mDNS advertisment + * and sets all require values as needed + */ static void setup_mdns() { ESP_ERROR_CHECK(mdns_init()); @@ -99,6 +107,10 @@ static void setup_mdns() mdns_service_add(NULL, "_http", "_tcp", 80, serviceTxtData, 6); } +/** + * Configures the SoftAP to follow tehcorrect naming schema + * as well as Network IPs + */ static bool wifi_init_softap(void) { esp_netif_t* netif = esp_netif_create_default_wifi_ap(); @@ -143,7 +155,12 @@ static bool wifi_init_softap(void) return true; } -static bool wifi_init_sta(void) +/** + * Check if a valid STA configuration exists + * + * @return true if a STA ssid is set otherwise false + */ +static bool wifi_check_sta(void) { wifi_config_t wifi_cfg; ESP_RETURN_ON_FALSE(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) == ESP_OK, false, TAG_STA, "failed to get wifi sta config"); @@ -158,6 +175,10 @@ static bool wifi_init_sta(void) return true; } +/** + * Sets up WiFi networking and attempts to figure out + * if we should connect to a network or host our own + */ esp_err_t net_connect(void) { /* Initialize event group */ @@ -197,7 +218,7 @@ esp_err_t net_connect(void) ESP_LOGE(TAG, "Failed to initialize SoftAP"); } - bool s = wifi_init_sta(); + bool s = wifi_check_sta(); if (s) ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); |