I'm working on an AWS IoT project where the MQTT routines, callback lambdas and kind of everything else apart from initialisation are inside a task created by xTaskCreatePinnedToCore().

This task does few things: connect to AWS, subscribe to topics and then it enters into an infinite loop where it calls aws_iot_mqtt_yield checks for errors etc. In each loop I also call: vTaskDelay(10 / portTICK_RATE_MS);. It is from an example project where the delay was 1 sec which I then decreased to 10ms. What is a 'healthy' delay? Why do we even need a delay here? Thanks!

You shouldn't need a delay, or at least not one that keeps waking up.

If, as you suggest, you have initiated a thread that is triggered by a callback then there is no need for a main loop. Unless that loop is doing something useful every time it runs, it is just using CPU time and electrical power every time it wakes from and reenters delay.

I would either set a delay of the maximum integer value, to delay effectively for ever, or simply terminate that thread.

If there is something useful in the loop, then the sensible delay will depend entirely on what that something is.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.