Microsoft Azure IoT Hub connection issue using qmqttClient
-
Hi,
I am trying to connect and send data to Microsoft Azure Iot Hub using
const QString iotHubName = QStringLiteral("<yourIoTHub>"); const QString iotHubHostName = iotHubName + QStringLiteral(".azure-devices.net"); const QString deviceId = QStringLiteral("<yourDeviceName>"); QMqttClient client; client.setPort(8883); client.setHostname(iotHubHostName); client.setClientId(deviceId); client.setUsername(iotHubHostName + QStringLiteral("/") + deviceId + QStringLiteral("/?api-version=2018-06-30")); client.setPassword(QLatin1String("SharedAccessSignature sr=<yourIoTHub>.azure-devices.net%2Fdevices…")); auto caCerts = QSslCertificate::fromData(QByteArray(certificates)); QSslConfiguration sslConf; sslConf.setCaCertificates(caCerts); client.connectToHostEncryped(sslConf);
i am getting error while building as
error: ‘certificates’ was not declared in this scope auto caCerts = QSslCertificate::fromData(QByteArray(certificates)); error: no matching function for call to ‘QMqttClient::connectToHostEncrypted(QSslConfiguration&)’ client.connectToHostEncrypted(sslConf); ^
how to solve this errors.
Thank you!
-
Hi,
I am trying to connect and send data to Microsoft Azure Iot Hub using
const QString iotHubName = QStringLiteral("<yourIoTHub>"); const QString iotHubHostName = iotHubName + QStringLiteral(".azure-devices.net"); const QString deviceId = QStringLiteral("<yourDeviceName>"); QMqttClient client; client.setPort(8883); client.setHostname(iotHubHostName); client.setClientId(deviceId); client.setUsername(iotHubHostName + QStringLiteral("/") + deviceId + QStringLiteral("/?api-version=2018-06-30")); client.setPassword(QLatin1String("SharedAccessSignature sr=<yourIoTHub>.azure-devices.net%2Fdevices…")); auto caCerts = QSslCertificate::fromData(QByteArray(certificates)); QSslConfiguration sslConf; sslConf.setCaCertificates(caCerts); client.connectToHostEncryped(sslConf);
i am getting error while building as
error: ‘certificates’ was not declared in this scope auto caCerts = QSslCertificate::fromData(QByteArray(certificates)); error: no matching function for call to ‘QMqttClient::connectToHostEncrypted(QSslConfiguration&)’ client.connectToHostEncrypted(sslConf); ^
how to solve this errors.
Thank you!
@Arbaj-Patel said in Microsoft Azure IoT Hub connection issue using qmqttClient:
error: ‘certificates’ was not declared in this scope
auto caCerts = QSslCertificate::fromData(QByteArray(certificates));I cannot see where the variable certificates is defined/created?
regards
Karl-Heinz -
Hi @karlheinzreichel Thank you for reply.
it is not defined anywhere. i am not getting what should be added in place of "certificates". i am referring Cloud providers and telemetry via Qt MQTT this qt documentation to implement.
Thanks.
-
So how shall your code compile if you done declare a variable?
If you are in doubt how to setup the QSslConfiguration see
QT docs or maybe
https://stackoverflow.com/questions/3683826/qnetworkrequest-and-default-ssl-configuration
helps
regards
karl-heinz -
Hi, I resolved the certificates issue by changing 1 line of code
auto caCerts = QSslCertificate::fromPath("<file_path>/verificationCert.pem",QSsl::Pem, QRegExp::Wildcard);
but still there is a error
error: no matching function for call to ‘QMqttClient::connectToHostEncrypted(QSslConfiguration&)’ client.connectToHostEncrypted(sslConf);
and if i use
client.connectToHost();
instead of client.connectToHostEncrypted(sslConf); then there is no Build issue but while connecting to host it throwing client.error 256.
How to fix this? which one is best way to connect? please help me.Thank you
-
Hi, I resolved the certificates issue by changing 1 line of code
auto caCerts = QSslCertificate::fromPath("<file_path>/verificationCert.pem",QSsl::Pem, QRegExp::Wildcard);
but still there is a error
error: no matching function for call to ‘QMqttClient::connectToHostEncrypted(QSslConfiguration&)’ client.connectToHostEncrypted(sslConf);
and if i use
client.connectToHost();
instead of client.connectToHostEncrypted(sslConf); then there is no Build issue but while connecting to host it throwing client.error 256.
How to fix this? which one is best way to connect? please help me.Thank you
@Arbaj-Patel said in Microsoft Azure IoT Hub connection issue using qmqttClient:
error: no matching function for call to ‘QMqttClient::connectToHostEncrypted(QSslConfiguration&)’ client.connectToHostEncrypted(sslConf);
the problem is that such method expects the name of the server to connect to, not a QSslConfiguration object. Check documentation
-
@Arbaj-Patel said in Microsoft Azure IoT Hub connection issue using qmqttClient:
client.connectToHostEncryped(sslConf);
You forgot the 't' in Encrypted:
Not client.connectToHostEncryped(sslConf);
but client.connectToHostEncrypted(sslConf); -
Hey,
this is a bit old, but maybe I can still help you, or someone else with a similar issue... We lately released a blog series about how to connect a qt application with Microsoft Azure IoT Hub; from scratch, including working examples in github. Take a look, https://blog.basyskom.com/2020/connect-qt-app-with-azure-iot-hub/Best
Jeremias