Chapter 4. API Guides
Another thing deserves our attention is that the default behavior of LwIP is to abort all TCP socket connections on
receiving the disconnect. Most of time it is not a problem. However, for some special application, this may not be
what they want, consider following scenarios:
• The application creates a TCP connection to maintain the application-level keep-alive data that is sent out every
60 seconds.
• Due to certain reasons, the Wi-Fi connection is cut off, and the
According to the current implementation, all TCP connections will be removed and the keep-alive socket will
be in a wrong status. However, since the application designer believes that the network layer should NOT care
about this error at the Wi-Fi layer, the application does not close the socket.
• Five seconds later, the Wi-Fi connection is restored because
cation event callback function. Moreover, the station connects to the same AP and gets the same IPV4
address as before.
• Sixty seconds later, when the application sends out data with the keep-alive socket, the socket returns an error
and the application closes the socket and re-creates it when necessary.
In above scenarios, ideally, the application sockets and the network layer should not be affected, since the Wi-Fi
connection only fails temporarily and recovers very quickly. The application can enable "Keep TCP connections
when IP changed"via LwIP menuconfig.
IP_EVENT_STA_GOT_IP
This event arises when the DHCP client successfully gets the IPV4 address from the DHCP server, or when the IPV4
address is changed. The event means that everything is ready and the application can begin its tasks (e.g., creating
sockets).
The IPV4 may be changed because of the following reasons:
• The DHCP client fails to renew/rebind the IPV4 address, and the station's IPV4 is reset to 0.
• The DHCP client rebinds to a different address.
• The static-configured IPV4 address is changed.
Whether the IPV4 address is changed or NOT is indicated by field ip_change of ip_event_got_ip_t.
The socket is based on the IPV4 address, which means that, if the IPV4 changes, all sockets relating to this IPV4 will
become abnormal. Upon receiving this event, the application needs to close all sockets and recreate the application
when the IPV4 changes to a valid one.
IP_EVENT_GOT_IP6
This event arises when the IPV6 SLAAC support auto-configures an address for the ESP32-S2, or when this address
changes. The event means that everything is ready and the application can begin its tasks (e.g., creating sockets).
IP_STA_LOST_IP
This event arises when the IPV4 address become invalid.
IP_STA_LOST_IP doesn' t arise immediately after the Wi-Fi disconnects, instead it starts an IPV4 address lost timer,
if the IPV4 address is got before ip lost timer expires, IP_EVENT_STA_LOST_IP doesn't happen. Otherwise, the
event arises when IPV4 address lost timer expires.
Generally the application don't need to care about this event, it is just a debug event to let the application know that
the IPV4 address is lost.
WIFI_EVENT_AP_START
Similar to WIFI_EVENT_STA_START.
Espressif Systems
esp_wifi_connect()
1517
Submit Document Feedback
WIFI_EVENT_STA_DISCONNECTED
is raised.
is called in the appli-
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?