Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #29 from argerus/add_automatic_reconnect
Browse files Browse the repository at this point in the history
dashboard: Add automatic reconnect
  • Loading branch information
Robert Hoettger committed Aug 19, 2019
2 parents 76050e6 + f6b64a6 commit b97b256
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions invehicle-apps/kuksa-cloud-dashboard/src/honoMqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ void HonoMqtt::connect (string honoAddr , string clientID, string userName, stri
p_Client = new mqtt::async_client (honoAddr, clientID);
p_Client->set_callback(*this);
mqtt::connect_options connOpts;
connOpts.set_connection_timeout(3);
connOpts.set_keep_alive_interval(20);
connOpts.set_automatic_reconnect(true);
connOpts.set_clean_session(true);
connOpts.set_user_name(userName);
connOpts.set_password(password);
Expand All @@ -78,10 +80,13 @@ void HonoMqtt::publish (string topic, string data) {
action_listener_pub listener;
mqtt::message_ptr pubmsg = mqtt::make_message(topic, data);
mqtt::delivery_token_ptr pubtok;
pubtok = p_Client->publish(pubmsg, nullptr, listener);
pubtok->wait();
cout << "Published." << endl;

try {
pubtok = p_Client->publish(pubmsg, nullptr, listener);
pubtok->wait();
cout << "Published." << endl;
} catch (const mqtt::exception& exc) {
cerr << exc.what() << endl;
}
}

void HonoMqtt::disconnect() {
Expand Down

0 comments on commit b97b256

Please sign in to comment.