How to keep MQTT alive for a long time. I want to connect MQTT for a long time but when connect for a peroid. it disconnect.
Thanks for advance
You need to change the keep alive time while connecting to the client. Default is 60 sec I think.
AT+CMQTTCONNECT?
Check the syntax for above mentioned command, you just need to change one parameter called <Keepalive_time>
Thanks for your advice. If I change the time. When the aive time finish.It disconnect. How I still connect forever ?
According to the AT command maximum keep alive time is 64800 secs (i.e. 18 hours). After that you have to reconnect to the client. Their is no such procedure in MQTT protocol that allows you to connect to the client forever.
If you check the MQTT protocol’s frame. In that 2 bytes are allotted for keep alive time, that means the maximum value will be (0b1111111111111111) in binary and its decimal equivalent is 65535 sec. So basically in protocol itself their is no provision to connect to client forever.
MQTT reference document : http://mqtt.org/documentation
Reference for keep alive time : https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901045
Thanks alot for your advice. how to send PINGREQ to broker? I want to keep mqtt alive for long time.