2024年1月30日 星期二

Node-Red MQTT基本實驗

  Node-Red MQTT基本實驗








ON Bouuton 節點

Payload : on

OFF Bouuton 節點

Payload : off

MQTT out節點

Server :broker.hivemq.com : 1883

Qos=1  保留

發行主題 : alex9ufo/node-red/out

MQTT in節點

Server :broker.hivemq.com : 1883

Qos=1  保留

發行主題 : alex9ufo/node-red/out

Audio Out 節點

1.     Microsoft Yatinf—Chinese

Function 節點

var onoff=msg.payload;

 

if (onoff=="on")

{

    msg.payload=true;

}

if (onoff=="off")

{

    msg.payload=false;

return msg;

勤益科大 Bouuton 節點

Payload :  勤益科大

Hello  Bouuton 節點

Payload :  hello

MQTT out節點

Server :broker.hivemq.com : 1883

Qos=1  保留

發行主題 :  alex9ufo/esp32/hello

MQTT in節點

Server :broker.hivemq.com : 1883

Qos=1  保留

發行主題 : alex9ufo/esp32/hello

Text 節點

Label : 訂閱主題 :

Value format{{msg.payload}}

Layout: 上中

 


[{"id":"b3f8ec721059e777","type":"debug","z":"67d337ef020161d4","name":"debug 215","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":40,"wires":[]},{"id":"4c879d39eefe146b","type":"inject","z":"67d337ef020161d4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"30","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":60,"wires":[[]]},{"id":"23672f0f8e0ad12d","type":"function","z":"67d337ef020161d4","name":"模擬RFID UID","func":"const MIN = 0;\nconst MAX = 255;\nvar hex_v=0;\n//The maximum is exclusive and the minimum is inclusive\nfunction getRandomInt(min = MIN, max = MAX) {\n    min = Math.ceil(min);\n    max = Math.floor(max);\n    return Math.floor(Math.random() * (max - min)) + min;\n}\n\nfunction decToHex(dec) {\n  hex_v= dec.toString(16);\n  if(hex_v<10)\n  {\n    hex_v= '0'+hex_v;\n    }\n    return hex_v;\n}\n\nvar no1=getRandomInt(min = MIN, max = MAX);\nvar no2=getRandomInt(min = MIN, max = MAX);\nvar no3=getRandomInt(min = MIN, max = MAX);\nvar no4=getRandomInt(min = MIN, max = MAX);\nvar no5=getRandomInt(min = MIN, max = MAX);\nvar no6=getRandomInt(min = MIN, max = MAX);\nvar no7=getRandomInt(min = MIN, max = MAX);\nvar no8=getRandomInt(min = MIN, max = MAX);\nvar var1=decToHex(no1);\nvar var2=decToHex(no2);\nvar var3=decToHex(no3);\nvar var4=decToHex(no4);\nvar var5=decToHex(no5);\nvar var6=decToHex(no6);\nvar var7=decToHex(no7);\nvar var8=decToHex(no8);\n\nmsg.payload=[var1,var2,var3,var4,var5,var6,var7,var8];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":60,"wires":[["a0a0aebe98475ee0"]]},{"id":"a0a0aebe98475ee0","type":"function","z":"67d337ef020161d4","name":"整理輸出","func":"var temp=\"\";\nfor (var i = 0; i < msg.payload.length; i++) \n{\n    temp=temp+ \" \" + msg.payload[i];\n    temp=temp.toUpperCase();\n}\nmsg.payload=temp;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":60,"wires":[["b3f8ec721059e777","7cb46951e2242e13"]]},{"id":"7cb46951e2242e13","type":"mqtt out","z":"67d337ef020161d4","name":"node-red/RFID","topic":"alex9ufo/node-red/RFID","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"841df58d.ee5e98","x":660,"y":80,"wires":[]},{"id":"5985ccd980cadbc0","type":"mqtt in","z":"67d337ef020161d4","name":"node-red/out","topic":"alex9ufo/node-red/out","qos":"1","datatype":"auto-detect","broker":"841df58d.ee5e98","nl":false,"rap":true,"rh":0,"inputs":0,"x":550,"y":360,"wires":[["7d50813717d9c144","29cfb54d20b988ba"]]},{"id":"7d50813717d9c144","type":"function","z":"67d337ef020161d4","name":"function LED on ,off","func":"var onoff=msg.payload;\n\nif (onoff==\"on\")\n{\n    msg.payload=true;\n}\nif (onoff==\"off\")\n{\n    msg.payload=false;\n}  \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":340,"wires":[["ccb103c0fc516c71"]]},{"id":"ccb103c0fc516c71","type":"ui_led","z":"67d337ef020161d4","order":3,"group":"955405990ff40136","width":3,"height":3,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"false","valueType":"bool"},{"color":"#008000","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"","x":930,"y":340,"wires":[]},{"id":"cfd2998590e660dd","type":"ui_button","z":"67d337ef020161d4","name":"","group":"680cff3c5de3a744","order":3,"width":3,"height":1,"passthru":false,"label":"ON","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"on","payloadType":"str","topic":"topic","topicType":"msg","x":130,"y":340,"wires":[["3cbd0b17930c8655"]]},{"id":"5da71322cb4f139e","type":"ui_button","z":"67d337ef020161d4","name":"","group":"680cff3c5de3a744","order":5,"width":3,"height":1,"passthru":false,"label":"OFF","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"off","payloadType":"str","topic":"topic","topicType":"msg","x":130,"y":380,"wires":[["3cbd0b17930c8655"]]},{"id":"3cbd0b17930c8655","type":"mqtt out","z":"67d337ef020161d4","name":"node-red/out","topic":"alex9ufo/node-red/out","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"841df58d.ee5e98","x":310,"y":360,"wires":[]},{"id":"18f3c0d36c1ff134","type":"ui_button","z":"67d337ef020161d4","name":"","group":"680cff3c5de3a744","order":7,"width":3,"height":1,"passthru":false,"label":"hello","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"hello","payloadType":"str","topic":"topic","topicType":"msg","x":130,"y":540,"wires":[["e3c069f1897ee572"]]},{"id":"e3c069f1897ee572","type":"mqtt out","z":"67d337ef020161d4","name":"esp32/hello","topic":"alex9ufo/esp32/hello","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"841df58d.ee5e98","x":310,"y":540,"wires":[]},{"id":"3e679a331c7d78a1","type":"mqtt in","z":"67d337ef020161d4","name":"esp32/hello","topic":"alex9ufo/esp32/hello","qos":"1","datatype":"auto-detect","broker":"841df58d.ee5e98","nl":false,"rap":true,"rh":0,"inputs":0,"x":550,"y":540,"wires":[["a59845502a7ca7e7","998d7a289c204070"]]},{"id":"a59845502a7ca7e7","type":"ui_text","z":"67d337ef020161d4","group":"955405990ff40136","order":9,"width":0,"height":0,"name":"","label":"訂閱主題 : ","format":"{{msg.payload}}","layout":"row-left","className":"","x":730,"y":540,"wires":[]},{"id":"1336ba3046dc85e9","type":"ui_button","z":"67d337ef020161d4","name":"","group":"680cff3c5de3a744","order":9,"width":3,"height":1,"passthru":false,"label":"勤益科大","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"勤益科大","payloadType":"str","topic":"topic","topicType":"msg","x":140,"y":500,"wires":[["e3c069f1897ee572"]]},{"id":"29cfb54d20b988ba","type":"ui_audio","z":"67d337ef020161d4","name":"","group":"680cff3c5de3a744","voice":"Microsoft Yating - Chinese (Traditional, Taiwan)","always":"","x":720,"y":380,"wires":[]},{"id":"998d7a289c204070","type":"ui_audio","z":"67d337ef020161d4","name":"","group":"680cff3c5de3a744","voice":"Microsoft Yating - Chinese (Traditional, Taiwan)","always":"","x":720,"y":600,"wires":[]},{"id":"3002fa82da16e976","type":"ui_button","z":"67d337ef020161d4","name":"","group":"680cff3c5de3a744","order":1,"width":7,"height":1,"passthru":false,"label":"送RFID UID到MQTT Broker","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"on","payloadType":"str","topic":"topic","topicType":"msg","x":180,"y":120,"wires":[["23672f0f8e0ad12d"]]},{"id":"1bed4dee0d82ca96","type":"mqtt in","z":"67d337ef020161d4","name":"node-red/RFID","topic":"alex9ufo/node-red/RFID","qos":"1","datatype":"auto-detect","broker":"841df58d.ee5e98","nl":false,"rap":true,"rh":0,"inputs":0,"x":540,"y":180,"wires":[["0447f59735f86a0e","62bd73114746850a"]]},{"id":"0447f59735f86a0e","type":"ui_text","z":"67d337ef020161d4","group":"955405990ff40136","order":1,"width":0,"height":0,"name":"","label":"訂閱UID : ","format":"{{msg.payload}}","layout":"row-left","className":"","x":700,"y":180,"wires":[]},{"id":"62bd73114746850a","type":"ui_audio","z":"67d337ef020161d4","name":"","group":"680cff3c5de3a744","voice":"Microsoft Yating - Chinese (Traditional, Taiwan)","always":"","x":700,"y":240,"wires":[]},{"id":"841df58d.ee5e98","type":"mqtt-broker","name":"","broker":"broker.hivemq.com","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"955405990ff40136","type":"ui_group","name":"MQTT 回來的訊息","tab":"68b2e080d17dd8ac","order":2,"disp":true,"width":7,"collapse":false,"className":""},{"id":"680cff3c5de3a744","type":"ui_group","name":"到MQTT的訊息","tab":"68b2e080d17dd8ac","order":2,"disp":true,"width":"7","collapse":false,"className":""},{"id":"68b2e080d17dd8ac","type":"ui_tab","name":"LED","icon":"dashboard","order":1,"disabled":false,"hidden":false}]



沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...