Connect 2 ESP32 directly via Ethernet

CloudsEder
Posts: 9
Joined: Fri Feb 04, 2022 7:25 am

Connect 2 ESP32 directly via Ethernet

Postby CloudsEder » Wed Apr 27, 2022 11:53 am

Hello everyone,

as stated in the title, I want to make a direct connection between two esp32 devices via Ethernet. Ethernet runs with the help of W5500 controllers and I am using a crossover cable. This way the status-LEDs of the RJ45-sockets are on and the Ethernet Link is up.

My plan was to give both ESPs static ip addresses. One will have a webserver running from which the other one will get information.

The way I set the static IPs:

Code: Select all

esp_netif_ip_info_t ip_info;
IP4_ADDR(&ip_info.ip, 192, 168, 20, 1);
IP4_ADDR(&ip_info.gw, 192, 168, 20, 1);
IP4_ADDR(&ip_info.netmask, 255, 255, 255, 0);
esp_netif_dhcpc_stop(eth_netif);
esp_netif_set_ip_info(eth_netif, &ip_info);
   	
Of course the other ESP gets a different IP.
I am not very familiar with networking so the gateway address may be an issue?

The way I set up the webserver:

Code: Select all

static httpd_handle_t start_webserver(void)
{
    httpd_handle_t server = NULL;                                
    httpd_config_t config = HTTPD_DEFAULT_CONFIG();                 
    config.uri_match_fn   = httpd_uri_match_wildcard;               
    config.lru_purge_enable = true;                                 
    config.max_uri_handlers = 12;                                                                    

    ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
    if (httpd_start(&server, &config) == ESP_OK) {                  

        ESP_LOGI(TAG, "Registering URI handlers");
        httpd_register_uri_handler(server, &root_uri);              // Root
        ESP_LOGI(TAG, "Started webserver");
        return server;                                              
    }

    ESP_LOGI(TAG, "Error starting server!");
    return NULL;                                                  
}
The way I get the content from http Webserver:

Code: Select all

esp_http_client_config_t config = {
	.url = "http://192.168.20.1",
        .event_handler = _http_event_handler,
        .method = HTTP_METHOD_HEAD
};

esp_http_client_handle_t client = esp_http_client_init(&config);
esp_err_t err = esp_http_client_perform(client);

if (err == ESP_OK) {
        ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d",
                esp_http_client_get_status_code(client),
                esp_http_client_get_content_length(client));
} else {
        ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
}
esp_http_client_cleanup(client);
When trying it this way I get the following error:
E (730557) TRANS_TCP: [sock=54] select() timeout
E (730557) HTTP_CLIENT: Connection failed, sock < 0
E (730557) main: Error perform http request ESP_ERR_HTTP_CONNECT
Via Wifi this wouldn't be much of a problem but I really want to make it work via Ethernet.
Anyone got any idea on how to get this working?
Thanks in advance. Any help would be appreciated

kentavr
Posts: 25
Joined: Fri Nov 08, 2019 2:39 pm

Re: Connect 2 ESP32 directly via Ethernet

Postby kentavr » Wed Apr 27, 2022 5:02 pm

Hi.

I would start with ICMP check, for instance: https://docs.espressif.com/projects/esp ... _echo.html

And if it succeeds, you'll know the Ethernet link works.

CloudsEder
Posts: 9
Joined: Fri Feb 04, 2022 7:25 am

Re: Connect 2 ESP32 directly via Ethernet

Postby CloudsEder » Mon May 02, 2022 11:58 am

I tried it and the ping works and actually that is everything I need.
So thank you very much and have a great day :)

Who is online

Users browsing this forum: No registered users and 114 guests