Change ethernet IP address?

Melbourne
Posts: 9
Joined: Mon May 23, 2022 1:20 am

Change ethernet IP address?

Postby Melbourne » Sat Apr 22, 2023 4:53 am

I am trying to change (not 'set') the IP address on the ethernet connection, like this:

Code: Select all

esp_err_t dnet_set_addr(char *str) {
    esp_netif_ip_info_t eth_info = {0};

    if (dnet_str2ip4(&eth_info.ip, str)) {
		return  esp_netif_set_ip_info(eth_get_netif(), &eth_info);
	} else {
		return -1;
	};	
}
because this: https://docs.espressif.com/projects/esp ... netif.html
says "If the interface is up, the new IP information is set directly in the TCP/IP stack." and "Calling this interface for may generate a SYSTEM_EVENT_STA_GOT_IP or SYSTEM_EVENT_ETH_GOT_IP event."

But the IP address is not changed (the IP address remains the same), and there is no EVENT (even after I search for SYSTEM_EVENT_ETH_GOT_IP documentation and realize that the name changed several versions ago), and there is no error (esp_netif_set_ip_info returns ESP_OK)

What am I doing wrong?

MicroController
Posts: 1696
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Change ethernet IP address?

Postby MicroController » Sat Apr 22, 2023 8:05 pm

It looks like you'd need to pass in a valid subnet mask and gateway together with the new local IP address to trigger the event.
Try esp_netif_get_ip_info(eth_get_netif(), &eth_info); to initialize the structure with the current sn+gw before putting the new IP address in.

Who is online

Users browsing this forum: Baidu [Spider], iParcelBox and 74 guests