[SOLVED] MQTT on ESP32 receiving ALL messages after being offline

task handle and semaphore are very very different things.

Yes, you can use taskhandles as a lightweight 'alternate' to semaphores. Enjoy.

thank you, im going thru some tutorials. your code seems much more intresting to me now :slight_smile: thanks

I had a task that was jumping out of the for(;:wink: loop. I used a taskhandle to cause the task to restart, until I figured out the issue.

Idahowalker:
I had a task that was jumping out of the for(;:wink: loop. I used a taskhandle to cause the task to restart, until I figured out the issue.

i have this also :smiley: ill try to change my code to use semaphores then :smiley:

start a new thread and lets see the task and its creation method. How do you know the task is jumping the for( ; ; ). A log_i("task jumped ship"); would do the trick after the close of the for loop.

I take you are using vTasDelete( NULL ); after the for loop end?

Have you checked the HighWaterMark for stack space use?

Im in the middle of changing the code at the moment. I know it was jumping out because i would get some disconnects and some other funny stuff that i had to "correct" by using some extra bools like inuse=true or false etc

I am not using vTaskDelete(NULL) on any task.. should I? Wouldn't that delete the task and not run again? Im running all tasks "all the time",with some vTaskDelays....
No i havent checked how much stack im using, i increaed it a lot just to make it run and then fix it properly.

btw:

  sema_MQTT_Parser      = xSemaphoreCreateBinary();
  sema_HistoryCompleted = xSemaphoreCreateBinary();
  sema_MQTT_KeepAlive   = xSemaphoreCreateBinary();
  xSemaphoreGive( sema_HistoryCompleted );
  xSemaphoreGive( sema_MQTT_KeepAlive );

Why you xSemaphoreGive 2 Tasks?

thank you

If vTaskDelete(NULL) is after the for loop then vTaskDelete will never run, unless the task skips or goes beyond the for loop.

Why you xSemaphoreGive 2 Tasks?

Humm. The question does not make much sense. Because those semaphores are protecting 2 different resources. It's how semaphores work. A semaphore token must be given before a token can be taken.