In many examples using the PubSubClient library, the MQTT client.loop() function is placed in the main 'void loop()' section of the sketch.
I have a sketch where the main 'loop' section is running at more than 100x per second if there is no action from connected sensors. So in my case the MQTT client.loop() is called at very high frequency.
Would it be better to reduce the number of MQTT client.loop() calls ? How often should it be called ?
Does calling client.loop() cause network traffic ?
Quote from
"I would not recommend calling it in a tight loop without any delay at all - I have seen that cause a mini denial-of-service on the network hardware as it constantly checks to see if there's anything to do."
Have you had a problem? What's the minimum update rate need such that your project's performance is acceptable? If you're worried about it, you could always include a millis()-based timer that throttles the update rate without slowing down the rest of your loop.
I have a dedicated FreeRTOS task on ESP32 that calls loop() every 100ms. That's fast enough for the particular project. So, it depends on what's needed.