Skip to content

Commit

Permalink
#451 Added low keep alive to async_publish_time to test connected/con…
Browse files Browse the repository at this point in the history
…nection_lost callbacks.
  • Loading branch information
fpagliughi committed Jan 4, 2025
1 parent c9e44ad commit 5e641dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/async_publish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//
// The sample demonstrates:
// - Connecting to an MQTT server/broker
// - Using a connect timeout
// - Publishing messages
// - Default file persistence
// - Last will and testament
Expand Down Expand Up @@ -41,6 +42,7 @@
#include "mqtt/async_client.h"

using namespace std;
using namespace std::chrono;

const string DFLT_SERVER_URI{"mqtt://localhost:1883"};
const string CLIENT_ID{"paho_cpp_async_publish"};
Expand Down Expand Up @@ -144,6 +146,7 @@ int main(int argc, char* argv[])
client.set_callback(cb);

auto connOpts = mqtt::connect_options_builder()
.connect_timeout(5s)
.clean_session()
.will(mqtt::message(TOPIC, LWT_PAYLOAD, QOS, false))
.finalize();
Expand Down
3 changes: 2 additions & 1 deletion examples/async_publish_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// - Sampling a value
// - Publishing messages using a `topic` object
// - Last will and testament
// - Callbacks with lambdas
// - Callbacks with lambdas (on connect and disconnect)
// - Using `create_options`
// - Creating options with builder classes
// - Offline buffering in the client
Expand Down Expand Up @@ -125,6 +125,7 @@ int main(int argc, char* argv[])
auto connOpts = mqtt::connect_options_builder()
.clean_session()
.will(willMsg)
.keep_alive_interval(10s)
.automatic_reconnect(seconds(1), seconds(10))
.finalize();

Expand Down

0 comments on commit 5e641dd

Please sign in to comment.