Read MQTT topic at app start
-
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.
-
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.
@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.
-
@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.
@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.
-
@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.
@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.