Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Trouble connecting to aws iot using QMqtt and QSsl stack.

    General and Desktop
    2
    5
    292
    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.
    • E
      eluppai last edited by

      Brief Description: I am using QMqtt and QSsl stack to connect to perform a secure Mqtt connection and then publish some data on the aws server. But the Client state always stays on connecting never changes to connected

      Expected behavior: First I tried connecting to test.mosquitto.org, I was able to connect and publish the data. So the expected behavior was to see some similar results.

      Send_MqTT::Send_MqTT(QObject *parent) : QObject(parent)
      {
          m_socket=new QSslSocket();
          m_client=new QMqttClient();
          m_topicname = new QMqttTopicName();
          m_topicname->setName("Pubtopic/test");
      
          connect(m_client,&QMqttClient::stateChanged,[](QMqttClient::ClientState state){
              if(state == QMqttClient::Disconnected)
              {
                  qDebug()<<"State is Disconnected: "<<state;
              }
              else if(state == QMqttClient::Connecting)
              {
                  qDebug()<<"State is Connecting: "<<state;
              }
              else if(state == QMqttClient::Connected)
              {
                  qDebug()<<"State is Connected: "<<state;
              }
      
          });
          connect(m_client,&QMqttClient::errorChanged,[](QMqttClient::ClientError error_state){
              qDebug()<<"Error State is: "<<error_state;
          });
      }
      void Send_MqTT::connect_toserver()
      {
          if(QSslSocket::supportsSsl())
            {
              qDebug()<<"SSL SUPORTED";
              m_socket->setLocalCertificate("<certificatelocation>",QSsl::Pem);
              m_socket->setPrivateKey("<private Key Location>",QSsl::Rsa,QSsl::Pem);
              m_client->setHostname("host-name");
              m_client->setPort(8883);
              m_client->setTransport(m_socket,QMqttClient::SecureSocket);
              m_client->connectToHostEncrypted();
          }
      }
      

      Am I missing something. Do I have to set Mqtt connection properties before I begin the connection?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Can you explain what result you are getting ?
        What errors are you getting ?
        What version of Qt are you using ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        E 1 Reply Last reply Reply Quote 0
        • E
          eluppai @SGaist last edited by

          @sgaist The clientState stays on connecting and never goes to connected. Because of which I am unable to publish any data. The ClientState has to transition to connected for me to publish or subscribe

          enum QMqttClient::ClientState
          Constant	                             Value	
          QMqttClient::Disconnected	              0	
          QMqttClient::Connecting	                      1	      
          QMqttClient::Connected	                      2
          

          So the state always stays on connecting. I do not get any errors.
          Qt version is 5.12.3
          and system is an Ubuntu 18.04

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            From the looks of it, you didn't connect any of the QOpenSSLSocket error signals. You should add them.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • E
              eluppai last edited by

              @SGaist okay I will add that. But Don't you think if there was any error. Mqtt should also throw an error. Because if I remove a certificate or a private key from the file or add any wrong information, I do get an error stating that the transport properties are not set properly and the ClientState goes to disconnected it does not stays on connecting for a long period of time.

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