Connect ESP32 to host pc with ethernet

GlenMorris
Posts: 2
Joined: Thu Dec 22, 2022 2:50 pm

Connect ESP32 to host pc with ethernet

Postby GlenMorris » Thu Dec 22, 2022 3:06 pm

Hello,

I am trying to connect my ESP32 device (OLIMEX ESP32-POE-ISO-EA-IND) to my PC (host machine) with Ethernet. I have looked to examples (eth2ap and tcpclient) and was able to install the ETH driver and also attach the ETH to netif using esp_eth_new_netif_glue().

But I am not able to have a communication (like socket) between my PC and the ESP. Every time I try to have a socket connection with the localhost (host PC) at port 3333, the connection fails, and I am getting an errno 104 (Socket unable to connect: errno 104).

Also, there is no IP address allocated to the ESP board when I connect it to my PC, however the ESP device gets an IP if I connect it to my router. I do not know whether this is an expected behavior, or do I even need an IP address to start a communication.

I would be grateful if you can help me overcome this issue.

Thank you for your help


----------------------Examples Link------------------------------

eth2ap - https://github.com/espressif/esp-idf/tr ... net/eth2ap
tcpclient - https://github.com/espressif/esp-idf/tr ... tcp_client
Last edited by GlenMorris on Fri Dec 23, 2022 8:36 am, edited 1 time in total.

ESP_ondrej
Posts: 211
Joined: Fri May 07, 2021 10:35 am

Re: Connect ESP32 to host pc with ethernet

Postby ESP_ondrej » Thu Dec 22, 2022 3:58 pm

Hi GlenMorris,
But I am not able to have a communication (like socket) between my PC and the ESP. Every time I try to have a socket connection with the localhost (host PC) at port 3333, the connection fails, and I am getting an errno 104 (Socket unable to connect: errno 104).
Localhost (127.0.0.1) is your PC. You need to have specific IP address assigned to your ESP32 device and specific IP address in the same subnet assigned to your PC to be able to communicate.
Also, there is no IP address allocated to the ESP board when I connect it to my PC, however the ESP device gets an IP if I connect it to my router. I do not know whether this is an expected behavior, or do I even need an IP address to start a communication.
You didn't specify which exact example do you use. However, yes, this is expected behavior in most of the cases since in the most of the configurations, the device is configured as DHCP client. Therefore it waits for DHCP server to get some IP address. Routers are usually configured as DHCP servers, hence it gives the address to your device. The PC's are usually configured as DHCP clients by default hence there is no address provided to your ESP device. You have several options:
1) Connect both ESP device and your PC to the router so both devices get the IP address and are going to be in the same subnet.
2) Configure your PC as DHCP server. It is not that hard on Linux OS. Search the internet.
3) Configure static IP address on your PC and static address on the ESP device. See example how https://github.com/espressif/esp-idf/tr ... /static_ip

Ondrej

GlenMorris
Posts: 2
Joined: Thu Dec 22, 2022 2:50 pm

Re: Connect ESP32 to host pc with ethernet

Postby GlenMorris » Tue Jan 03, 2023 9:18 am

Hello,

Thank you for the detailed reply. It took me some time to set up a DHCP server, as I was trying it on Windows, but I have finally able to do it in Linux (was much easier).

Have a nice day :)

Who is online

Users browsing this forum: jialin.yang, Majestic-12 [Bot] and 120 guests