- Sun Jan 11, 2015 11:34 am
#6998
scargill wrote:Thinking about it - mqttPublishedCb is no good - so that happens when something is published - and... you publish something else and... it disappears forever. I COULD set a flag in mqttPublishedCb and poll for that - but I'm worried that polling would stop other things from happening. I remember back in the dark ages of Visual Basic we had DOEVENTS which would ensure other stuff was handled while you were stuck in a loop - I've no idea if a similar function exists in the SDK or not..
Where is the problem? Of course when you call publish you will start a timer to notify in case of timeout. So you either get the sent callback (and kill the timer) or you get "not sent timeout" callback and you take proper measures - retry, reconnect, print error or whatever. This works no matter if you publish from a timer or from callback.
Do you say that publishing from the context of the mq callback is not working?
Probably this timeout could be embedded in the MQTT core and all this could be managed by the MQTT source. It already has one ticking timer so making "publishing" timeout is easy.
What do you think about this, Tuan PM? A new argument to the publish API to get a timeout value, and maybe additional argument to the callback so the user knows if this is success or timeout (or any other kind of error, e.g. not connected?).
Edit: buffering is not a solution. How deep buffers will you add? Probably user configurable, fine, but no matter how you make it, the "main" application might get buffer overflow - simply because it doesn't care about the actual processing in the "other" task (the mqtt task).
In other words, it is not possible that the main task runs in 1s periods and makes several publish actions without taking care about the environment - it could be that perfectly running system is deployed in remote area and two weeks later it breaks - because the speed of the internet connection slowed down. Imagine the other case, with callbacks and timeouts - the system will slow down the publishing rate according to the speed to the broker.
Also, imagine the case where you want to go into sleep mode after each measurement and publishing. If you don't use the callback, how will you know that the IP stack has sent the publish? When will you call the sleep function?