File tree 1 file changed +10
-1
lines changed
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 20
20
#include " Logger.h"
21
21
22
22
#include < string>
23
+ #include < chrono>
24
+
25
+ using namespace std ::chrono_literals;
23
26
24
27
namespace {
25
28
@@ -131,11 +134,13 @@ namespace sua {
131
134
{
132
135
Logger::info (" MQTT broker address: '{}:{}'" , _config.brokerHost , _config.brokerPort );
133
136
134
- mqtt::connect_options options;
137
+ static mqtt::connect_options options;
135
138
options.set_clean_session (false );
136
139
options.set_servers (std::make_shared<mqtt::string_collection>(
137
140
fmt::format (" {}:{}" , _config.brokerHost , _config.brokerPort )
138
141
));
142
+ options.set_automatic_reconnect (true );
143
+ options.set_connect_timeout (5000ms);
139
144
140
145
static MqttCallback callback (_client, options, _context);
141
146
_client.set_callback (callback);
@@ -176,6 +181,10 @@ namespace sua {
176
181
message->set_qos (QUALITY);
177
182
message->set_retained (retained);
178
183
_client.publish (message);
184
+
185
+ if (!_client.is_connected () || !_client.get_pending_delivery_tokens ().empty ()) {
186
+ _client.reconnect ();
187
+ }
179
188
}
180
189
181
190
} // namespace sua
You can’t perform that action at this time.
0 commit comments