Create a Freertos task with ota example

Hi amazing community…

I would like to run this amazing example

https://github.com/ayushsharma82/ElegantOTA/blob/master/examples/ESP32_Demo/ESP32_Demo.ino

But inside a freertos task in this way

void Seventh_task_creation(void)
{
  xTaskCreate(Webserver_task ,"WEBSERVER",WEBSERVER_DELAY, NULL, Webserver_priority , &Task7_handle);
 
}

where

void Webserver_task(void *parameters)
{
   /*init of the ble task with properties*/
   web_portal_init();

   for(;;)
   {
    
   }
}

and inside the web_init fuinction basically there is the example inside the setup function …

void web_portal_init(void) 
{

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  } 
  // Wait for connection
  Serial.println(WiFi.localIP());

  local_server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) 
  {
    request->send(200, "text/plain", "Hi! I am ESP32.");
  });

  AsyncElegantOTA.begin(&local_server);    // Start ElegantOTA
 local_server.begin();
  Serial.println("HTTP server started");
  local_server.end(); 
}

Each time I try I get

ERROR A stack overflow in task WEBSERVER has been detected.
abort() was called at PC 0x40088a70 on core 0

Can you tell me what is wrong ?

Thanks a lot

The third entry is how much stack memory in words (á 4 bytes) you want to give the task, see

DELAY is a strange name for that. Have you tried putting a number like 32*1024 as the third argument?

1 Like

I need holiday Max… Instead of putting WEBSERVER_TASK_SIZE i used the delay…

xTaskCreate(Webserver_task ,"WEBSERVER",STACK_SIZE_WEBSERVER_TASK, NULL, Webserver_priority , &Task7_handle);

No I don’t have anymore the problem with the stack overflow…
The task is running but when I try to insert the ip address on the browser I don’t get
the result from the webserver…
The example without using the freeRTOS task was running ok without issues…

This is how the task is defined…

void Webserver_task(void *parameters)
{
   /*init of the ble task with properties*/
   web_portal_init();

   for(;;)
   {
    //vTaskDelay(WEBSERVER_DELAY/portTICK_PERIOD_MS);
   }
}

this is the main.cpp

void setup(void)
{    

     /*start serial communication for debug purpose*/
     Serial.begin(115200); 

     /*creation of the queues for exchange data*/
/*      Create_queue_for_exchange_alarms_between_uart_and_wifi();
     Create_queue_for_exchange_log_between_uart_and_wifi();
     Create_queue_for_exchange_state_between_uart_and_wifi();
     Create_queue_for_exchange_physics_between_uart_and_wifi();

     Create_queue_for_exchange_commands_between_wifi_and_uart();
     Create_queue_for_exchange_config_between_wifi_and_uart();
     Create_queue_for_exchange_program_upload_between_wifi_and_uart(); */


     /*tasks creation*/ 
     //First_task_creation();
     //Second_task_creation();
     //Third_task_creation();
     //Fourth_task_creation();
     //Fifth_task_creation();
     //Sixth_task_creation();
     Seventh_task_creation();

     


}
/**
  * @brief  Function to execute in loop generated by the arduino framework
  * @param  None
  * @retval None
  */

void loop(void)
{
}

Thanks as usual for your time

Hard to say without the full code. Can you insert some Serial.println() statements to see whether it reaches certain parts of the code in the loop?

Max… find the issue… I was stopping the webservrr inside the init function…
Now it works inside the freertos task…
Now i will try to run this just created task with another task that transmit data over wifi with mqtt using the google iot library…
Let’see if i have problems with concurrecy…
For the moment thanks a lot as always

1 Like