You've already forked Adafruit_MQTT_Library
mirror of
https://github.com/adafruit/Adafruit_MQTT_Library.git
synced 2025-07-08 14:01:58 +03:00
settable keepalive interval
This commit is contained in:
@ -132,6 +132,8 @@ Adafruit_MQTT::Adafruit_MQTT(const char *server, uint16_t port, const char *cid,
|
||||
will_qos = 0;
|
||||
will_retain = 0;
|
||||
|
||||
keepAliveInterval = MQTT_CONN_KEEPALIVE;
|
||||
|
||||
packet_id_counter = 0;
|
||||
}
|
||||
|
||||
@ -153,6 +155,8 @@ Adafruit_MQTT::Adafruit_MQTT(const char *server, uint16_t port,
|
||||
will_qos = 0;
|
||||
will_retain = 0;
|
||||
|
||||
keepAliveInterval = MQTT_CONN_KEEPALIVE;
|
||||
|
||||
packet_id_counter = 0;
|
||||
}
|
||||
|
||||
@ -384,6 +388,25 @@ bool Adafruit_MQTT::will(const char *topic, const char *payload, uint8_t qos,
|
||||
return true;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets the connect packet's KeepAlive Interval, in seconds. This
|
||||
function MUST be called prior to connect().
|
||||
@param keepAlive
|
||||
Maximum amount of time without communication between the
|
||||
client and the MQTT broker, in seconds.
|
||||
@returns True if called prior to connect(), False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool Adafruit_MQTT::setKeepAliveInterval(uint16_t keepAlive) {
|
||||
if (connected()) {
|
||||
DEBUG_PRINT(F("keepAlive defined after connection established."));
|
||||
return false;
|
||||
}
|
||||
keepAliveInterval = keepAlive;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Adafruit_MQTT::subscribe(Adafruit_MQTT_Subscribe *sub) {
|
||||
uint8_t i;
|
||||
// see if we are already subscribed
|
||||
@ -649,9 +672,9 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
|
||||
p[0] |= MQTT_CONN_PASSWORDFLAG;
|
||||
p++;
|
||||
|
||||
p[0] = MQTT_CONN_KEEPALIVE >> 8;
|
||||
p[0] = keepAliveInterval >> 8;
|
||||
p++;
|
||||
p[0] = MQTT_CONN_KEEPALIVE & 0xFF;
|
||||
p[0] = keepAliveInterval & 0xFF;
|
||||
p++;
|
||||
|
||||
if (MQTT_PROTOCOL_LEVEL == 3) {
|
||||
|
Reference in New Issue
Block a user