examples: modify other examples and tests to use esp_netif instead of tcpip_adapter

This commit is contained in:
David Cermak 2019-09-01 18:25:23 +02:00
parent 0eec84bc4f
commit b834c99148
24 changed files with 85 additions and 54 deletions

View file

@ -94,8 +94,10 @@ TEST_CASE("adc2 work with wifi","[adc]")
r = nvs_flash_init();
}
TEST_ESP_OK( r);
tcpip_adapter_init();
esp_netif_init();
event_init();
esp_netif_create_default_wifi_sta();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
TEST_ESP_OK(esp_wifi_init(&cfg));
wifi_config_t wifi_config = {
@ -144,5 +146,5 @@ TEST_CASE("adc2 work with wifi","[adc]")
printf("test passed...\n");
TEST_IGNORE_MESSAGE("this test case is ignored due to the critical memory leak of tcpip_adapter and event_loop.");
TEST_IGNORE_MESSAGE("this test case is ignored due to the critical memory leak of esp_netif and event_loop.");
}

View file

@ -62,7 +62,7 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
{
EventGroupHandle_t eth_event_group = (EventGroupHandle_t)arg;
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
const tcpip_adapter_ip_info_t *ip_info = (tcpip_adapter_ip_info_t *)&event->ip_info;
const esp_netif_ip_info_t *ip_info = &event->ip_info;
ESP_LOGI(TAG, "Ethernet Got IP Address");
ESP_LOGI(TAG, "~~~~~~~~~~~");
@ -309,9 +309,11 @@ TEST_CASE("dm9051 io test", "[ethernet][ignore]")
};
TEST_ESP_OK(spi_bus_add_device(HSPI_HOST, &devcfg, &spi_handle));
gpio_install_isr_service(0);
tcpip_adapter_init();
esp_netif_init();
TEST_ESP_OK(esp_event_loop_create_default());
TEST_ESP_OK(tcpip_adapter_set_default_eth_handlers());
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
esp_netif_t* eth_netif = esp_netif_new(&cfg);
TEST_ESP_OK(esp_eth_set_default_handlers(eth_netif));
TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));
TEST_ESP_OK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
@ -322,6 +324,7 @@ TEST_CASE("dm9051 io test", "[ethernet][ignore]")
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
esp_eth_handle_t eth_handle = NULL;
TEST_ESP_OK(esp_eth_driver_install(&config, &eth_handle));
TEST_ESP_OK(esp_netif_attach(eth_netif, eth_handle));
vTaskDelay(pdMS_TO_TICKS(portMAX_DELAY));
TEST_ESP_OK(esp_eth_driver_uninstall(eth_handle));
TEST_ESP_OK(phy->del(phy));

View file

@ -17,7 +17,7 @@
#include <stdio.h>
#include <stdarg.h>
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "lwip/sockets.h"
#include "esp32/rom/md5_hash.h"
#include "mbedtls/base64.h"

View file

