Split wifi_init into wifi_init and wifi_connect

This commit is contained in:
Renze Nicolai 2022-05-13 22:56:20 +02:00
parent 90636e01c6
commit 8d61e4be6b
3 changed files with 13 additions and 5 deletions

View file

@ -5,4 +5,5 @@
#include "esp_wifi.h"
bool wifi_init(const char* aSsid, const char* aPassword, wifi_auth_mode_t aAuthmode, uint8_t aRetryMax);
void wifi_init();
bool wifi_connect(const char* aSsid, const char* aPassword, wifi_auth_mode_t aAuthmode, uint8_t aRetryMax);

View file

@ -379,6 +379,9 @@ void app_main(void) {
ws2812_init(GPIO_LED_DATA);
uint8_t ledBuffer[15] = {50, 0, 0, 50, 0, 0, 50, 0, 0, 50, 0, 0, 50, 0, 0};
ws2812_send_data(ledBuffer, sizeof(ledBuffer));
/* Start WiFi */
wifi_init();
/* Launcher menu */
while (true) {
@ -419,7 +422,7 @@ void app_main(void) {
}
}
nvs_close(&handle);
wifi_init(ssid, password, WIFI_AUTH_WPA2_PSK, 3);
wifi_connect(ssid, password, WIFI_AUTH_WPA2_PSK, 3);
} else if (menu_action == ACTION_OTA) {
graphics_task(pax_buffer, ili9341, framebuffer, NULL, "Firmware update...");
} else if (menu_action == ACTION_SETTINGS) {

View file

@ -41,9 +41,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
}
}
bool wifi_init(const char* aSsid, const char* aPassword, wifi_auth_mode_t aAuthmode, uint8_t aRetryMax) {
gRetryCounter = 0;
gRetryMax = aRetryMax;
void wifi_init() {
s_wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_netif_init());
@ -58,7 +56,13 @@ bool wifi_init(const char* aSsid, const char* aPassword, wifi_auth_mode_t aAuthm
esp_event_handler_instance_t instance_got_ip;
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id));
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip));
ESP_ERROR_CHECK(esp_wifi_stop());
}
bool wifi_connect(const char* aSsid, const char* aPassword, wifi_auth_mode_t aAuthmode, uint8_t aRetryMax) {
gRetryCounter = 0;
gRetryMax = aRetryMax;
wifi_config_t wifi_config = {0};
strcpy((char*) wifi_config.sta.ssid, aSsid);
strcpy((char*) wifi_config.sta.password, aPassword);