How are sockets and netifs connected in ESP32?

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

How are sockets and netifs connected in ESP32?

Postby RichPiano » Wed May 05, 2021 8:16 am

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?

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Re: How are sockets and netifs connected in ESP32?

Postby Vader_Mester » Wed May 05, 2021 9:45 am

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.

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

Re: How are sockets and netifs connected in ESP32?

Postby RichPiano » Wed May 05, 2021 9:52 am

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..


RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

Re: How are sockets and netifs connected in ESP32?

Postby RichPiano » Wed May 05, 2021 1:26 pm

@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?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How are sockets and netifs connected in ESP32?

Postby WiFive » Wed May 05, 2021 7:38 pm

It is based on lwip forwarding using netmasks and the default netif

RichPiano
Posts: 123
Joined: Mon May 18, 2020 2:51 pm

Re: How are sockets and netifs connected in ESP32?

Postby RichPiano » Thu May 06, 2021 6:48 am

Thank you can you recommend to me some literature or a place to start reading? I would like to know more about this topic! :)

Who is online

Users browsing this forum: No registered users and 118 guests