@ -21,7 +21,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "lwip/sockets.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "esp_log.h"
#include "esp_wifi.h"
#include "esp_event.h"
@ -69,7 +69,7 @@ static int sc_ack_send_get_errno(int fd)
static void sc_ack_send_task(void *pvParameters)
{
sc_ack_t *ack = (sc_ack_t *)pvParameters;
tcpip_adapter_ip_info_t local_ip;
esp_netif_ip_info_t local_ip;
uint8_t remote_ip[4];
memcpy(remote_ip, ack->ctx.ip, sizeof(remote_ip));
int remote_port = (ack->type == SC_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_SERVER_PORT : SC_ACK_AIRKISS_SERVER_PORT;
@ -94,7 +94,7 @@ static void sc_ack_send_task(void *pvParameters)
while (s_sc_ack_send) {
/* Get local IP address of station */
ret = tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &local_ip);
ret = esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &local_ip);
if ((ESP_OK == ret) && (local_ip.ip.addr != INADDR_ANY)) {
/* If ESP touch, smartconfig ACK contains local IP address. */
if (ack->type == SC_TYPE_ESPTOUCH) {

View file

@ -144,8 +144,8 @@ TEST_CASE("wifi stop and deinit","[wifi]")
}
TEST_ESP_OK(r);
//init tcpip
ESP_LOGI(TAG, EMPH_STR("tcpip_adapter_init"));
tcpip_adapter_init();
ESP_LOGI(TAG, EMPH_STR("esp_netif_init"));
esp_netif_init();
//init event loop
ESP_LOGI(TAG, EMPH_STR("event_init"));
@ -163,7 +163,7 @@ TEST_CASE("wifi stop and deinit","[wifi]")
nvs_flash_deinit();
ESP_LOGI(TAG, "test passed...");
TEST_IGNORE_MESSAGE("this test case is ignored due to the critical memory leak of tcpip_adapter and event_loop.");
TEST_IGNORE_MESSAGE("this test case is ignored due to the critical memory leak of esp_netif and event_loop.");
}
static void start_wifi_as_softap(void)

View file

@ -197,9 +197,10 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
static void initialise_wifi(void)
{
tcpip_adapter_init();
esp_netif_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_create_default());
assert(esp_netif_create_default_wifi_sta());
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, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));

View file

@ -16,7 +16,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "iperf.h"
typedef struct {
@ -51,6 +51,8 @@ static const char *TAG = "iperf";
static EventGroupHandle_t wifi_event_group;
const int CONNECTED_BIT = BIT0;
const int DISCONNECTED_BIT = BIT1;
static esp_netif_t * sta_netif = NULL;
static esp_netif_t * ap_netif = NULL;
static void scan_done_handler(void)
{
@ -124,9 +126,11 @@ void initialise_wifi(void)
return;
}
tcpip_adapter_init();
esp_netif_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_create_default());
assert(sta_netif = esp_netif_create_default_wifi_sta());
assert(ap_netif = esp_netif_create_default_wifi_ap());
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, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
@ -286,22 +290,22 @@ static int wifi_cmd_query(int argc, char **argv)
static uint32_t wifi_get_local_ip(void)
{
int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
tcpip_adapter_if_t ifx = TCPIP_ADAPTER_IF_AP;
tcpip_adapter_ip_info_t ip_info;
esp_netif_t * ifx = ap_netif;
esp_netif_ip_info_t ip_info;
wifi_mode_t mode;
esp_wifi_get_mode(&mode);
if (WIFI_MODE_STA == mode) {
bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
if (bits & CONNECTED_BIT) {
ifx = TCPIP_ADAPTER_IF_STA;
ifx = sta_netif;
} else {
ESP_LOGE(TAG, "sta has no IP");
return 0;
}
}
tcpip_adapter_get_ip_info(ifx, &ip_info);
esp_netif_get_ip_info(ifx, &ip_info);
return ip_info.ip.addr;
}

View file

@ -65,9 +65,10 @@ void wifi_init_sta(void)
{
s_wifi_event_group = xEventGroupCreate();
tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
assert(esp_netif_create_default_wifi_sta());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));

View file

@ -80,7 +80,7 @@ void app_main(void)
initialize_console();
ESP_ERROR_CHECK(nvs_flash_init());
tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* wait for active network connection */
ESP_ERROR_CHECK(example_connect());

View file

@ -15,7 +15,7 @@
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_event.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "protocol_examples_common.h"
#include "freertos/FreeRTOS.h"
@ -128,7 +128,7 @@ void app_main(void)
esp_log_level_set("OUTBOX", ESP_LOG_VERBOSE);
ESP_ERROR_CHECK(nvs_flash_init());
tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.

View file

@ -20,7 +20,7 @@
#include "netif/ppp/pppapi.h"
#include "netif/ppp/pppos.h"
#include "lwip/dns.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "esp_modem.h"
#include "esp_log.h"
#include "sdkconfig.h"

View file

