I am using MQTT 3.1.1, I have installed a mosquito as a local server on my computer.
I am sending the Some sensors data from pubsubclient (MQTT client library ) to the mosquito and saving it to the database from the mosquito server
Whenever I start the session upto 5-10 minutes I am getting the messages but after that MQTT client couldn't send any message and disconnect automatically.
Before disconnecting it prints the following message in command line
client <clientname> has exceeded timeout, disconnecting
Socket error on client <clientname>, disconnecting.
Also I am using the server with default configurations, except the QOS is set to 2
What is causing this error and What should I do, so that client should not disconnect from my local server ?
The node(s) that is(are) Subscribing (and maybe the Publishing nodes if they take too long to Publish again) need the 'keepalive' field on the Connect call set. Most MQTT Brokers will timeout connections after something like 5 minutes, unless you have modified the timeout value in the settings.
Set the 'keepalive' option to something like 30 or 60 seconds will prevent the MQTT Broker from disconnecting. You Subscribers will start sending PINGREQ packets, and the MQTT Broker will reply with PINGRESP packets.
Read more here: http://www.steves-internet-guide.com/mqtt-keep-alive-by-example/