Boris Deletic
Boris Deletic

Reputation: 111

MQTT Keep Alive byte format

The MQTT 3.1.1 documentation is very clear and helpful, however I am having trouble understanding the meaning of one section regarding the Keep Alive byte structure in the connect message.

The documentation states:

The Keep Alive is a time interval measured in seconds. Expressed as a 16-bit word, it is the maximum time interval that is permitted to elapse between the point at which the Client finishes transmitting one Control Packet and the point it starts sending the next.

And gives an example of a keep alive payload:

  1. Keep Alive MSB (0) 0 0 0 0 0 0 0 0
  2. Keep Alive LSB (10) 0 0 0 0 1 0 1 0

I have interpreted this to represent a keep alive interval of 10 seconds, as the interval is given in seconds and that makes the most sense. However I'm not sure how you would represent longer intervals of, for example, 10 minutes.

Finally, would the maximum keep alive interval of 65535 seconds (~18 hours) be represented by these bytes

  1. Keep Alive MSB (255) 1 1 1 1 1 1 1 1
  2. Keep Alive LSB (255) 1 1 1 1 1 1 1 1

Thank you for your help

Upvotes: 1

Views: 719

Answers (2)

E. Ortiz
E. Ortiz

Reputation: 63

2^16=65536 seconds 65536/60 = 1092.27 minutes 1092.27/60 = 18.20 hours

0.20hour*60 = 12minutes y 0.27min*60 = 16.2sec

result: 18 hours,12minutes, 16sec

Upvotes: 1

hardillb
hardillb

Reputation: 59608

10 minutes = 600 seconds

600 in binary -> 0000 0010 0101 1000

And yes 65535 is the largest number that can be represented by a 16bit binary field, but there are very few situations where an 18 hour keep alive interval would make sense.

Upvotes: 0

Related Questions