Problems migrating from tcpip_adapter to netif

afcec1
Posts: 23
Joined: Tue Oct 08, 2019 1:48 pm

Problems migrating from tcpip_adapter to netif

Postby afcec1 » Wed Dec 07, 2022 7:03 am

Hi, I developed a custom board based on ESP32-WROOM-32D and our software had been freezed for a while after working successfully for two years. Now I decided to update it to the last ESP-IDF available. I am doing it step by step so first of all I am trying with ESP-IDF 4.1 but unfortunately I am facing an issue that has been consuming a lot of effort recently and so far I have not been able to make it work.

We are using ESP-AZURE (last version available).

I can start Wi-Fí in both, station and ap modes successfully but the problem comes when I disconnect and then connect again, where I am receiving an error and the ESP is restarting. It only happens when the connection to the IoT Hub in Azure has been stablished (TLS). If the board is connected to Wi-Fi but not to the IoT Hub, the connection/disconnection process works just fine.

When I connect to Wi-Fi and then to the IoT Hub, I can see an error: "Error from SSL_write: 0" although then it seems to work just fine and data is beeing sent and received correctly.

When I connect I do:

main.c:

esp_netif_init();
esp_event_loop_create_default();

wifi_comm.c:

Connect function

netif_station = 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_wifi_get_config(ESP_IF_WIFI_STA, &wifi_config));
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));


ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());

Disconnect function

DisconnectIotHub(); // two steps --> 1. IoTHubDeviceClient_LL_Destroy(iotHubClientHandle); 2. IoTHub_Deinit();
esp_wifi_disconnect();
esp_wifi_stop();
esp_wifi_deinit();
esp_wifi_clear_default_wifi_driver_and_handlers(netif_station);
esp_netif_destroy(netif_station);

When I disconnect, I can see the following error:

E (314671) esp-tls-mbedtls: write error :-78:
Info: Error from SSL_write: -78

And then if I try to connect again (Wi-Fi and IoT Hub):

Error: Time:Wed Dec 7 06:41:49 2022 File:C:/...../esp-azure/port/src/tlsio_esp_tls.c Func:tlsio_esp_tls_destroy Line:152 tlsio_esp_tls_destroy called while not in TLSIO_STATE_CLOSED.
Guru Meditation Error: Core 0 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x00000000 PS : 0x00060b30 A0 : 0x8010ccf0 A1 : 0x3ffd8050
A2 : 0x3ffc9aa8 A3 : 0x3ffc9476 A4 : 0x0000005a A5 : 0x3ffc93e4
A6 : 0x0000be1a A7 : 0x00000000 A8 : 0x8019c6c8 A9 : 0x00000064
A10 : 0x00000000 A11 : 0x3ffc9476 A12 : 0x0000005a A13 : 0x3ffc93e4
A14 : 0x3ffc8ad4 A15 : 0xffffffff SAR : 0x00000010 EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff

ELF file SHA256: f4248fb42d819f8f

Backtrace: 0xfffffffd:0x3ffd8050 |<-CORRUPTED

Rebooting...

It seems to be a problem with TLS and not related to ESP-IDF, but I am completly lost... ESP-AZURE repo seems to be dead, with no updates and no solutions to the open issues so I hope someone here can help. This same procedure worked just fine with ESP-IDF 4.0.1

Thanks in advance

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 377 guests