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!

1 Answer 1


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 agree to our terms of service and acknowledge you have read our privacy policy.

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