First - its GREAT that you are using freeRTOS - I have long (to many years been a fan of this on Pics - primarily 32’s…
So I have seen some posts which suggest that you will ‘eventually’ make multiple tasks available for user apps (as opposed to just splitting system/user)…any prognosis on when please ???.
If its likely to be a while, then a simpler solution may be to just create TWO loops (loop1 and loop2) - each of which runs in its own ‘task’.
That would allow us to simplify code into Local and Network (for example), so that local code can do its thing without worrying about if the Wifi is connected, if it managed to ‘publish’ etc.
Seems (to me anyway that it could simplify code (which is what an RTOS is good at doing) ??.
Just a suggestion…but would probably make my code easier - and thus so for many users…