-->
Page 1 of 1

How to delay inside a task on ESP8266?

PostPosted: Wed Jan 29, 2020 9:55 am
by Chris DB
On ESP32, if I want to put a delay inside a task I do this:
Code: Select all   xTaskCreate([](void * p) {
      for (int i = 0; i < 10; i++) {
         Serial.println(String("i=") + i);
         delay(1000);
      }
      vTaskDelete(NULL);
   }, "t1", 10000, (int *)1, 0, NULL);

and a new line is printed every second.

On ESP8266, if I do this:
Code: Select all   system_os_task([](os_event_t *e) {
      for (int i = 0; i < 10; i++) {
         Serial.println(String("i=") + i);
         delay(1000);
      }
   }, 0, g_my_queue, 1);
   system_os_post(0, 0, 0);

all lines are printed without delay. `delay(1000)` has no effect inside the task.

How does one put a delay inside a task on ESP8266?