Hello,
I'm trying to obtain an IP address from a DHCP server using the ethernet example program found on Github. The source code is in the esp-idf folder, under examples/ethernet, or it can be found here:
https://github.com/espressif/esp-idf/tr ... t/ethernet
The hardware configuration I am using is a breakout board circuit based off of the schematic for the Waveshare LAN8720 ETH Board, found here:
http://www.waveshare.com/w/upload/0/08/ ... ematic.pdf
The README.md file explains that the program is supposed obtain a DHCP lease so you can ping the the IP address that was given. However, when I run the program from within the terminal window, the IP address, gateway and subnet mask is repeatedly printed as all zeros. I'm not sure where in the program the ESP is supposed to request or obtain an IP address.
I was wondering if anyone else has had a similar problem, or has any idea how to go about fixing this. Could it be a hardware, or a software issue?
Thanks
Cannot obtain IP Address using Ethernet Example
Re: Cannot obtain IP Address using Ethernet Example
I coincidentally started working on the same thing yesterday. I got the same issue using the ethernet example but on a custom board I made. I checked the pin out with what was written in the readme file and everything seems in order. I even tried writing my own custom code which assigns a static IP. When I print this IP, it outputs the one I set but I still can't ping it over the network. So I assume it hasn't received a DHCP lease from the router. You can find my code below, maybe it will help someone. Just to be clear, I have not solved this issue yet.
Code: Select all
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); // Don't run a DHCP client
inet_pton(AF_INET, &ip[0], &ipInfo.ip);
inet_pton(AF_INET, &dgw[0], &ipInfo.gw);
inet_pton(AF_INET, &snm[0], &ipInfo.netmask);
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
eth_config_t config = DEFAULT_ETHERNET_PHY_CONFIG;
/* Set the PHY address in the example configuration */
config.phy_addr = CONFIG_PHY_ADDRESS;
config.gpio_config = eth_gpio_config_rmii;
config.tcpip_input = tcpip_adapter_eth_input;
config.phy_power_enable = phy_device_power_enable_via_gpio;
err = esp_eth_init(&config);
if (err == ESP_OK)
{
ESP_LOGI(TAG, "networkConnect: Successfully configured ethernet");
esp_eth_enable();
if (err == ESP_OK)
{
ESP_LOGI(TAG, "networkConnect: Successfully enabled ethernet");
ESP_LOGI(TAG, "ETHIP:"IPSTR, IP2STR(&ipInfo.ip));
ESP_LOGI(TAG, "ETHPMASK:"IPSTR, IP2STR(&ipInfo.netmask));
ESP_LOGI(TAG, "ETHPGW:"IPSTR, IP2STR(&ipInfo.gw));
}
else
{
ESP_LOGI(TAG, "networkConnect: Failed to enable ethernet");
}
}
else
{
ESP_LOGI(TAG, "networkConnect: Failed to configure ethernet");
}
Re: Cannot obtain IP Address using Ethernet Example
@aaquilina: In your code you use TCPIP_ADAPTER_IF_STA which is the Wifi Station adapter. To use the Ethernet adapter use TCPIP_ADAPTER_IF_ETH.
Re: Cannot obtain IP Address using Ethernet Example
In addition I found that a bug in tcpip_adapter_dhcpc_stop() which prevents setting a static IP.
Refer to this pull request which you have to apply to your esp-idf: https://github.com/espressif/esp-idf/pull/657
Refer to this pull request which you have to apply to your esp-idf: https://github.com/espressif/esp-idf/pull/657
Re: Cannot obtain IP Address using Ethernet Example
@hwmaier Thanks for that! So I found out what was causing me not to be able to acquire an IP on the example as well. My RXD0 and RXD1 were swapped accidentally . So it acquired the IP after swapping them .
Now I'll try your fix for the static IP now and get back to you
@paul1419 Check this blog post and make sure your wiring and all is correct cause he's using the same exact breakout board.
https://sautter.com/blog/ethernet-on-es ... g-lan8720/
Now I'll try your fix for the static IP now and get back to you
@paul1419 Check this blog post and make sure your wiring and all is correct cause he's using the same exact breakout board.
https://sautter.com/blog/ethernet-on-es ... g-lan8720/
Re: Cannot obtain IP Address using Ethernet Example
@hwmaier I've applied your fix to the component but for some reason I still can't ping my static IP. Have you managed to work with a static IP? This is my new adjusted code:
Code: Select all
else
{
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH); // Don't run a DHCP client
inet_pton(AF_INET, &ip[0], &ipInfo.ip);
inet_pton(AF_INET, &dgw[0], &ipInfo.gw);
inet_pton(AF_INET, &snm[0], &ipInfo.netmask);
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_ETH, &ipInfo);
eth_config_t config = DEFAULT_ETHERNET_PHY_CONFIG;
/* Set the PHY address in the example configuration */
config.phy_addr = CONFIG_PHY_ADDRESS;
config.gpio_config = eth_gpio_config_rmii;
config.tcpip_input = tcpip_adapter_eth_input;
config.phy_power_enable = phy_device_power_enable_via_gpio;
err = esp_eth_init(&config);
if (err == ESP_OK)
{
ESP_LOGI(TAG, "networkConnect: Successfully configured ethernet");
esp_eth_enable();
if (err == ESP_OK)
{
ESP_LOGI(TAG, "networkConnect: Successfully enabled ethernet");
ESP_LOGI(TAG, "ETHIP:"IPSTR, IP2STR(&ipInfo.ip));
ESP_LOGI(TAG, "ETHPMASK:"IPSTR, IP2STR(&ipInfo.netmask));
ESP_LOGI(TAG, "ETHPGW:"IPSTR, IP2STR(&ipInfo.gw));
}
else
{
ESP_LOGI(TAG, "networkConnect: Failed to enable ethernet");
}
}
else
{
ESP_LOGI(TAG, "networkConnect: Failed to configure ethernet");
}
}
Re: Cannot obtain IP Address using Ethernet Example
I found out what was ruining my link! I was initialising the serial interface as well and even though im not using hardware flow control, I was still calling uart_set_pin for the RTS and CTS which were using GPIO_NUM_18 and GPIO_NUM_19. These pins are used by the MDIO interface and TXD0 for ethernet. Once i disabled those pins, everything worked fine!
Thanks again @hwmaier
Thanks again @hwmaier
Re: Cannot obtain IP Address using Ethernet Example
This is my working static Ethernet initialisation (using a LAN8720 PHY and the before mentioned tcpip_adapter_dhcpc_stop() fix):
Code: Select all
#define IP_DEFAULT_ADDRESS "192.168.0.10"
#define IP_DEFAULT_NETMASK "255.255.255.0"
#define IP_DEFAULT_GATEWAY "192.168.0.1"
tcpip_adapter_init();
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH); // Don't run a DHCP client
tcpip_adapter_ip_info_t ipInfo;
ip4addr_aton(IP_DEFAULT_ADDRESS, &ipInfo.ip);
ip4addr_aton(IP_DEFAULT_GATEWAY, &ipInfo.gw);
ip4addr_aton(IP_DEFAULT_NETMASK, &ipInfo.netmask);
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_ETH, &ipInfo));
ESP_ERROR_CHECK(esp_event_loop_init(NULL, NULL));
eth_config_t phyConfig = DEFAULT_ETHERNET_PHY_CONFIG;
phyConfig.phy_addr = CONFIG_PHY_ADDRESS;
phyConfig.gpio_config = eth_gpio_config_rmii;
phyConfig.tcpip_input = tcpip_adapter_eth_input;
ESP_ERROR_CHECK(esp_eth_init(&phyConfig));
ESP_ERROR_CHECK(esp_eth_enable());
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ipInfo));
printf("main: Network started on "IPSTR"\n", IP2STR(&ipInfo.ip));
Who is online
Users browsing this forum: Bing [Bot] and 62 guests