Page 1 of 1

How are sockets and netifs connected in ESP32?

Posted: Wed May 05, 2021 8:16 am
by RichPiano
I'm developing an app that uses the ESP-MESH network interfaces. For that I would like to know how to write TCP-packets to that netif. I read this very helpful blogpost , but I'm pretty sure that the architecture within the esp is somewhat different than in Linux.The basic implementation of HTTP writes to a socket, but then how does that socket know what network interface to use?

Re: How are sockets and netifs connected in ESP32?

Posted: Wed May 05, 2021 9:45 am
by Vader_Mester
I suggest you read this, will be helpful.
https://docs.espressif.com/projects/esp ... netif.html

By the way, when you initilaize the Wifi with MESH, there is a function that initializes the netif as well.

Re: How are sockets and netifs connected in ESP32?

Posted: Wed May 05, 2021 9:52 am
by RichPiano
Thank you! I have though already read the documentation on netifs, meshes and a lot of other stuff but I still can't wrap my head around this particular thing.

So what happens when I create a netif and the tcp module writes to a socket? Through which netif will the data leave the esp when I have multiple of them? I think I'm missing a piece here..

Re: How are sockets and netifs connected in ESP32?

Posted: Wed May 05, 2021 10:22 am
by WiFive

Re: How are sockets and netifs connected in ESP32?

Posted: Wed May 05, 2021 1:26 pm
by RichPiano
@WiFive That's the example I'm studying right now. As far as I can see, the root node will handle the IP traffic of the network. All nodes receive from mesh with esp_mesh_recv() and pass it on to the interfaces with esp_netif_receive(), isn't it? But then how does the kernel know which socket it has to pass on the data?

My current understanding is this:

Code: Select all

Socket (application API) --> kernel --> netif --> mesh
(or vice versa) Is this correct?

Re: How are sockets and netifs connected in ESP32?

Posted: Wed May 05, 2021 7:38 pm
by WiFive
It is based on lwip forwarding using netmasks and the default netif

Re: How are sockets and netifs connected in ESP32?

Posted: Thu May 06, 2021 6:48 am
by RichPiano
Thank you can you recommend to me some literature or a place to start reading? I would like to know more about this topic! :)