Hi guys,
Im currently working on an android mqtt based app using the paho java client. Here is my Question:
Is there a qay to turn of the automatically created ping messages that the client sends the broker every "keepAliveInterval" seconds?
Since the CPU of my device can go to sleep every now and then i need to implement my own ping service, wich wakes the CPU when its time to ping. The "problem" is that now i ping twice when the cpu is running.It would be nice to have an option in the ConnectionOptions to tell the client that i gonna do the pinging stuff on my own.
Setting the keepalive value to 0 using method setKeepAliveInterval on the connect options class will stop the client from sending pings. The value of 0 will be passed to the MQTT server telling it not to expect any ping packets and hence not to do any "keep alive" processing - which I suspect is not what you are looking for.
If any MQTT packet (not just ping) is sent within a keepalive interval the MQTT client will reset the timer which it uses to send a ping i.e. it minimises when it sends pings to only when no MQTT packet has been sent within a keepalive interval.
How are you sending a ping at the moment? The MQTT client does not have a public interface for sending a ping?
If a ping method was added then I believe the following would provide what you are looking for?
1) MQTT app sets the keepalive to value x
2) MQTT app has logic to wake up slightly less than x
3) MQTT app invokes the MQTT ping - this would reset the internal keepalive timer in the client meaning it would then not send its own ping.
Until a ping method is added publishing a message or re-subscribing would have the same effect.
oh... thank you,
I didnt know that the client stops pinging if any message was sent to the server within the last keepAlive period.
The problem was that my self managed ping message was sent shortly after the ping from the client. so it was a little too late. I changed the ping period that my app pings shortly before the mqtt client and that solved the problem.