如何在接收消息时确定ID客户端?

问题描述 投票:0回答:1

我正在设置我的MQTT设备。我从ESP8266 + NodeMCU v2发送的代码是这样的:

client.publish(ANSWER_TEMPERATURE_TOPIC, buffer);

ANSWER_TEMPERATURE_TOPIC“ answer / node_1 /温度”,而buffer例如是22.10。我在连接到const char* CLIENT_ID = "node_1";

时设置了设备
client.connect(CLIENT_ID, MQTT_USERNAME, MQTT_PASSWORD)

在接收消息期间是否有可能检查此ID CLIENT?我在树莓派中运行以下命令:

 mosquitto_sub -d -u pi -P channel -t answer/node_1/temperature

答案是

Client mosqsub/1021-raspberryp sending CONNECT
Client mosqsub/1021-raspberryp received CONNACK
Client mosqsub/1021-raspberryp sending SUBSCRIBE (Mid: 1, Topic: 
answer/node_1/temperature, QoS: 0)

Client mosqsub/1021-raspberryp received SUBACK
Subscribed (mid: 1): 0

Client mosqsub/1021-raspberryp received PUBLISH (d0, q0, r0, m0, 
'answer/node_1/temperature', ... (5 bytes))
21.8

是否有可能看到此CLIENT_ID?以后,我想创建PHP文件来接收此消息。

mosquitto libmosquitto
1个回答
0
投票

您不能,除非您自己将消息添加到有效负载中,或者在将消息发布到的主题中,否则消息中没有编码的有关发件人的信息。

© www.soinside.com 2019 - 2024. All rights reserved.