Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Read MQTT topic at app start
Forum Updated to NodeBB v4.3 + New Features

Read MQTT topic at app start

Scheduled Pinned Locked Moved Unsolved C++ Gurus
4 Posts 2 Posters 606 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.
  • Q Offline
    Q Offline
    qAlexKo
    wrote on last edited by qAlexKo
    #1

    Hi Qts!

    The tasks is this - when I start my program, at first I have to read a topic from some MQTT broker for some information. Before QT I made programs using Paho MQTT, and I used a synchronous reading mode, the functions like this:

    rc = MQTTClient_receive(mqtt_client, &topic_received, &topic_received_len, &message_received, 1000);
    

    I use QMQTT now; as far I understand it has only asynchronous reading (with a callback). But I need to read an MQTT topic right on the app start.

    jsulmJ 1 Reply Last reply
    0
    • Q qAlexKo

      Hi Qts!

      The tasks is this - when I start my program, at first I have to read a topic from some MQTT broker for some information. Before QT I made programs using Paho MQTT, and I used a synchronous reading mode, the functions like this:

      rc = MQTTClient_receive(mqtt_client, &topic_received, &topic_received_len, &message_received, 1000);
      

      I use QMQTT now; as far I understand it has only asynchronous reading (with a callback). But I need to read an MQTT topic right on the app start.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @qAlexKo said in Read MQTT topic at app start:

      But I need to read an MQTT topic right on the app start

      You can also do that with assynchronous APIs. But from your description it is not clear what should NOT happen until you get the result from MQTT.

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

      Q 1 Reply Last reply
      0
      • jsulmJ jsulm

        @qAlexKo said in Read MQTT topic at app start:

        But I need to read an MQTT topic right on the app start

        You can also do that with assynchronous APIs. But from your description it is not clear what should NOT happen until you get the result from MQTT.

        Q Offline
        Q Offline
        qAlexKo
        wrote on last edited by
        #3

        @jsulm said in Read MQTT topic at app start:

        You can also do that with assynchronous APIs. But from your description it is not clear what should NOT happen until you get the result from MQTT.

        At the start of my app I create the main app structure in memory reading from a base file. After that this structure must be tuned according the information from the MQTT topic. In the end of the contructor I set ready_fl=true;
        In other words I must be sure that MQTT topic had been read before the structure tuning starts.

        Theoretically, I can create my main structure inside MQTT callback and set ready_fl also in the callback, but I somehow don't like it - the initialization sequence must be more clear and be in the app contructor.

        jsulmJ 1 Reply Last reply
        0
        • Q qAlexKo

          @jsulm said in Read MQTT topic at app start:

          You can also do that with assynchronous APIs. But from your description it is not clear what should NOT happen until you get the result from MQTT.

          At the start of my app I create the main app structure in memory reading from a base file. After that this structure must be tuned according the information from the MQTT topic. In the end of the contructor I set ready_fl=true;
          In other words I must be sure that MQTT topic had been read before the structure tuning starts.

          Theoretically, I can create my main structure inside MQTT callback and set ready_fl also in the callback, but I somehow don't like it - the initialization sequence must be more clear and be in the app contructor.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @qAlexKo said in Read MQTT topic at app start:

          must be more clear and be in the app contructor

          I disagree. If you use communication like MQTT you should not do everything in a constructor of a class. Assynchronous approach is the right one, especially when using assynchronous frameworks like Qt.

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

          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