UDP broadcasting over Station+SoftAP

beman.ghison
Posts: 1
Joined: Mon Jan 02, 2023 12:47 pm

UDP broadcasting over Station+SoftAP

Postby beman.ghison » Mon Jan 02, 2023 1:48 pm

Hi,

I have a particular problem. I have two ESP32-S2 devices, one configured as Station + SoftAP
and the other is connected to the first one (as a station).

both devices are set to send and receive UDP broadcast packets to each other on the same port. and both of them work fine. In another word, both can send successfully, and both can receive the other packet successfully either.

BUT, if the first device (as a station) gets connected to a third access-point, then it could no longer send UDP packets to its SoftAP interface! it seems the device just sends the UDP broadcasting packet to a third AP, not to stations that get connected to it.

The question is, how can I force it to send UDP broadcast packets to both Station and SoftAP interfaces

Using ESP-IDF 4.3

These simple diagrams may be helpful,

The below scenario works without any problem:

Code: Select all

+--------------------------+                            +---------------------+
| [DEVICE: 1]              |                            | [DEVICE: 2]         |
| SoftAP (Connected)       | ---- UDP packets (OK) ---> | Station (Connected) |
| Station  (NOT CONNECTED) | <--- UDP packets (OK) ---- |                     |
+--------------------------+                            +---------------------+
But this scenario get into problem:

Code: Select all

+--------------+           +-----------------------+                        +---------------------+
| Another      |           | [DEVICE: 1]           |                        | [DEVICE: 2]         |
| Access-Point | <-------> | SoftAP (Connected)->  | ---- UDP (NOT OK) ---> | Station (Connected) |
|              |           | <-Station (CONNECTED) | <--- UDP (OK) -------- |                     |
+--------------+           +-----------------------+                        +---------------------+
the source code gets simplified to something like this for better understanding. (the original source code has error handling and other functionalities that are irrelevant.
  1.  
  2. source.sin_addr.s_addr = htonl(INADDR_ANY);
  3. source.sin_family = AF_INET;
  4. source.sin_port = htons(port);
  5.  
  6. dest.sin_addr.s_addr = htonl(INADDR_BROADCAST);
  7. dest.sin_family = AF_INET;
  8. dest.sin_port = htons(port);
  9.    
  10. sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
  11. bind(sock, (struct sockaddr *)&source, sizeof(source))
  12. ....
  13. recvfrom(sock, rx_buffer, sizeof(rx_buffer) - 1, MSG_DONTWAIT,
  14.         (struct sockaddr *)&source_addr, &socklen);
  15. ....
  16. sendto(sock, payload, strlen(payload), 0,
  17.         (struct sockaddr *)&dest, sizeof(dest));        
  18.        
  19.        

Who is online

Users browsing this forum: jialin.yang and 118 guests