发送MQTT传入包Paho到void函数

问题描述

我无法将传入的mqtt包(Paho MQTT)发送到void函数send。我可以在receive中收到它,但我需要在send()

中再次发送它

cpp

void MqttApplication::mqttReceive()
{

    try {
        cout << "\subscribing to topics..." << endl;
        mqttClient->start_consuming();
        mqttClient->subscribe(TOPIC,QOS)->wait();
        cout << "...OK" << endl;
    }
    catch (const mqtt::exception& exc) {
        cerr << exc.what() << endl;
        return;
    }

    while (true) {
        auto msg = mqttClient->consume_message();
        if (!msg) {
            if (!mqttClient->is_connected()) {
                cout << "lost connection" << endl;
                if (mqttTryReconnect(*mqttClient)) {
                    mqttClient->subscribe(TOPIC,QOS);
                    cout << "application reconnected" << endl;
                    continue;
                }
                else {
                    cout << "application reconnect failed." << endl;
                }
            }
            else {
                cout << "error occurred." << endl;
            }
            break;
        }

        try {
            send(mqtt::const_message_ptr consume_message());
        }
        catch (const mqtt::exception& exc) {
            cerr << exc.what() << endl;
            return;
        }

        if (msg->get_topic() == "command" && msg->to_string() == "exit") {
            cout << "Exit command received" << endl;
            break;
        }

        cout << msg->get_topic() << ": " << msg->to_string() << endl;
    }
}

void MqttApplication::send(mqtt::const_message_ptr* msg)
{
    doc.Parse(msg->to_string())
}

hpp

void send(mqtt::const_message_ptr* msg);

我得到这些错误:

 error: expected primary-expression before ‘consume_message’
  286 |             send(mqtt::const_message_ptr consume_message());
      |                                             ^~~~~~~~~~~~~~~
 error: ‘using const_message_ptr = using const_ptr_t = class std::shared_ptr<const mqtt::message>’ {aka ‘class std::shared_ptr<const mqtt::message>’} has no member named ‘to_string’
  326 |     doc.Parse(msg->to_string());

consume_message()

enter image description here

我想念什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)