my ESP32 is operating in SoftAP mode, which obtains the IP 192.168.4.1 in the AP. DHCP is now used to assign IPs to clients. This works quite well, but unfortunately, IP assignment depends on the order in which clients connect. I want to change this and assign static IPs to various clients based on their MAC addresses.
For this purpose, I listen for the WIFI_EVENT_AP_STACONNECTED event and attempt to assign the IPs in this way:
Code: Select all
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_STACONNECTED)
{
ESP_LOGI(TAG, "Station connected");
wifi_event_ap_staconnected_t *event = (wifi_event_ap_staconnected_t *)event_data;
handleNewClient(event->mac);
}
Code: Select all
esp_netif_ip_info_t ipInfo_ap_new;
ipInfo_ap_new.ip.addr = ipaddr_addr("192.168.4.20");
ipInfo_ap_new.gw.addr = ipaddr_addr("192.168.4.20");
ipInfo_ap_new.netmask.addr = ipaddr_addr("255.255.255.0");
ESP_ERROR_CHECK(esp_netif_dhcps_stop(wifiAP));
esp_netif_set_ip_info(wifiAP, &ipInfo_ap_new);
ESP_ERROR_CHECK(esp_netif_dhcps_start(wifiAP));
I have already tried to keep the gateway address the same:
Code: Select all
ipInfo_ap_new.ip.addr = ipaddr_addr("192.168.4.20");
ipInfo_ap_new.gw.addr = ipaddr_addr("192.168.4.1");
Thank you for your help.
Kind regards,
Danny