Skip to content

Commit

Permalink
Add setKeepAlive as requested in #57
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Lapointe committed Sep 3, 2020
1 parent de496a4 commit 1faf534
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ publish KEYWORD2
subscribe KEYWORD2
subscribe KEYWORD2
unsubscribe KEYWORD2
setKeepAlive KEYWORD2

executeDelayed KEYWORD2

Expand All @@ -39,4 +40,6 @@ getMqttServerPort KEYWORD2

setOnConnectionEstablishedCallback KEYWORD2

setMqttReconnectionAttemptDelay KEYWORD2
setMqttReconnectionAttemptDelay KEYWORD2

setWifiReconnectionAttemptDelay KEYWORD2
5 changes: 5 additions & 0 deletions src/EspMQTTClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/EspMQTTClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1faf534

Please sign in to comment.