Internal ip communication and mesh

Magnetuz
Posts: 12
Joined: Thu Dec 31, 2020 8:39 am

Internal ip communication and mesh

Postby Magnetuz » Fri Jul 12, 2024 3:13 pm

Hi all,

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;
    }
}
Then I am looping to send and then receive the replies.

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));
}
When running it, I keep getting the following error on both root and node and never receiving the messages:

Code: Select all

E (2234107) mesh_main: Failed to recv data from 0.0.0.0: No more processes
I also tried to send the message directly to the pair address instead of broadcast, but I got the same results.


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.

Who is online

Users browsing this forum: No registered users and 149 guests