Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trouble connecting to aws iot using QMqtt and QSsl stack.
QtWS25 Last Chance

Trouble connecting to aws iot using QMqtt and QSsl stack.

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 615 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.
  • E Offline
    E Offline
    eluppai
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • SGaistS SGaist

        Hi,

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

        E Offline
        E Offline
        eluppai
        wrote on last edited by
        #3

        @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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • E Offline
            E Offline
            eluppai
            wrote on last edited by
            #5

            @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
            0

            • Login

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