I modified the [ip_internal_network](https://github.com/espressif/esp-idf/tr ... al_network) example so the root and node broadcast an UDP message after the GOT_IP event.
I am creating a non-blocking socket,
Code: Select all
int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sockfd < 0) {
return;
} else {
if (fcntl(sockfd, F_SETFL, O_NONBLOCK) == -1) {
if (sockfd >= 0) {
close(sockfd);
}
return;
}
}
Code: Select all
struct sockaddr_in dest_addr;
struct sockaddr_in src_addr;
ssize_t udp_data_len = 0;
char buf[24] = {0};
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(8090);
dest_addr.sin_addr.s_addr = inet_addr("255.255.255.255");
udp_data_len = sendto(sockfd, "I am the blob", 14, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
if (udp_data_len < 0) {
ESP_LOGE(MESH_TAG, "Failed to send the UDP: %d", udp_data_len);
} else {
ESP_LOGI(MESH_TAG, "Sent UDP message (%d bytes)", udp_data_len);
}
src_addr_len = sizeof(src_addr);
udp_data_len = recvfrom(sockfd, buf, 24, 0, (struct sockaddr *)&src_addr, &src_addr_len);
if (udp_data_len > 0) {
ESP_LOGI(MESH_TAG, "UDP Data from %s: %s", inet_ntoa(src_addr.sin_addr.s_addr), buf);
} else if (udp_data_len == -1) {
ESP_LOGE(MESH_TAG, "Failed to recv data from %s: %s", inet_ntoa(src_addr.sin_addr.s_addr), strerror(errno));
}
Code: Select all
E (2234107) mesh_main: Failed to recv data from 0.0.0.0: No more processes
What setup could be wrong/missing?
Another question I have is: will the DHCP server on the root provide an IP address for the nodes on all the layers? Or a workaround is necessary to have an internal IP network on all the mesh layers?
Thanks in advance.