2020年12月4日 星期五

Using the switch node to handle a JSON object

利用 開關節點處理Json物件


If you now go back to the HiveMQ input page and send the MQTT message {“analyze”:true, “value”:6}, you will see that the first (top) output is activated and the incoming messages is routed, or ‘switched’, to output 1. If you send the original message {“analyze”:false, “value”:10}, the switch node will activate output 2 and the original debug node will fire.


{"analyze": false , "value":70}

http://www.hivemq.com/demos/websocket-client/




{"analyze": true , "value": 20}

http://www.hivemq.com/demos/websocket-client/




[{"id":"995c991a.566ba8","type":"mqtt in","z":"2b3214e5.a3a7cc","name":"","topic":"alex9ufo/sensor1/outTopic","qos":"2","datatype":"auto","broker":"e4d9b72d.d14398","x":350,"y":180,"wires":[["ba25f21f.ffa71"]]},{"id":"ba25f21f.ffa71","type":"json","z":"2b3214e5.a3a7cc","name":"","property":"payload","action":"","pretty":false,"x":530,"y":180,"wires":[["9660236a.9c53d","1d645c6b.ebe424","aecc5427.7bfa98"]]},{"id":"9660236a.9c53d","type":"debug","z":"2b3214e5.a3a7cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":100,"wires":[]},{"id":"f55b4a38.72baf8","type":"mqtt out","z":"2b3214e5.a3a7cc","name":"","topic":"alex9ufo/sensor2/inTopic","qos":"1","retain":"","broker":"e4d9b72d.d14398","x":770,"y":360,"wires":[]},{"id":"1175a0c6.d4ca9f","type":"function","z":"2b3214e5.a3a7cc","name":"","func":"var outstr={\"analyze\": true ,\"value\":50};\nmsg.payload= outstr;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":360,"wires":[["4582efd.f2bb31"]]},{"id":"4582efd.f2bb31","type":"json","z":"2b3214e5.a3a7cc","name":"","property":"payload","action":"","pretty":false,"x":570,"y":360,"wires":[["f55b4a38.72baf8","3fb07ae9.09b6b6"]]},{"id":"19c954a9.3f835b","type":"inject","z":"2b3214e5.a3a7cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":360,"wires":[["1175a0c6.d4ca9f"]]},{"id":"3fb07ae9.09b6b6","type":"debug","z":"2b3214e5.a3a7cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":420,"wires":[]},{"id":"fc8bf9ea.d0bde8","type":"switch","z":"2b3214e5.a3a7cc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":240,"wires":[["7ae78527.7c838c","9a089abc.740618"],["3f794d9.0b3f8b2","70c4abed.4d5cd4"]]},{"id":"7ae78527.7c838c","type":"debug","z":"2b3214e5.a3a7cc","name":"","active":true,"console":"false","complete":"false","x":870,"y":220,"wires":[]},{"id":"3f794d9.0b3f8b2","type":"debug","z":"2b3214e5.a3a7cc","name":"","active":true,"tosidebar":true,"console":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":260,"wires":[]},{"id":"9a089abc.740618","type":"ui_led","z":"2b3214e5.a3a7cc","group":"57fb2f24.9f1f1","order":11,"width":"0","height":"0","label":"LED1","labelPlacement":"left","labelAlignment":"right","colorForValue":[{"color":"red","value":"false","valueType":"bool"},{"color":"green","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"name":"","x":850,"y":180,"wires":[]},{"id":"70c4abed.4d5cd4","type":"ui_led","z":"2b3214e5.a3a7cc","group":"57fb2f24.9f1f1","order":12,"width":"0","height":"0","label":"LED2","labelPlacement":"left","labelAlignment":"right","colorForValue":[{"color":"red","value":"false","valueType":"bool"},{"color":"green","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"name":"","x":850,"y":300,"wires":[]},{"id":"fee116dd.9f9388","type":"ui_gauge","z":"2b3214e5.a3a7cc","name":"","group":"57fb2f24.9f1f1","order":13,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"35","seg2":"75","x":830,"y":140,"wires":[]},{"id":"1d645c6b.ebe424","type":"function","z":"2b3214e5.a3a7cc","name":"","func":"msg.payload=msg.payload.value;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":710,"y":140,"wires":[["fee116dd.9f9388"]]},{"id":"aecc5427.7bfa98","type":"function","z":"2b3214e5.a3a7cc","name":"","func":"msg.payload=msg.payload.analyze;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":570,"y":240,"wires":[["fc8bf9ea.d0bde8"]]},{"id":"e4d9b72d.d14398","type":"mqtt-broker","z":"","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"57fb2f24.9f1f1","type":"ui_group","z":"","name":"ON OFF 1","tab":"6f605bb4.60a174","order":1,"disp":true,"width":"6","collapse":false},{"id":"6f605bb4.60a174","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...