@@ -359,12 +359,15 @@ class MosquittoEngine final : public Engine, protected mqtt_event_listener, prot
359359
360360public:
361361 MosquittoEngine (const EngineConfig config, const string &host, const int port,
362- const int keep_alive, const string &client_id, const bool clean_session)
362+ const int keep_alive, const string &client_id, const bool clean_session, const std::string &user, const std::string &pw )
363363 : _debugOutput(config.debugOutput())
364364 , client(this , host, port, keep_alive, client_id, clean_session)
365365 , discoveryLastSent(0 )
366366 , discoveryPeriod(config.discoveryPeriod/3 )
367367 {
368+ if (user.size ()) {
369+ client.setUsernamePassword (user, pw);
370+ }
368371 client.connect ();
369372 }
370373
@@ -567,8 +570,7 @@ shared_ptr<Engine> createEngine(const EngineConfig config) {
567570 cout << " keep_alive: " << keep_alive << endl;
568571 cout << " clean_session: " << clean_session << endl;
569572 }
570-
571- return make_shared<MosquittoEngine>(config, host, port, keep_alive, client_id, clean_session);
573+ return make_shared<MosquittoEngine>(config, host, port, keep_alive, client_id, clean_session, username, password);
572574 } else if (string_starts_with (url, " amqp://" )) {
573575 return make_shared<AmqpEngine>(url, config);
574576 }
0 commit comments