How can I use FreeRTOS Socket API instead of LWIP?

User avatar
Micrified
Posts: 11
Joined: Thu Aug 29, 2019 1:26 pm

How can I use FreeRTOS Socket API instead of LWIP?

Postby Micrified » Sat Sep 28, 2019 12:43 pm

Context: I'm using FreeRTOS to run my project. One task in the project needs to manage sockets for me. To do this, I decided to use FreeRTOS Select since it enables FreeRTOS to put my socket-task in the background when there is nothing to read.

Link to FreeRTOS Select: https://www.freertos.org/FreeRTOS-Plus/ ... elect.html

Problem: I can't include FreeRTOS_sockets. I have tried:
1.

Code: Select all

#include "freertos/FreeRTOS_sockets.h"
2.

Code: Select all

#include "FreeRTOS_sockets.h
3.

Code: Select all

#include freertos/sockets.h
It seems that from this, and also looking into the components of Esp IDF, that there isn't a sockets API available from FreeRTOS library. This is a big problem because I want to use the built in functionality that comes with the FreeRTOS sockets. Is there any workaround for this? Is there a branch of Esp-IDF with this API I want? Can I somehow include the files myself?

Thank you for your time in advanced. If you want to see what I am doing, the source code for the task (and only the task) in particular is here: https://gist.github.com/Micrified/5471e ... 11c99a366b
Micrified (Netherlands)

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

Re: How can I use FreeRTOS Socket API instead of LWIP?

Postby WiFive » Sun Sep 29, 2019 3:51 am

The freertos tcpip stack is a separate component and it used to be commercial license only so esp-idf was built with lwip.

https://github.com/espressif/esp-idf/tr ... tem/select

ESP_Sprite
Posts: 9759
Joined: Thu Nov 26, 2015 4:08 am

Re: How can I use FreeRTOS Socket API instead of LWIP?

Postby ESP_Sprite » Sun Sep 29, 2019 4:51 am

Also, our LwIP implementation also doesn't schedule tasks if all they're doing is waiting for data.

User avatar
Micrified
Posts: 11
Joined: Thu Aug 29, 2019 1:26 pm

Re: How can I use FreeRTOS Socket API instead of LWIP?

Postby Micrified » Sun Sep 29, 2019 12:43 pm

@ESP_Sprite

So you're saying that using an LwIP socket will put the task in the background if it is blocked waiting? If that's true, then it's a good thing because I'm not totally stuck. However, I would really like to know if there anything I can do to easily get access to the FreeRTOS sockets. It would be disappointing to have to throw away the code I wrote and redesign my socket handling setup.

For what it's worth, I found that Amazon FreeRTOS (https://medium.com/the-esp-journal/amaz ... 74a4412a21) does use the native socket implementation? Do you know anything about that or whether that can/will be incorporated into ESP-IDF anytime soon?

Thanks for answering!
Micrified (Netherlands)

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

Re: How can I use FreeRTOS Socket API instead of LWIP?

Postby WiFive » Sun Sep 29, 2019 9:54 pm

Amazon freertos does support esp32 but it doesn't support dual core and they are not great about pulling in updates from esp-idf. But they did at least update their minor release version recently.

It seems like most of your changes would just be removing the freertos prefix.

User avatar
Micrified
Posts: 11
Joined: Thu Aug 29, 2019 1:26 pm

Re: How can I use FreeRTOS Socket API instead of LWIP?

Postby Micrified » Mon Sep 30, 2019 12:23 am

Yeah I ended up using the file you linked, along with some other forum posts (because LwIP doesn't seem to have any guides besides a barebones API reference from what I could find) to refactor my task. I now have a working select and it does exactly what I wanted.

I've very happy with this development. I am going to just leave a link my github gist containing the source and header file for the task. That way someone else searching this might find it. There are a couple of other included files there that people will need to remove since I don't provide them but nothing they can't replace themselves. It at least shows how I got select to work, which was the problem here.

https://gist.github.com/Micrified/45c28 ... 08900a8dae

Thanks a lot for your assistance, and for that information on Amazon FreeRTOS. I think I'll stick with ESP IDF for now! :)
Micrified (Netherlands)

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 164 guests