How to migrate from tcpip_adapter_* to esp_netif_`*
How to migrate from tcpip_adapter_* to esp_netif_`*
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
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
Re: How to migrate from tcpip_adapter_* to esp_netif_`*
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
using the version 4 release - so has anyone come across this ?
TIA Danny
-
- Posts: 74
- Joined: Wed Oct 23, 2019 1:49 am
Re: How to migrate from tcpip_adapter_* to esp_netif_`*
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.
Re: How to migrate from tcpip_adapter_* to esp_netif_`*
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:
I declared it as:
then initialized it:
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;
^~~~~~~~~~~~~
Code: Select all
static esp_netif_t * sta_netif = NULL;
Code: Select all
sta_netif = esp_netif_create_default_wifi_sta();
Re: How to migrate from tcpip_adapter_* to esp_netif_`*
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: This component is used in my custom component which has CMakeLists.txt file where i tested with PRIV_REQUIRES and REQUIRES:
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()'
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 . )
Re: How to migrate from tcpip_adapter_* to esp_netif_`*
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.
Re: How to migrate from tcpip_adapter_* to esp_netif_`*
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":
Please fix it in the repo
Additionally i had to put the include in extern "C":
Code: Select all
extern "C" {
#include "esp_wifi.h"
}
Re: How to migrate from tcpip_adapter_* to esp_netif_`*
Just started to look at the espidf framework.
I am on windows VSCode.
Platformio.ini
I was using their example at https://docs.platformio.org/en/latest/t ... lysis.html
I will include my current code, but the bottom line when I used tcpip_adapter_init() it works and if I use esp_netif_init it can not get an IP. The log shows a connect but my device after timeout says it can not obtain IP.
This may not be a bug but my limited understanding of the framework and wifi library.
I saw the depreciation message, so as part of my learning I was going to fix it. I assumed it was just a matter of switching names for functions. If I understand that these two functions only handle the hardware layer, I would think the upper layers (DHCP) would have been the same, correct?
Here is a log of sucssufull (tcpip_adapter_init()) connect and DHCP assigned IP.
Hre is a log of unsucssufull (esp_netif_init()) connect and DHCP assigned IP.
The only difference is unremarked the tcpip_adaper vs esp_netif
Here is the code:
I am on windows VSCode.
Platformio.ini
Code: Select all
[env:esp32doit-devkit-v1]
platform = espressif32
board = wemosbat
framework = espidf
upload_port = com9
monitor_speed=115200
monitor_port = com9
I will include my current code, but the bottom line when I used tcpip_adapter_init() it works and if I use esp_netif_init it can not get an IP. The log shows a connect but my device after timeout says it can not obtain IP.
This may not be a bug but my limited understanding of the framework and wifi library.
I saw the depreciation message, so as part of my learning I was going to fix it. I assumed it was just a matter of switching names for functions. If I understand that these two functions only handle the hardware layer, I would think the upper layers (DHCP) would have been the same, correct?
Here is a log of sucssufull (tcpip_adapter_init()) connect and DHCP assigned IP.
Code: Select all
I (18529) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (18529) wifi:station: a0:cc:2b:1c:4f:8e join, AID=1, bgn, 20
␛[0;32mI (18589) wifi softAP: station a0:cc:2b:1c:4f:8e join, AID=1␛[0m
W (18769) wifi:<ba-add>idx:4 (ifx:1, a0:cc:2b:1c:4f:8e), tid:6, ssn:0, winSize:64
␛[0;32mI (19179) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.2␛[0m
I (386639) wifi:station: a0:cc:2b:1c:4f:8e leave, AID = 1, bss_flags is 658547, bss:0x3ffba33c
I (386639) wifi:new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
W (386639) wifi:<ba-del>idx
␛[0;32mI (386639) wifi softAP: station a0:cc:2b:1c:4f:8e leave, AID=1␛[0m
Code: Select all
I (19329) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (19339) wifi:station: a0:cc:2b:1c:4f:8e join, AID=1, bgn, 20
␛[0;32mI (19419) wifi softAP: station a0:cc:2b:1c:4f:8e join, AID=1␛[0m
W (19569) wifi:<ba-add>idx:4 (ifx:1, a0:cc:2b:1c:4f:8e), tid:6, ssn:0, winSize:64
I (55739) wifi:station: a0:cc:2b:1c:4f:8e leave, AID = 1, bss_flags is 658547, bss:0x3ffba33c
Here is the code:
Code: Select all
/* WiFi softAP Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#define EXAMPLE_ESP_WIFI_SSID "PaulTest"
#define EXAMPLE_ESP_WIFI_PASS "abcd1234"
#define EXAMPLE_MAX_STA_CONN (3)
static const char *TAG = "wifi softAP";
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
if (event_id == WIFI_EVENT_AP_STACONNECTED) {
wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
ESP_LOGI(TAG, "station "MACSTR" join, AID=%d",
MAC2STR(event->mac), event->aid);
} else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*) event_data;
ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d",
MAC2STR(event->mac), event->aid);
}
}
void wifi_init_softap()
{
//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));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
wifi_config_t wifi_config = {
.ap = {
.ssid = EXAMPLE_ESP_WIFI_SSID,
.ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID),
.password = EXAMPLE_ESP_WIFI_PASS,
.max_connection = EXAMPLE_MAX_STA_CONN,
.authmode = WIFI_AUTH_WPA_WPA2_PSK
},
};
if (strlen(EXAMPLE_ESP_WIFI_PASS) == 0) {
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
}
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_LOGI(TAG, "wifi_init_softap finished. SSID:%s password:%s",
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
}
void app_main()
{
//Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "ESP_WIFI_MODE_AP");
wifi_init_softap();
}
Who is online
Users browsing this forum: Bing [Bot] and 168 guests