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:
parent
477307ee18
commit
d23505609b
15
main/main.c
15
main/main.c
|
@ -8,6 +8,18 @@
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
#include "driver/gpio.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
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
|
|
||||||
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
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)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
nvs_flash_init();
|
nvs_flash_init();
|
||||||
tcpip_adapter_init();
|
TCPIP_INIT();
|
||||||
|
|
||||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
|
@ -41,6 +53,7 @@ void app_main(void)
|
||||||
#else
|
#else
|
||||||
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
|
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
|
||||||
#endif
|
#endif
|
||||||
|
CREATE_WIFI_STATION();
|
||||||
|
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
|
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
|
||||||
|
|
Loading…
Reference in New Issue