ESP32 answers DHCP request with NAK
Posted: Mon Feb 26, 2018 6:14 pm
Hello everyone,
Currently I am setting up an ESP32 to act as a TCP server to which clients can connect in order to retrieve some information. I have configured my ESP32 in softAP mode, with an assigned static IP address and with a listening server socket. Below is the code for configuring the network interface:
On the client side, I have setup a Python script (running on a Windows computer) which creates a client socket that connects to the ESP32's server socket through its known network interface static IP address.
I am able to successfully establish a connection and transmit data from the ESP32 to the Python client; however, I can only maintain this connection for an hour or so. After a while, the client issues a DHCP Request to which the ESP32 answers with a NAK, from what I've seen using Wireshark. After that, the ESP32 continues to send data, but the client never acknowledges such transmission. Below is a screenshot of the Wireshark capture.
I do not quite understand why the client is sending the DHCP request while the transmission is already in place after a while. Also, I do not understand why the ESP32 replies with a NAK.
My first approach in dealing with this issue was to stop the DHCP server on the ESP32 by calling this function:
Doing this has solved the problem, considering that the client no longer issued DHCP requests. However, this meant I had to set the IP address of the WiFi interface of my Windows computer manually (to be something like 192.168.x.x) which is not a viable solution for customer deployment. The IP address should be set automatically as it is the case for when a DHCP server is running.
As such, I was wondering if there are any other configurations I could run on the ESP32 to help dealing with this problem. Any ideas? Thanks!
Currently I am setting up an ESP32 to act as a TCP server to which clients can connect in order to retrieve some information. I have configured my ESP32 in softAP mode, with an assigned static IP address and with a listening server socket. Below is the code for configuring the network interface:
Code: Select all
tcpip_adapter_init();
// assign a static IP to the network interface
tcpip_adapter_ip_info_t ip_info;
memset(&ip_info, 0, sizeof(ip_info));
IP4_ADDR(&ip_info.ip, 192, 168, 1, 1);
IP4_ADDR(&ip_info.gw, 192, 168, 1, 1); // ESP32 acts as router, so GW address will be its own address
IP4_ADDR(&ip_info.netmask, 255, 255, 255, 0);
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &ip_info));
ESP_ERROR_CHECK(esp_event_loop_init(esp32_wifi_eventHandler, NULL));
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
wifi_config_t apConfig = {
.ap = {
.ssid_len=0,\
.password="",
.channel=0,
.authmode=WIFI_AUTH_OPEN,
.ssid_hidden=0,
.max_connection=4,
.beacon_interval=100
}
};
strcpy((char *)apConfig.ap.ssid, ssid);
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &apConfig));
ESP_ERROR_CHECK(esp_wifi_start());
I am able to successfully establish a connection and transmit data from the ESP32 to the Python client; however, I can only maintain this connection for an hour or so. After a while, the client issues a DHCP Request to which the ESP32 answers with a NAK, from what I've seen using Wireshark. After that, the ESP32 continues to send data, but the client never acknowledges such transmission. Below is a screenshot of the Wireshark capture.
I do not quite understand why the client is sending the DHCP request while the transmission is already in place after a while. Also, I do not understand why the ESP32 replies with a NAK.
My first approach in dealing with this issue was to stop the DHCP server on the ESP32 by calling this function:
Code: Select all
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP)
As such, I was wondering if there are any other configurations I could run on the ESP32 to help dealing with this problem. Any ideas? Thanks!