You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You might be better served using the RTOS port for the ESP32 which has a clear concept of threads, rather than abstracted like Arduino. https://github.com/espressif/ESP31_RTOS_SDK
@whatnick nothing is abstracted ;) Arduino runs in one thread and you are free to spin another one or more if you need to. API is exactly the same... as @igrr said, Arduino on ESP32 runs on FreeRTOS
void do_thing_task( void* p ) // gotta have a void pointer as parameter even if unused
{
while( true ) // gotta have infinite loop
{
// do things
vTaskDelay( 1000 / portTICK_PERIOD_MS ) // wait / yield time to other tasks
}
}
Then you start it with
xTaskCreate(
&do_thing_task, // function
"do_thing_task", // name
2048, // stack
NULL, // void* to input parameter
10, // priority
NULL // task handle
);
This is a really interesting topic. To clarify my doubts I would like to ask by showing example.
Since arduino-esp32 is built on top of FreeRTOS, does it mean it is possible to call xTaskCreate directly from *.ino code? Is there a sufficient API for doing that?
Activity
copercini commentedon Feb 23, 2017
Check this out: https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiClientEvents/WiFiClientEvents.ino
https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino
https://github.com/copercini/esp32-iot-examples/blob/master/WiFi_nonBlocking/WiFi_nonBlocking.ino
You can manage your wifi connection without block the main Sketch
see the functions:
wifiOnConnect
wifiOnDisconnect
wifiConnectedLoop
wifiDisconnectedLoop
me-no-dev commentedon Feb 23, 2017
what do you mean by "listen on another thread"?
marvindinneweth commentedon Feb 24, 2017
I want to have a different thread where a little rest api is running and responds to get requests. This intirely separated from the main loop.
whatnick commentedon Mar 17, 2017
You might be better served using the RTOS port for the ESP32 which has a clear concept of threads, rather than abstracted like Arduino. https://github.com/espressif/ESP31_RTOS_SDK
igrr commentedon Mar 17, 2017
@whatnick what makes you think that this Arduino core is bare metal? It runs on top of FreeRTOS.
whatnick commentedon Mar 17, 2017
I meant as threads explicitly exposed, rather than abstracted away in Arduino land.
me-no-dev commentedon Mar 17, 2017
@whatnick nothing is abstracted ;) Arduino runs in one thread and you are free to spin another one or more if you need to. API is exactly the same... as @igrr said, Arduino on ESP32 runs on FreeRTOS
whatnick commentedon Mar 17, 2017
What would be the concrete answer to the above ? A threaded webserver sample ?
me-no-dev commentedon Mar 17, 2017
@whatnick so you want an example? I'm not quite sure what the issue is here?
Again, Arduino runs on top of RTOS and the specific RTOS is: https://github.com/espressif/esp-idf
whatnick commentedon Mar 18, 2017
forthlightning commentedon Mar 20, 2017
Not sure about threading.h but freertos has tasks which probably satisfy what you want to do.
I'm on freertos.org all day, here is the task API call that esp-idf uses: http://www.freertos.org/a00125.html
A task has to be of the form
Then you start it with
baldram commentedon Jul 1, 2017
This is a really interesting topic. To clarify my doubts I would like to ask by showing example.
Since arduino-esp32 is built on top of FreeRTOS, does it mean it is possible to call
xTaskCreate
directly from*.ino
code? Is there a sufficient API for doing that?It would look somehow like this example then:
https://github.com/feilipu/Arduino_FreeRTOS_Library/blob/master/examples/Blink_AnalogRead/Blink_AnalogRead.ino
Is it possible with arduino-esp32 ?
hakuren commentedon Jul 1, 2017
Check out this example by @copercini
https://github.com/copercini/esp32-iot-examples/blob/master/multiloop/multiloop.ino
[-]Multithreading?[/-][+]Multithreading support with xTaskCreate?[/+]17 remaining items