简体   繁体   中英

UDP client doesn't broadcast message on esp32

So I am trying to send packets via UDP as a broadcast from one ESP32 to another. The receiver is an access_point and server, the sender is a station and client.

I already read this: ESP32 - UDP broadcaster/ receiver with native LwIP library

But it didn't help. I know that my server works because I can send packages via terminal. But for the client it seems that the packages aren't leaving the esp.

My code:

// CLIENT: 

sockaddr_in _send_addr;
_send_addr.sin_family         = AF_INET,
_send_addr.sin_port           = htons( 5000 );
// also tried local broadcast 192.168.4.255
_send_addr.sin_addr.s_addr    = inet_addr( "255.255.255.255" ); 
_send_addr.sin_len            = sizeof( _send_addr );


int _sock;
_sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_IP );

int broadcast = 1;
setsockopt( _sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast) );

void* data; // has some length
size_t len; // len of data
sendto( _sock, data, len, 0, (const struct sockaddr*) &_send_addr,
   sizeof(_send_addr) );

// SERVER:
// server is bound to same port, and to ip "0.0.0.0"
// like I said normally the server shouldn't be the problem, cause he received already

I skipped the checks.

But everything is created successfully, and the sendto returns the correct number of bytes written.

I have really no idea anymore appreciate any help.

So I found the problem. There is in fact no problem with the socket.

I have bluetooth and wifi running at the same time. On esp32 both share one antenna. It seems like the BT gets a higher priority (I am running an a2dp sink). And the wifi module is unable to acquire the antenna. Hence the problem.

The following problem (and maybe a solution), can be found here:

acquire a semaphore for the esp32 antenna (bluetooth/wifi dualmode)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM