Skip to content

Commit

Permalink
UDP socket accept broadcast messages
Browse files Browse the repository at this point in the history
  • Loading branch information
seeul8er committed Apr 23, 2024
1 parent 498aed3 commit c8dacb4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion main/db_esp32_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ int open_udp_socket() {
ESP_LOGE(TAG, "Unable to create socket: errno %d", errno);
return -1;
}
int err = bind(udp_socket, (struct sockaddr *) &server_addr, sizeof(server_addr));
int broadcastEnable=1;
int err = setsockopt(udp_socket, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));
if (err < 0) {
ESP_LOGE(TAG, "Socket unable to set socket to accept broadcast messages: errno %d", errno);
}
err = bind(udp_socket, (struct sockaddr *) &server_addr, sizeof(server_addr));
if (err < 0) {
ESP_LOGE(TAG, "Socket unable to bind: errno %d", errno);
}
Expand Down

0 comments on commit c8dacb4

Please sign in to comment.