@ -9,7 +9,7 @@
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "mqtt_client.h"
#include "esp_modem.h"
#include "esp_log.h"
@ -181,7 +181,7 @@ static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
void app_main(void)
{
tcpip_adapter_init();
esp_netif_init();
event_group = xEventGroupCreate();
/* create dte object */
esp_modem_dte_config_t config = ESP_MODEM_DTE_DEFAULT_CONFIG();

View file

@ -16,7 +16,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "cmd_wifi.h"
@ -44,9 +44,11 @@ static void initialise_wifi(void)
if (initialized) {
return;
}
tcpip_adapter_init();
esp_netif_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_create_default());
assert(esp_netif_create_default_wifi_ap());
assert(esp_netif_create_default_wifi_sta());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &event_handler, NULL) );

View file

@ -18,7 +18,7 @@
#include "esp_vfs.h"
#include "esp_vfs_dev.h"
#include "driver/uart.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "lwip/sockets.h"
#include "lwip/netdb.h"
@ -43,7 +43,7 @@ static void socket_init(void)
int err;
struct sockaddr_in saddr = { 0 };
tcpip_adapter_init();
esp_netif_init();
err = getaddrinfo("localhost", "80", &hints, &res);

View file

@ -21,7 +21,7 @@
#include "freertos/timers.h"
#include "nvs_flash.h"
#include "esp_event.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "esp_system.h"
@ -41,7 +41,7 @@ static void example_espnow_deinit(example_espnow_send_param_t *send_param);
/* WiFi should start before using ESPNOW */
static void example_wifi_init(void)
{
tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );

View file

@ -85,7 +85,7 @@ static void event_handler(void* arg, esp_event_base_t event_base,
/* Initialize Wi-Fi as sta and set scan method */
static void fast_scan(void)
{
tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
@ -94,6 +94,11 @@ static void fast_scan(void)
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
// Initialize default station as network interface instance (esp-netif)
esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
assert(sta_netif);
// Initialize and start WiFi
wifi_config_t wifi_config = {
.sta = {
.ssid = DEFAULT_SSID,

View file

@ -16,7 +16,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "iperf.h"
@ -48,6 +48,8 @@ static wifi_scan_arg_t scan_args;
static wifi_args_t ap_args;
static bool reconnect = true;
static const char *TAG="cmd_wifi";
static esp_netif_t *netif_ap = NULL;
static esp_netif_t *netif_sta = NULL;
static EventGroupHandle_t wifi_event_group;
const int CONNECTED_BIT = BIT0;
@ -106,9 +108,11 @@ void initialise_wifi(void)
return;
}
tcpip_adapter_init();
esp_netif_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK( esp_event_loop_create_default() );
assert(netif_ap = esp_netif_create_default_wifi_ap());
assert(netif_sta = esp_netif_create_default_wifi_sta());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_SCAN_DONE, &scan_done_handler, NULL) );
@ -266,22 +270,22 @@ static int wifi_cmd_query(int argc, char** argv)
static uint32_t wifi_get_local_ip(void)
{
int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
tcpip_adapter_if_t ifx = TCPIP_ADAPTER_IF_AP;
tcpip_adapter_ip_info_t ip_info;
esp_netif_t * netif = netif_ap;
esp_netif_ip_info_t ip_info;
wifi_mode_t mode;
esp_wifi_get_mode(&mode);
if (WIFI_MODE_STA == mode) {
bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
if (bits & CONNECTED_BIT) {
ifx = TCPIP_ADAPTER_IF_STA;
netif = netif_sta;
} else {
ESP_LOGE(TAG, "sta has no IP");
return 0;
}
}
tcpip_adapter_get_ip_info(ifx, &ip_info);
esp_netif_get_ip_info(netif, &ip_info);
return ip_info.ip.addr;
}

View file

@ -55,8 +55,9 @@ static void event_handler(void* arg, esp_event_base_t event_base,
/*init wifi as sta and set power save mode*/
static void wifi_power_save(void)
{
tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
assert(esp_netif_create_default_wifi_sta());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));

View file

@ -114,8 +114,9 @@ static void print_cipher_type(int pairwise_cipher, int group_cipher)
/* Initialize Wi-Fi as sta and set scan method */
static void wifi_scan(void)
{
tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
assert(esp_netif_create_default_wifi_sta());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));

