Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Microsoft Azure IoT Hub connection issue using qmqttClient
QtWS25 Last Chance

Microsoft Azure IoT Hub connection issue using qmqttClient

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 5 Posters 733 Views
  • 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 Offline
    A Offline
    Arbaj Patel
    wrote on last edited by
    #1

    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
    0
    • A Arbaj Patel

      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 Offline
      K Offline
      karlheinzreichel
      wrote on last edited by
      #2

      @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
      1
      • A Offline
        A Offline
        Arbaj Patel
        wrote on last edited by
        #3

        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
        0
        • K Offline
          K Offline
          karlheinzreichel
          wrote on last edited by
          #4

          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
          0
          • A Offline
            A Offline
            Arbaj Patel
            wrote on last edited by
            #5

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

              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. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @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
              0
              • F Offline
                F Offline
                Francois W
                wrote on last edited by
                #7

                @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
                0
                • J Offline
                  J Offline
                  Jeremias.Bosch
                  wrote on last edited by
                  #8

                  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
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved