c++ - 蚊子 : publish message to broker

标签 c++ c mqtt mosquitto

我在 Linux 下使用 mosquitto 的 cpp 包装器。
初始化后:

this->keepalive = 60;   
this->id = id;
this->port = port;
this->host = host;
this->topic = topic;
mosquittopp::log_init(MOSQ_LOG_ALL, MOSQ_LOG_STDOUT);
const int result = connect(host, port, keepalive);

如何发布我的自定义消息?

我正在使用包装器定义的发布方法,如下所示:

int publish(uint16_t *mid, const char *topic, uint32_t payloadlen=0, const uint8_t *payload=NULL, int qos=0, bool retain=false);

所以我可以这样调用:

publish(NULL, topic, strlen(message));

但是..我可以在哪里指定真正的“消息”?

最佳答案

在这里您可以使用 C++ 编写发布示例的示例代码 http://www.disk91.com/2013/technology/programming/mosquitto-c-sample-code-to-publish-message/

关于c++ - 蚊子 : publish message to broker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24534711/

相关文章:

c++ - gdb 打印命令中自静态包含字符串子类的递归输出

c++ - Arduino倒数计时器阻止程序运行的其余部分

检查数组索引是数字还是字母?

c - unsigned 在 if 语句比较中变为 signed?

使用 Paho 客户端的安卓 MQTT。无法接收消息

google-cloud-platform - MQTT 谷歌云与 ESP8266 连接

java - MQTT 代理在应用中?

c++ - 您的计算机缺少 CMAKE libintl-8.dll

c++ - 我如何将 char 数组转换为 int?

c - 我正在使用dstev计算特征向量得到零值