How to set multiple static IP addresses in ESP32 Station mode?
Posted: Tue May 21, 2024 3:43 am
I can set a static IP address according to the following document.
https://docs.espressif.com/projects/esp ... station-ip
I now want to set multiple static IP addresses, do not know how to achieve?
I tried to do this below, but only the last IP will work.
https://docs.espressif.com/projects/esp ... station-ip
I now want to set multiple static IP addresses, do not know how to achieve?
I tried to do this below, but only the last IP will work.
- esp_netif_t *esp_netif = esp_netif_create_default_wifi_sta();
- if (esp_netif_dhcpc_stop(esp_netif) != ESP_OK)
- {
- ESP_LOGE(TAG, "dhcpc stop failed");
- return;
- }
- esp_netif_ip_info_t ip;
- memset(&ip, 0 , sizeof(esp_netif_ip_info_t));
- ip.ip.addr = ipaddr_addr("10.0.0.111");
- ip.netmask.addr = ipaddr_addr("255.255.255.0");
- ip.gw.addr = ipaddr_addr("10.0.0.1");
- if (esp_netif_set_ip_info(esp_netif, &ip) != ESP_OK) {
- ESP_LOGE(TAG, "Failed to set ip info");
- return;
- }
- memset(&ip, 0 , sizeof(esp_netif_ip_info_t));
- ip.ip.addr = ipaddr_addr("192.168.0.111");
- ip.netmask.addr = ipaddr_addr("255.255.255.0");
- ip.gw.addr = ipaddr_addr("192.168.0.1");
- if (esp_netif_set_ip_info(esp_netif, &ip) != ESP_OK) {
- ESP_LOGE(TAG, "Failed to set ip info");
- return;
- }