View file

@ -11,7 +11,7 @@
#include <stdlib.h>
#include "linenoise/linenoise.h"
#include "argtable3/argtable3.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "esp_console.h"
#include "esp_event.h"
#include "esp_vfs_dev.h"
@ -64,7 +64,7 @@ static void initialize_nvs(void)
/* Initialize wifi with tcp/ip adapter */
static void initialize_wifi(void)
{
tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));

View file

@ -18,7 +18,7 @@
#include "esp_log.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "esp_smartconfig.h"
/* FreeRTOS event group to signal when we are connected & ready to make a request */
@ -78,9 +78,10 @@ static void event_handler(void* arg, esp_event_base_t event_base,
static void initialise_wifi(void)
{
tcpip_adapter_init();
esp_netif_init();
s_wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_create_default());
assert(esp_netif_create_default_wifi_sta());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );

View file

@ -27,7 +27,7 @@
#include "esp_log.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
/* The examples use simple WiFi configuration that you can set via
project configuration menu.
@ -48,6 +48,9 @@
/* FreeRTOS event group to signal when we are connected & ready to make a request */
static EventGroupHandle_t wifi_event_group;
/* esp netif object representing the WIFI station */
static esp_netif_t *sta_netif = NULL;
/* The event group allows multiple bits for each event,
but we only care about one event - are we connected
to the AP with an IP? */
@ -101,9 +104,11 @@ static void initialise_wifi(void)
unsigned int client_key_bytes = client_key_end - client_key_start;
#endif /* CONFIG_EXAMPLE_EAP_METHOD_TLS */
tcpip_adapter_init();
esp_netif_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_create_default());
assert(sta_netif = esp_netif_create_default_wifi_sta());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
@ -139,14 +144,14 @@ static void initialise_wifi(void)
static void wpa2_enterprise_example_task(void *pvParameters)
{
tcpip_adapter_ip_info_t ip;
memset(&ip, 0, sizeof(tcpip_adapter_ip_info_t));
esp_netif_ip_info_t ip;
memset(&ip, 0, sizeof(esp_netif_ip_info_t));
vTaskDelay(2000 / portTICK_PERIOD_MS);
while (1) {
vTaskDelay(2000 / portTICK_PERIOD_MS);
if (tcpip_adapter_get_ip_info(ESP_IF_WIFI_STA, &ip) == 0) {
if (esp_netif_get_ip_info(sta_netif, &ip) == 0) {
ESP_LOGI(TAG, "~~~~~~~~~~~");
ESP_LOGI(TAG, "IP:"IPSTR, IP2STR(&ip.ip));
ESP_LOGI(TAG, "MASK:"IPSTR, IP2STR(&ip.netmask));

View file

@ -97,8 +97,9 @@ static void got_ip_event_handler(void* arg, esp_event_base_t event_base,
/*init wifi as sta and start wps*/
static void start_wps(void)
{
tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
assert(esp_netif_create_default_wifi_sta());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));

View file

@ -17,7 +17,7 @@
#include "test_utils.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "lwip/sockets.h"
const esp_partition_t *get_test_data_partition(void)
@ -32,7 +32,7 @@ const esp_partition_t *get_test_data_partition(void)
void test_case_uses_tcpip(void)
{
// Can be called more than once, does nothing on subsequent calls
tcpip_adapter_init();
esp_netif_init();
// Allocate all sockets then free them
// (First time each socket is allocated some one-time allocations happen.)
@ -49,7 +49,7 @@ void test_case_uses_tcpip(void)
// Allow LWIP tasks to finish initialising themselves
vTaskDelay(25 / portTICK_RATE_MS);
printf("Note: tcpip_adapter_init() has been called. Until next reset, TCP/IP task will periodicially allocate memory and consume CPU time.\n");
printf("Note: esp_netif_init() has been called. Until next reset, TCP/IP task will periodicially allocate memory and consume CPU time.\n");
// Reset the leak checker as LWIP allocates a lot of memory on first run
unity_reset_leak_checks();