Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Microsoft Azure IoT Hub connection issue using qmqttClient

    QML and Qt Quick
    5
    8
    324
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Arbaj Patel 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!

      K 1 Reply Last reply Reply Quote 0
      • K
        karlheinzreichel @Arbaj Patel 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

        1 Reply Last reply Reply Quote 1
        • A
          Arbaj Patel 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.

          1 Reply Last reply Reply Quote 0
          • K
            karlheinzreichel 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

            1 Reply Last reply Reply Quote 0
            • A
              Arbaj Patel 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

              Pablo J. Rogina 1 Reply Last reply Reply Quote 0
              • Pablo J. Rogina
                Pablo J. Rogina @Arbaj Patel 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

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                1 Reply Last reply Reply Quote 0
                • F
                  Francois W 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);

                  1 Reply Last reply Reply Quote 0
                  • J
                    Jeremias.Bosch 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

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post