issues establishing connection between broker and Qt using Qmqtt
-
Hello
I am trying to establish a MQTT connection between my app and an external broker with a certificate. . When I try to connect to the host I do get a log on the broker but on QT I get the "QMqttClient::TransportInvalid" error. Anyone know what the issue could be?
Logging Ubuntu mosquitto broker behind nginx proxy:
1675345598: New connection from 172.17.0.1:60662 on port 8883.
1675345598: Client <unknown> closed its connection.It does work with other applications like MqttBox.
Here is the code I use:
QFile certFile(":/ca.cer"); certFile.open(QIODevice::ReadOnly); client = new QMqttClient(this); QSslCertificate cert = QSslCertificate(&certFile, QSsl::Der); QSslConfiguration conf; conf.setProtocol(QSsl::TlsV1_2); conf.setCaCertificates({cert}); QSslConfiguration::setDefaultConfiguration(conf); QObject::connect(client, &QMqttClient::stateChanged, [](QMqttClient::ClientState state){ if(state == QMqttClient::Disconnected) qDebug() << " State: Disconnected"; else if(state == QMqttClient::Connecting) qDebug() << " State: Connecting"; else if(state == QMqttClient::Connected) qDebug() << " State: Connected"; }); QObject::connect(client, &QMqttClient::errorChanged, [](QMqttClient::ClientError error){ qDebug() << "error Mqtt: " << error; }); client->setHostname(hostName); client->setPort(portName); client->setUsername(userName); client->setPassword(passWord); client->setClientId(clientId); client->setProtocolVersion(QMqttClient::MQTT_3_1_1); client->connectToHostEncrypted(conf);```Kind regards
Yina