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. is offical mqt has not Autoreconnect future as in the emqtd ?
Forum Updated to NodeBB v4.3 + New Features

is offical mqt has not Autoreconnect future as in the emqtd ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.2k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RahibeMeryem
    wrote on 25 Oct 2018, 08:57 last edited by
    #1

    Hi,

    I saw there is

    void setAutoReconnect(const bool value);
    void setAutoReconnectInterval(const int autoReconnectInterval);
    

    in the : https://github.com/emqtt/qmqtt
    link text

    do we have same in the official one ? I couldnt find it ?

    J 1 Reply Last reply 25 Oct 2018, 09:12
    0
    • R RahibeMeryem
      25 Oct 2018, 08:57

      Hi,

      I saw there is

      void setAutoReconnect(const bool value);
      void setAutoReconnectInterval(const int autoReconnectInterval);
      

      in the : https://github.com/emqtt/qmqtt
      link text

      do we have same in the official one ? I couldnt find it ?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 Oct 2018, 09:12 last edited by jsulm
      #2

      @RahibeMeryem I would say it depends on the version you're using. What version of qmqtt do you use?
      And do you mean the Client class?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RahibeMeryem
        wrote on 25 Oct 2018, 10:53 last edited by
        #3

        yes offical qmtt Client class.

        I could manage to use qmqtt in Qt thread successfully. I couldn't find a full example such as :

        qmqtt Client lives a thread created by movetothread.

        connet
        subscribe
        sendmessage
        reconnect-at-disconnet
        imeediately work on the received message.
        QTimer usage in that thread.

        J 1 Reply Last reply 25 Oct 2018, 11:10
        0
        • R RahibeMeryem
          25 Oct 2018, 10:53

          yes offical qmtt Client class.

          I could manage to use qmqtt in Qt thread successfully. I couldn't find a full example such as :

          qmqtt Client lives a thread created by movetothread.

          connet
          subscribe
          sendmessage
          reconnect-at-disconnet
          imeediately work on the received message.
          QTimer usage in that thread.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 25 Oct 2018, 11:10 last edited by jsulm
          #4

          @RahibeMeryem See https://github.com/emqtt/qmqtt/blob/master/src/mqtt/qmqtt_client.h, there are all these setAutoReconnect*() methods
          Why do you need a thread?
          Implement first without threads.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RahibeMeryem
            wrote on 25 Oct 2018, 11:24 last edited by
            #5

            its perfectly working without thread.

            I need to integrate it to our main framework as a thread which is responsible to send/reveve data

            looking now for QUdpSocket for messaging between pyqt5 and qt

            J 1 Reply Last reply 25 Oct 2018, 11:30
            0
            • R RahibeMeryem
              25 Oct 2018, 11:24

              its perfectly working without thread.

              I need to integrate it to our main framework as a thread which is responsible to send/reveve data

              looking now for QUdpSocket for messaging between pyqt5 and qt

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 25 Oct 2018, 11:30 last edited by
              #6

              @RahibeMeryem said in is offical mqt has not Autoreconnect future as in the emqtd ?:

              messaging between pyqt5 and qt

              I don't get this: do you mean in same application or are those two different applications?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • R Offline
                R Offline
                RahibeMeryem
                wrote on 25 Oct 2018, 16:58 last edited by
                #7

                I tested qmqtt without thread in Qt c++ and perfectly working .

                (I am using mqt to communicate between Qt c++ and pyqqt)

                Than I want to use in the my c++ app as thread like:

                in mainWidget:

                
                    c_qmqtt_thread = new QThread;
                    c_queue = new Central_que;
                    c_queue->moveToThread(c_qmqtt_thread);
                    c_qmqtt_thread->start();
                

                in Central_que.h:

                #ifndef CENTRAL_QUE_H
                #define CENTRAL_QUE_H
                
                #include <QObject>
                #include <QtMqtt>
                //#include "qmqtt.h"
                
                class Central_que : public QObject
                {
                    Q_OBJECT
                public:
                    explicit Central_que(QObject *parent = 0);
                
                    QMqttClient *c_client;
                    const QString topic = "qtmqtt/saf-0";
                    const QString result_topic = "result/light";
                    const QString hostname = "localhost";
                    QTimer *msg_timer;
                private:
                
                signals:
                
                public slots:
                    void cent_starting_connection();
                    void cent_send_message();
                    void succesfully_connected();
                    void status_changed();
                    void sendMessages();
                };
                
                #endif // CENTRAL_QUE_H
                
                

                Cental_que.cpp:

                #include "central_que.h"
                
                Central_que::Central_que(QObject *parent) : QObject(parent)
                {
                //    qRegisterMetaType<QMqttClient::ClientState>("QMqttClient::ClientState");
                
                    qDebug() << " CENTRAL QUEUE THREAD started" << endl;
                
                //    cent_starting_connection();
                }
                
                void Central_que::cent_starting_connection()
                {
                
                    c_client = new QMqttClient(this);
                    qDebug() << "Central :: Connecting....  " << endl;
                    qDebug() << "Central :: Connecting....  " << endl;
                    qDebug() << "Central :: Connecting....  " << endl;
                    qDebug() << "Central :: Connecting....  " << endl;
                    qDebug() << "Central :: Connecting....  " << endl;
                
                    connect(c_client , &QMqttClient::stateChanged , this , &Central_que::status_changed);
                    connect(c_client , &QMqttClient::connected , this , &Central_que::succesfully_connected);
                
                    c_client->setHostname(hostname);
                    c_client->setPort(1883);
                    c_client->setClientId("B-01");
                    c_client->setKeepAlive(200);
                
                    c_client->connectToHost();
                
                
                }
                
                void Central_que::cent_send_message()
                {
                
                }
                
                void Central_que::succesfully_connected()
                {
                    qDebug() << "Central : SUCCESFULLY CONNECTED . .  : " << c_client->state() << endl;
                    qDebug() << "Central : SUCCESFULLY CONNECTED . .  : " << c_client->state() << endl;
                    qDebug() << "Central : SUCCESFULLY CONNECTED . .  : " << c_client->state() << endl;
                
                    msg_timer = new QTimer;
                    connect(msg_timer, SIGNAL(timeout()) , this , SLOT(sendMessages()));
                    msg_timer->start(4000);
                
                     auto subscription = c_client->subscribe(result_topic,2);
                    if (!subscription) {
                        qDebug() << "Error Could not subscribe. Is there a valid connection?" << endl;
                        return;
                    }
                    else
                        qDebug() << " SUBSCRIBED Succefully " << endl;
                }
                
                
                
                
                
                void Central_que::status_changed()
                {
                    qDebug() << "Central : State Changed : " << c_client->state() << endl;
                    qDebug() << "Central : State Changed : " << c_client->state() << endl;
                    qDebug() << "Central : State Changed : " << c_client->state() << endl;
                
                }
                
                void Central_que::sendMessages()
                {
                    auto id = c_client->publish(topic, "bytarray" , 2 ,true);
                    qDebug() << "serverRespond : " << id << endl;
                }
                
                

                not copleted but this is second version. to give an idea.

                I want to use from my c++ app as a realible thread , re-connect if disconnected .

                I will feed the data from main thread through direct call or signal/slot.

                But when it comes to thread I couldnt utilize qmqtt as I expected.

                need a simple working basic example , could be useful for all of us.

                Best

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 25 Oct 2018, 20:59 last edited by
                  #8

                  Hi,

                  For that example, you should talk with that module's author, it's not an official Qt module.

                  Qt's mqtt module can be found here.

                  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
                  1
                  • R Offline
                    R Offline
                    RahibeMeryem
                    wrote on 31 Oct 2018, 17:35 last edited by
                    #9

                    I mean official qmqtt , is there any auto reconnect ?

                    or how can I properly re-connect if there is disconnection etc ?

                    1 Reply Last reply
                    0

                    4/9

                    25 Oct 2018, 11:10

                    • Login

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