I use the official sample LWIP / TCP / TLS example:
https://github.com/espressif/esp-idf/tr ... tcp_client
https://github.com/espressif/esp-idf/tr ... ps_mbedtls
All work fine, so we need catch WiFi events -> ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &MyEventFunctionCallback, NULL));
If WiFi Connected/Disconnect -> if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)...
What about Socket Connect/Disconnect events ?
If we create a persistent socket (long during connection), we get no event if the server close the socket for example!.
Please, How to catch Socket Connect/Disconnect events ?
Thank you,
How to catch LWIP TCP/IP Events
-
- Posts: 9759
- Joined: Thu Nov 26, 2015 4:08 am
Re: How to catch LWIP TCP/IP Events
There are no such events. You can notice that your socket is closed because recv() will return with a return value of 0; send() will return an error if the socket is entirely lost on the other end.
Re: How to catch LWIP TCP/IP Events
I got it, I was thinking to use a scheduled task to check the return of send(), but this will create conflicts in our server, so maybe re-connect if send() return error will be a better solution.
Thank you so much ESP_Sprite.
Sincerely,
Thank you so much ESP_Sprite.
Sincerely,
Re: How to catch LWIP TCP/IP Events
CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is disabled by default. This disables the default lwIP behaviour of keeping TCP connections open if an interface IP changes, in case the interface IP changes back (for example, if an interface connection goes down and comes back up). Enable this option to keep TCP connections open in this case, until they time out normally. This may increase the number of sockets in use if a network interface goes down temporarily.
Some common lwIP “app” APIs are supported indirectly by ESP-IDF:
DHCP Server & Client are supported indirectly via the ESP-NETIF functionality
Simple Network Time Protocol (SNTP) is supported via the lwip/include/apps/sntp/sntp.h lwip/lwip/src/include/lwip/apps/sntp.h functions (DQ Feedback see also SNTP Time Synchronization)
ICMP Ping is supported using a variation on the lwIP ping API. See ICMP Echo.
NetBIOS lookup is available using the standard lwIP API. protocols/http_server/restful_server has an option to demonstrate using NetBIOS to look up a host on the LAN.
mDNS uses a different implementation to the lwIP default mDNS (see mDNS Service), but lwIP can look up mDNS hosts using standard APIs such as gethostbyname() and the convention hostname.local, provided the CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES setting is enabled.
Some common lwIP “app” APIs are supported indirectly by ESP-IDF:
DHCP Server & Client are supported indirectly via the ESP-NETIF functionality
Simple Network Time Protocol (SNTP) is supported via the lwip/include/apps/sntp/sntp.h lwip/lwip/src/include/lwip/apps/sntp.h functions (DQ Feedback see also SNTP Time Synchronization)
ICMP Ping is supported using a variation on the lwIP ping API. See ICMP Echo.
NetBIOS lookup is available using the standard lwIP API. protocols/http_server/restful_server has an option to demonstrate using NetBIOS to look up a host on the LAN.
mDNS uses a different implementation to the lwIP default mDNS (see mDNS Service), but lwIP can look up mDNS hosts using standard APIs such as gethostbyname() and the convention hostname.local, provided the CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES setting is enabled.
Last edited by jollayc on Thu Apr 02, 2020 12:38 pm, edited 1 time in total.
Re: How to catch LWIP TCP/IP Events
Thank you Jollayc for those information, I will use CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES to reduce losing socket connection's.
Who is online
Users browsing this forum: No registered users and 105 guests