MQTT : Keep Alive

Communications

MQTT : Keep Alive

2 min read
iotbasics
MQTT

This article is a continuation of the article IoT basics: Introduction to MQTT Protocol

MQTT keepalive is used to know if the connection between sender and receiver is still open and working.

When a connection is established between sender and receiver, the connection usually stays open. However, the sender may not be sending the messages frequently.

If no message was exchanged between the sender and the receiver for a certain amount of time, the sender sends a ping request to the receiver and the receiver sends a response back. This is called the keep-alive interval.

PINGREQ is a ping request message and PINGRESP is the response to the ping.

When opening the connection, the keep-alive period can be set. For example, with mosquito MQTT, the default keep-alive is 60 seconds. That means, if there is no message exchange in 60 seconds, the PINGREQ is sent by the sender.

Definition of keepalive interval from mosquitto docs

keepalive_interval seconds : Set the number of seconds after which the bridge should send a ping if no other traffic has occurred. Defaults to 60. A minimum value of 5 seconds is allowed.

More about the practical use of keepalive interval in the next articles.

More Posts

Web of Things ( WoT ) Explained
General

The Internet of Things has revolutionized the way we interact with our devices, but it also brings new challenges in terms of interoperabili...

10 essential tips to speed up software development on Linux
General

Developers who always use Linux can not shut up about it because it is actually that good. It feels like you are coming out of the abstracti...

Git commit best practices
General

This post explains how to write good commit messages and how not to write bad commit messages. Also, you will learn some more best practices...