Hi everybody,
I'm using ESP32-WROVER-2 module.
Interfaces that are configured:
Ethernet.
Wifi AP or Wifi client.
Protocols started:
Socket UDP.
Webserver with some websockets.
On one hand, I have UDP packets going out over ethernet to a local PC.
At the same time, I started a web server with some websockets. I can configure the wifi of the ESP32 as AP mode or as Client mode to serve a http page.
When I start wifi as AP mode, everything works fine. UDP packets goes out over ethernet and web server serves the page over wifi as expected. Instead, if I start Wifi as client mode, as soon as the router assigns IP to esp32, UDP packets stop leaving ethernet.
Is any special socket configuration necessary for it to work when wifi is enabled as a client?
Thank you so much,
Asier.
UDP packet stops going out over ethernet
-
- Posts: 1707
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: UDP packet stops going out over ethernet
You can try to explicitly bind the UDP socket to the ethernet interface via setsockopt(..., SO_BINDTODEVICE,...), like in this example.
Re: UDP packet stops going out over ethernet
I bind sock to address but no way.
Furthermore, I do:
int err = sendto(sock, &udp_packet, sizeof(udp_packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
where address is explicitly passed to the function.
¿Why udp packet are going out when Wifi is in AP mode or when it is just disabled and not when it is client?
Thank you,
ASier.
Furthermore, I do:
int err = sendto(sock, &udp_packet, sizeof(udp_packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
where address is explicitly passed to the function.
¿Why udp packet are going out when Wifi is in AP mode or when it is just disabled and not when it is client?
Thank you,
ASier.
-
- Posts: 1707
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: UDP packet stops going out over ethernet
I'd guess that either a) the UDP socket doesn't survive the reconfiguration of the network environment, or b) the UDP packets still "go out", but via WiFi once WiFi is connected.¿Why udp packet are going out when Wifi is in AP mode or when it is just disabled and not when it is client?
Re: UDP packet stops going out over ethernet
It seems to be otion b) that you said, because only when the router assigns an IP does it start to fail. Is there any way or example to redirect those udp packets to the ethernet interface ?
I've tried to bind but it does not work:
esp_netif_ip_info_t ip;
memset(&ip, 0, sizeof(esp_netif_ip_info_t));
ESP_ERROR_CHECK(esp_netif_get_ip_info(eth_handle, &ip));
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(PORT);
addr.sin_addr.s_addr = ip.ip.addr;
int retb = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
Best regards,
ASier.
I've tried to bind but it does not work:
esp_netif_ip_info_t ip;
memset(&ip, 0, sizeof(esp_netif_ip_info_t));
ESP_ERROR_CHECK(esp_netif_get_ip_info(eth_handle, &ip));
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(PORT);
addr.sin_addr.s_addr = ip.ip.addr;
int retb = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
Best regards,
ASier.
-
- Posts: 1707
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: UDP packet stops going out over ethernet
You do read the answers people write to your questions, right?Is there any way or example to redirect those udp packets to the ethernet interface ?
MicroController wrote: ↑Tue Sep 19, 2023 4:54 pmYou can try to explicitly bind the UDP socket to the ethernet interface via setsockopt(..., SO_BINDTODEVICE,...), like in this example.
Re: UDP packet stops going out over ethernet
The issue was here:
esp_netif_ip_info_t ip;
memset(&ip, 0, sizeof(esp_netif_ip_info_t));
ESP_ERROR_CHECK(esp_netif_get_ip_info(eth_netif, &ip));
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(PORT);
addr.sin_addr.s_addr = ip.ip.addr;
int retb = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
I was passing wrong netif, so I was binding an incorrect address.
Thank you,
ASier.
esp_netif_ip_info_t ip;
memset(&ip, 0, sizeof(esp_netif_ip_info_t));
ESP_ERROR_CHECK(esp_netif_get_ip_info(eth_netif, &ip));
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(PORT);
addr.sin_addr.s_addr = ip.ip.addr;
int retb = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
I was passing wrong netif, so I was binding an incorrect address.
Thank you,
ASier.
-
- Posts: 1707
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: UDP packet stops going out over ethernet
Glad you got it working
Who is online
Users browsing this forum: No registered users and 101 guests