MQTT互动

本示例介绍了如何使用SmartNode通过MQTT进行互动,比如通过MQTT发送How are you的信息。

SmartNode中用到的node有:注入节点、MQTT输入节点、MQTT输出节点、调试节点。

程序设计如下:

13

相关节点的配置如下:

14

单击“Broker”右侧的按钮即可输入mqtt.smartnode.io,默认端口设置为1883。

15

 

16

17

单击“Broker”右侧的按钮即可输入mqtt.smartnode.io,默认端口设置为1883。通过设置MQTT节点的“broker”和“主题”就可以将两个节点间进行通信,需要注意的是,MQTT输入和MQTT输出需要保持同一个主题。

 

配置完成后,点击右上角的部署(Deploy)按钮,便可看到“MQTT输入”节点与“MQTT输出”节点已成功连接。单击注入节点,便可在调试窗口看到我们所发送的消息啦!

整个程序的json代码如下:

[{“id”:”88f6398a.7709c8″,”type”:”mqtt-broker”,”z”:”e2987d3.f1d678″,”broker”:”mqtt.smartnode.io”,”port”:”1883″,”clientid”:””,”usetls”:false,”verifyservercert”:true,”compatmode”:true,”keepalive”:”15″,”cleansession”:true,”willTopic”:””,”willQos”:”0″,”willRetain”:”false”,”willPayload”:””,”birthTopic”:””,”birthQos”:”0″,”birthRetain”:”false”,”birthPayload”:””},{“id”:”89efc522.761038″,”type”:”mqtt in”,”z”:”e2987d3.f1d678″,”name”:””,”topic”:”ZJY”,”broker”:”88f6398a.7709c8″,”x”:280,”y”:313,”wires”:[[“499952ee.b666ac”]]},{“id”:”9f8e2ce6.6071d”,”type”:”mqtt out”,”z”:”e2987d3.f1d678″,”name”:””,”topic”:”ZJY”,”qos”:””,”retain”:””,”broker”:”88f6398a.7709c8″,”x”:483,”y”:368,”wires”:[]},{“id”:”499952ee.b666ac”,”type”:”debug”,”z”:”e2987d3.f1d678″,”name”:””,”active”:true,”console”:”false”,”complete”:”payload”,”x”:484,”y”:314,”wires”:[]},{“id”:”9b6c0413.6493f8″,”type”:”inject”,”z”:”e2987d3.f1d678″,”name”:””,”topic”:””,”payload”:”How are you?”,”payloadType”:”string”,”repeat”:””,”crontab”:””,”once”:false,”x”:323,”y”:368,”wires”:[[“9f8e2ce6.6071d”]]}]

跳至工具栏