3

The mqtt documentation explains that the maximum value of the keepalive is 18 hours 12 minutes and 15 seconds.

But the mosquitto server disconnects the clients if it does not receive messages before 60 seconds plus a tolerance of 30 seconds that is to say maximum to 90 seconds.

That is, I can not configure a keepalive more than 90 seconds.

hardillb
  • 54,545
  • 11
  • 67
  • 105
E. Ortiz
  • 53
  • 1
  • 1
  • 4

2 Answers2

4

You do not configure the keep alive on the broker, it is configured on the client side.

The value is pass in the connect packet from the client to the broker (http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Keep_Alive)

How you configure this will depend on which client library you are using, but most libraries take it as a configuration option.

E.g. for libmosquitto you pass the keep alive value in seconds to the mosquitto_connect function (https://mosquitto.org/man/libmosquitto-3.html#idm46181896216640)

int mosquitto_connect(  mosq,    
    host,    
    port,    
    keepalive);      
struct mosquitto *mosq;
const char *host;
int port;

Also you normally will not have to publish a message, the client library should send ping packets if no messages have been sent/received in the keep alive period in order to keep the connection alive. int keepalive;

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Yes, that's right, I just made captures with wireshark to observe the PING packages with a keepalive of 5min, a PING is sent in the 5minutes to the mosquito server, but the PING never arrives, which causes that at 7 minutes and 30 seconds the server declares the connection closed by timeout, I think the problem is not MQTT the problem is TCP. – E. Ortiz Jan 17 '18 at 23:35
1

yes, 60 seconds is a default keepalive time for the clients. But there did exists a keepalive_interval in mosquitto.conf, that is for Mosquitto bridge mode, which is used to connect more than one mosquitto broker together.

Sebas
  • 21,192
  • 9
  • 55
  • 109
jianhui
  • 133
  • 6