after publish I do one loop() and then a disconnect(), but very often there are unsent messages that get lost.
Is there a clean way to verify if there are still messages in the queue and then iterate a loop() until the queue is empty? I could do this by using a counter to increment at each publish and to decrement at each onPublish, but is not a clean approach
One loop isn't enough. I'd probably go for the counter option. I don't know offhand of any way to see if there's anything left in flight in the queue, I'll have another look though.
after publish I do one loop() and then a disconnect(), but very often there are unsent messages that get lost.
Is there a clean way to verify if there are still messages in the queue and then iterate a loop() until the queue is empty? I could do this by using a counter to increment at each publish and to decrement at each onPublish, but is not a clean approach