esp32 eterneth - auto IP- static IP
Posted: Wed Dec 13, 2023 8:53 am
Hi
I have problem with DHCPc and auto IP. I want to set my defaul IP( e.g 192.168.1.200) when DHCP serwer not respond.
Now i get e.g. 169.254.92.229, how tu set my own IP when dhcp tries is out?
My code:
I have problem with DHCPc and auto IP. I want to set my defaul IP( e.g 192.168.1.200) when DHCP serwer not respond.
Now i get e.g. 169.254.92.229, how tu set my own IP when dhcp tries is out?
My code:
Code: Select all
esp_netif_dhcpc_stop(eth_netif);
if (esp_netif_dhcpc_stop(eth_netif) != ESP_OK) {
ESP_LOGE(TAG, "Failed to stop dhcp client");
return;
}
esp_netif_ip_info_t info_t;
memset(&info_t, 0, sizeof(esp_netif_ip_info_t));
info_t.ip.addr=eeprom_nvs_read_u32(EP_netIp);
info_t.gw.addr=eeprom_nvs_read_u32(EP_netGateway);
info_t.netmask.addr=eeprom_nvs_read_u32(EP_netMask);
if (esp_netif_set_ip_info(eth_netif, &info_t) != ESP_OK) {
ESP_LOGE(TAG, "Failed to set ip info");
return;
}
esp_netif_dns_info_t dns;
dns.ip.type=IPADDR_TYPE_V4;
dns.ip.u_addr.ip4.addr=eeprom_nvs_read_u32(EP_netDns1);
esp_netif_set_dns_info(eth_netif, ESP_NETIF_DNS_MAIN, &dns);
dns.ip.u_addr.ip4.addr=eeprom_nvs_read_u32(EP_netDns2);
esp_netif_set_dns_info(eth_netif, ESP_NETIF_DNS_BACKUP, &dns);
esp_netif_dhcpc_start(eth_netif);