Microsoft Azure IoT Hub connection issue using qmqttClient
-
wrote on 1 Oct 2019, 12:20 last edited by
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!
wrote on 1 Oct 2019, 12:27 last edited by@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 -
wrote on 1 Oct 2019, 12:41 last edited by
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.
-
wrote on 1 Oct 2019, 14:06 last edited by
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 -
wrote on 3 Oct 2019, 06:56 last edited by
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
wrote on 4 Oct 2019, 17:16 last edited by@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
-
wrote on 4 Mar 2020, 16:27 last edited by
@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); -
wrote on 21 May 2020, 19:47 last edited by
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