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. QMqtt5 extracting response topic from received message
Forum Updated to NodeBB v4.3 + New Features

QMqtt5 extracting response topic from received message

Scheduled Pinned Locked Moved Unsolved General and Desktop
mqtt
1 Posts 1 Posters 261 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.
  • L Offline
    L Offline
    lukutis222
    wrote on last edited by lukutis222
    #1

    Hello. In QMqtt5 some updates were introduced. One of those updates is response topic and correlation data.

    Whenever server receives a message on a subscribed topic, there should be a way to extract its response topic (if the message has one) and then publish an acknowledgment message on that response topic.

    I have read simmilar QT forum thread regarding simmillar topic:
    https://forum.qt.io/topic/104756/mqtt-v5-request-response-example/7

    In QT documentation, I have found the following:
    https://doc.qt.io/qt-6/qmqttpublishproperties.html

    One of the public functions that this class contains is the following:
    2c5c8556-c561-4016-aed1-cf7ccc2345aa-image.png

    I am not fully understanding how can I use this class in my code. How can I retrieve what is the response topic?

    In my code, I have MQTT_message_handler that is being called everytime a message that I am subscribed to is received:

    
    void MainWindow::Mqtt_message_handler(QString topic,QString message){
        qDebug("MQTT handler");
        
            qDebug("Topic received = %s ",topic.toStdString().c_str());
            qDebug("Message received = %s ",message.toStdString().c_str());
            QMqttPublishProperties test;
            qDebug("response topic = %s",test.responseTopic().toStdString().c_str());
            qDebug("corellation data = %u",test.correlationData().toUInt());
            qDebug("\n");
        
        heck if subscribed topic has a response topic
        auto response_topic = QMqttPublishProperties::ResponseTopic();
    
        //LAST WILL RECEIVED
        if(strcmp(topic.toStdString().c_str(),LAST_WILL_T.toStdString().c_str())==0){
            ui->cell1_edit->setText(message);
        }
    
        //TEST TOPIC RECEIVED
        if(strcmp(topic.toStdString().c_str(),TEST_T.toStdString().c_str())==0){
            qDebug("Test topic message received");
        }
    }
    

    I am then monitoring the application output. I can see the following being printed when I receive a message that I am subscribed to:

    MQTT handler
    Topic received = /topic/led 
    Message received = Enable 
    response topic = 
    corellation data = 0
    
    

    For some reason the response topic is empty and corellation data is 0. However, on my mqtt client device I have set the following publish properties:

    static esp_mqtt5_publish_property_config_t publish_property_toggle_led = {
        .payload_format_indicator = 1,
        .message_expiry_interval = 1000,
        .topic_alias = 0,
        .response_topic = "/topic/test/response",
        .correlation_data = "5",
        .correlation_data_len = 1,
    };
    

    I would very much appreciate if someone could clarify to me how to correctly retrieve the response topic.

    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