• V
 

设置已发布消息的主题

问题

您希望动态设置已发布 MQTT 消息的主题。

解决方案

在将消息发送到 MQTT Output 节点之前,设置 topic 消息属性。

示例

[{"id":"73abc692.bb3838","type":"mqtt out","z":"eda2a949.74ea98","name":"","topic":"","qos":"","retain":"","broker":"61de5090.0f5d9","x":410,"y":300,"wires":[]},{"id":"ef5a01ee.a940d","type":"inject","z":"eda2a949.74ea98","name":"kitchen temperature","topic":"sensors/kitchen/temperature","payload":"22","payloadType":"num","repeat":"","crontab":"","once":false,"x":250,"y":300,"wires":[["73abc692.bb3838"]]},{"id":"61de5090.0f5d9","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

在此示例中,Inject 节点设置了 msg.topic,但您不一定总是需要使用注入节点来完成此操作。

讨论

确保 MQTT Output 配置对话框中的 Topic 字段留空,以便使用 topic 消息属性。