我正在设置我的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文件来接收此消息。
您不能,除非您自己将消息添加到有效负载中,或者在将消息发布到的主题中,否则消息中没有编码的有关发件人的信息。