diff -r 382697f556bb -r e63b17b80244 main/task_wifi.c --- a/main/task_wifi.c Mon May 31 16:52:10 2021 +0200 +++ b/main/task_wifi.c Thu Jun 24 14:07:49 2021 +0200 @@ -16,6 +16,8 @@ wifi_ap_record_t *accessp_records; ///< [MAX_AP_NUM] records array with scan results. wifi_config_t *task_wifi_ConfigSTA = NULL; ///< Current STA configuration. WIFI_State *wifi_state = NULL; ///< Public state for other tasks. +esp_netif_t *sta_netif = NULL; ///< Station interface + wifi_scan_config_t scan_config = { .ssid = 0, @@ -88,7 +90,7 @@ case WIFI_EVENT_STA_START: ESP_LOGI(TAG, "Event wifi START"); // Set the configured hostname for the dhcp client. - ESP_ERROR_CHECK(tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, config.hostname)); + ESP_ERROR_CHECK(esp_netif_set_hostname(sta_netif, config.hostname)); esp_wifi_connect(); break; @@ -149,9 +151,9 @@ ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { wifi_state->STA_online = true; - snprintf(wifi_state->STA_ip, 16, "%s", ip4addr_ntoa(&event->ip_info.ip)); - snprintf(wifi_state->STA_nm, 16, "%s", ip4addr_ntoa(&event->ip_info.netmask)); - snprintf(wifi_state->STA_gw, 16, "%s", ip4addr_ntoa(&event->ip_info.gw)); + snprintf(wifi_state->STA_ip, 16, IPSTR, IP2STR(&event->ip_info.ip)); + snprintf(wifi_state->STA_nm, 16, IPSTR, IP2STR(&event->ip_info.netmask)); + snprintf(wifi_state->STA_gw, 16, IPSTR, IP2STR(&event->ip_info.gw)); xSemaphoreGive(xSemaphoreWiFi); } else { ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_GOT_IP"); @@ -193,8 +195,10 @@ /* event handler and event group for the wifi driver */ xEventGroupWifi = xEventGroupCreate(); /* initialize the tcp stack */ - tcpip_adapter_init(); + ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); + sta_netif = esp_netif_create_default_wifi_sta(); + assert(sta_netif); /* * memory allocation of objects used by the task @@ -207,18 +211,16 @@ wifi_state = malloc(sizeof(WIFI_State)); memset(wifi_state, 0x00, sizeof(WIFI_State)); - /* stop dhcp server and start dhcp client */ - ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP)); - ESP_ERROR_CHECK(tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA)); - /* * init wifi as station */ wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_config)); - ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL) ); - ESP_ERROR_CHECK( esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &got_ip_event_handler, NULL) ); + esp_event_handler_instance_t instance_any_id; + esp_event_handler_instance_t instance_got_ip; + ESP_ERROR_CHECK( esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, &instance_any_id) ); + ESP_ERROR_CHECK( esp_event_handler_instance_register(IP_EVENT, ESP_EVENT_ANY_ID, &got_ip_event_handler, NULL, &instance_got_ip) ); ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));