How to migrate from tcpip_adapter_* to esp_netif_`*

ataweg
Posts: 2
Joined: Sat Jan 20, 2018 1:42 pm

How to migrate from tcpip_adapter_* to esp_netif_`*

Postby ataweg » Tue Nov 19, 2019 8:17 pm

Today I updated to the last version of esp-idf and wanted to build my project. There was a message "tcpip_adapter_init () is deprecated please use esp_netif_init ()". Ok, I did it and my project was built, but there was a crash. So I edited around until my project ran again. I would like to share the necessary steps with you:

replace in your sources "tcpip_adapter_init();" with
"esp_netif_init();
sta_netif = esp_netif_create_default_wifi_sta();
assert( sta_netif );
"
replace "WIFI_IF_STA" with "ESP_IF_WIFI_STA" and "WIFI_IF_AP" with "ESP_IF_WIFI_AP"
replace "TCPIP_ADAPTER_IF_STA" with "sta_netif" and "TCPIP_ADAPTER_IF_AP" with "ap_netif"
replace "tcpip_adapter_" to "esp_netif_"
replace "TCPIP_ADAPTER_" with "ESP_NETIF_"

set in your main wifi source file
/* esp netif object representing the WIFI station */
esp_netif_t *sta_netif = NULL;
esp_netif_t *ap_netif = NULL;

in other files using these variables add
extern esp_netif_t *sta_netif;
extern esp_netif_t *ap_netif;

Maybe it will help you.
Viele Gruesse
Axel

DanCurram
Posts: 15
Joined: Tue Jun 12, 2018 2:13 pm

Re: How to migrate from tcpip_adapter_* to esp_netif_`*

Postby DanCurram » Thu Dec 05, 2019 11:38 am

So looking at using a TCP client socket and following the examples it uses esp_netif.h but the IDE cant find it so esp_netif_init(); also fails

using the version 4 release - so has anyone come across this ?

TIA Danny

ESP-Marius
Posts: 44
Joined: Wed Oct 23, 2019 1:49 am

Re: How to migrate from tcpip_adapter_* to esp_netif_`*

Postby ESP-Marius » Fri Dec 06, 2019 12:51 am

DanCurram wrote:
Thu Dec 05, 2019 11:38 am
So looking at using a TCP client socket and following the examples it uses esp_netif.h but the IDE cant find it so esp_netif_init(); also fails

using the version 4 release - so has anyone come across this ?

TIA Danny
Which examples are you looking at? If you are using release 4.0 then this doesn't have esp_netif (it will be a part of 4.1), so the examples for this version should still use the tcpip_adapter.

meneldor
Posts: 73
Joined: Mon Dec 25, 2017 7:28 am

Re: How to migrate from tcpip_adapter_* to esp_netif_`*

Postby meneldor » Fri Dec 13, 2019 5:02 pm

I just changed to v4.1 and my project is a complete mess now :) I am looking in the compilation errors and replacing 1 by 1 but it's a pain. It's hard to search in the documentation because I don't know what to search for.
It might be good if you write some article about it because this is a big change. Also, the v4 examples are not comprehensive enough. The getting_started one has only two events..

Im stuck for hours on this error:

Code: Select all

../components/WifiManager/WifiManager.cpp:647:13: error: invalid use of incomplete type 'esp_netif_t' {aka 'struct esp_netif_obj'}
    sta_netif->ip_info.ip.addr      = new_ip;
             ^~
In file included from /home/anio/esp/esp-idf/components/esp_netif/include/esp_netif.h:22,
                 from /home/anio/esp/esp-idf/components/esp_event/include/esp_event_legacy.h:22,
                 from /home/anio/esp/esp-idf/components/esp_event/include/esp_event.h:26,
                 from /home/anio/esp/esp-idf/components/esp_wifi/include/esp_wifi.h:64,
                 from ../components/WifiManager/WifiManager.cpp:22:
/home/anio/esp/esp-idf/components/esp_netif/include/esp_netif_types.h:33:8: note: forward declaration of 'esp_netif_t' {aka 'struct esp_netif_obj'}
 struct esp_netif_obj;
        ^~~~~~~~~~~~~
I declared it as:

Code: Select all

static esp_netif_t * sta_netif = NULL;
then initialized it:

Code: Select all

sta_netif = esp_netif_create_default_wifi_sta();

meneldor
Posts: 73
Joined: Mon Dec 25, 2017 7:28 am

Re: How to migrate from tcpip_adapter_* to esp_netif_`*

Postby meneldor » Sat Dec 14, 2019 9:54 pm

Well, i found the problem. I've used the esp_netif_t type in a wrong way. Now i have another problem, i cant link anything from esp_netif. The linker complains against anything netif related:

Code: Select all

/home/anio/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/WifiManager/libWifiManager.a(WifiManager.cpp.obj):(.literal._ZN11WifiManagerC2Ev+0x48): undefined reference to `esp_netif_init()'
This component is used in my custom component which has CMakeLists.txt file where i tested with PRIV_REQUIRES and REQUIRES:

Code: Select all

idf_component_register(SRCS WifiManager.cpp json/json.c
                        REQUIRES hm_config
                        PRIV_REQUIRES esp_wifi esp_netif
                        PRIV_INCLUDE_DIRS ./json
                       INCLUDE_DIRS . )

meneldor
Posts: 73
Joined: Mon Dec 25, 2017 7:28 am

Re: How to migrate from tcpip_adapter_* to esp_netif_`*

Postby meneldor » Sun Dec 15, 2019 6:20 pm

Any help please? I am stuck at this all day. The esp_netif component seems to be compiled but can't be linked. I tried all combinations to include headers and REQUIRE components.

meneldor
Posts: 73
Joined: Mon Dec 25, 2017 7:28 am

Re: How to migrate from tcpip_adapter_* to esp_netif_`*

Postby meneldor » Mon Dec 16, 2019 6:27 pm

Well, i dont know whats been changed in the master in the last sever hours but it fixed it.
Additionally i had to put the include in extern "C":

Code: Select all

extern "C" {
       #include "esp_wifi.h"
}
Please fix it in the repo

Who is online

Users browsing this forum: ankayca, veryDigJJ and 37 guests