diff --git a/README.md b/README.md index b537b53..5130f7f 100644 --- a/README.md +++ b/README.md @@ -91,12 +91,17 @@ bool unsubscribe(const String &topic); Change the maximum packet size that can be sent over MQTT. The default is 128 bytes. ```c++ -bool setMaxPacketSize(const uint16_t size) +bool setMaxPacketSize(const uint16_t size); +``` + +Change the keepalive interval (15 seconds by default) +```c++ +void setKeepAlive(uint16_t keepAliveSeconds); ``` Enable the display of usefull debugging messages that will output to serial. ```c++ -void enableDebuggingMessages(const bool enabled = true) +void enableDebuggingMessages(const bool enabled = true); ``` Enable the web updater. This will host a simple form that will allow firmware upgrade (using, e.g., the `.bin` file produced by "Export Compiled Binary" in the Arduino IDE's "Sketch" menu). Must be set before the first loop() call. @@ -122,6 +127,11 @@ Change the delay between each MQTT reconnection attempt. Default is 15 seconds. void setMqttReconnectionAttemptDelay(const unsigned int milliseconds); ``` +Change the delay between each Wifi reconnection attempt. Default is 60 seconds. +```c++ +void setWifiReconnectionAttemptDelay(const unsigned int milliseconds); +``` + Connection status ```c++ bool isConnected(); // Return true if everything is connected. diff --git a/keywords.txt b/keywords.txt index 67db672..6cedb9c 100644 --- a/keywords.txt +++ b/keywords.txt @@ -25,6 +25,7 @@ publish KEYWORD2 subscribe KEYWORD2 subscribe KEYWORD2 unsubscribe KEYWORD2 +setKeepAlive KEYWORD2 executeDelayed KEYWORD2 @@ -39,4 +40,6 @@ getMqttServerPort KEYWORD2 setOnConnectionEstablishedCallback KEYWORD2 -setMqttReconnectionAttemptDelay KEYWORD2 \ No newline at end of file +setMqttReconnectionAttemptDelay KEYWORD2 + +setWifiReconnectionAttemptDelay KEYWORD2 \ No newline at end of file diff --git a/src/EspMQTTClient.cpp b/src/EspMQTTClient.cpp index 74c4a45..0faa239 100644 --- a/src/EspMQTTClient.cpp +++ b/src/EspMQTTClient.cpp @@ -377,6 +377,11 @@ bool EspMQTTClient::unsubscribe(const String &topic) return true; } +void EspMQTTClient::setKeepAlive(uint16_t keepAliveSeconds) +{ + _mqttClient.setKeepAlive(keepAliveSeconds); +} + void EspMQTTClient::executeDelayed(const unsigned long delay, DelayedExecutionCallback callback) { DelayedExecutionRecord delayedExecutionRecord; diff --git a/src/EspMQTTClient.h b/src/EspMQTTClient.h index afbcd74..3654b0b 100644 --- a/src/EspMQTTClient.h +++ b/src/EspMQTTClient.h @@ -139,6 +139,7 @@ class EspMQTTClient bool subscribe(const String &topic, MessageReceivedCallback messageReceivedCallback); bool subscribe(const String &topic, MessageReceivedCallbackWithTopic messageReceivedCallback); bool unsubscribe(const String &topic); //Unsubscribes from the topic, if it exists, and removes it from the CallbackList. + void setKeepAlive(uint16_t keepAliveSeconds); // Change the keepalive interval (15 seconds by default) // Other void executeDelayed(const unsigned long delay, DelayedExecutionCallback callback);