Track multiple timeous with TaskScheduler

I have an ESP32 that receives watchdog messages from up to approximately 30 remote devices via UDP. I had it in mind to use TaskScheduler for tracking the timeouts as it is already in use and I like it, and I am looking for some advice as how best to implement this.

The number of devices vary as they come on and offline, which means the number of scheduler tasks varies, and maybe the number of callback routines?

  1. I think I would would ideally like to use the same callback for all task, but I have never delved into this, but it seems straightforward enough using TaskId and LTS, but any advice would be appreciated.
  2. Is there a way to dynamically create tasks? I would like to create and destroy tasks, as devices come on and offline, but I have never done this before. Each device has its own struct, and ideally the task (or pointer to) would reside in the struct. I tried creating a pointer to a Task in the structure but I got a load of errors.
  3. Ive already discovered that enabling the Tsk Scheduler functionality with the #define lines in the LTS examples stops my serial read JSON from working properly - whats that about then?

Thanks, Jim

Are you dynamically adding new remote devices and then configuring your esp32 with a profile of the new device (say through a web interface) with say its ID, data send frequency etc. etc. or do these devices self-register ?
I'd probably create an object for each device and mark it with a timestamp of the last data transmission from it. Occasionally scan all the objects looking for those which have not been active recently.

Hi 6v6gt - thats a good way of doing it.
As the devices appear (by sending a UDP msg) they get added to the list and compared with an expected MAC - when matched, the data object for it can be set to active and the time stored as you suggest.
I have got my dynamic scheduler tasks working, albeit with some fiddling with the TaskScheduler build #defines, and now an unexplained crash.. still, onwards and upwards.
If I dont manage to determine the problem with the schedulers, I may resort to your idea.
Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.