esp_netif: Updated init code to use esp-netif instead of tcpip_adapter

From IDF 4.1.0 ESP-NETIF approach is encouraged and all network
interfaces have to be explicitely created
This commit is contained in:
David Cermak 2019-09-04 15:10:33 +02:00
parent 477307ee18
commit d23505609b
1 changed files with 14 additions and 1 deletions

View File

@ -8,6 +8,18 @@
#include "nvs_flash.h"
#include "driver/gpio.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
//
// From IDF 4.1.0 ESP-NETIF approach is encouraged and all network
// interfaces have to be explicitely created
//
#define TCPIP_INIT() esp_netif_init()
#define CREATE_WIFI_STATION() assert(esp_netif_create_default_wifi_sta())
#else
#define TCPIP_INIT() tcpip_adapter_init()
#define CREATE_WIFI_STATION()
#endif
#if ESP_IDF_VERSION_MAJOR >= 4
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
@ -32,7 +44,7 @@ esp_err_t event_handler(void *ctx, system_event_t *event)
void app_main(void)
{
nvs_flash_init();
tcpip_adapter_init();
TCPIP_INIT();
#if ESP_IDF_VERSION_MAJOR >= 4
ESP_ERROR_CHECK(esp_event_loop_create_default());
@ -41,6 +53,7 @@ void app_main(void)
#else
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
#endif
CREATE_WIFI_STATION();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );