2023年11月4日 星期六

Node-Red 模擬 RFID UID產生器 暨 LED ON,OFF 接收器

 Node-Red 模擬 RFID UID產生器 暨 LED ON,OFF 接收器

1) 利用亂數產生器 產生8個 hex 碼 RFID UID code

    送給 broker.mqtt-dashboard.com : 1883  

     TOPIC :  alex9ufo/node-red/RFID

2) 接收 broker.mqtt-dashboard.com : 1883 ,  TOPIC :  alex9ufo/node-red/LED  payload: on , off 的訊息 並控制 Dashboard UI的LED節點

on 變成綠色LED , off 變成紅色LED 














[{"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":60,"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":120,"y":100,"wires":[["23672f0f8e0ad12d"]]},{"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":100,"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":100,"wires":[["b3f8ec721059e777","7cb46951e2242e13","87dde3dbd1fbfaa6"]]},{"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":"70940176.2b2d3","x":660,"y":120,"wires":[]},{"id":"5985ccd980cadbc0","type":"mqtt in","z":"67d337ef020161d4","name":"node-red/LED ","topic":"alex9ufo/node-red/LED ","qos":"1","datatype":"auto-detect","broker":"70940176.2b2d3","nl":false,"rap":true,"rh":0,"inputs":0,"x":110,"y":220,"wires":[["7d50813717d9c144"]]},{"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":310,"y":220,"wires":[["ccb103c0fc516c71"]]},{"id":"87dde3dbd1fbfaa6","type":"ui_text","z":"67d337ef020161d4","group":"680cff3c5de3a744","order":1,"width":0,"height":0,"name":"","label":"RFID UID","format":"{{msg.payload}}","layout":"row-left","className":"","x":660,"y":180,"wires":[]},{"id":"ccb103c0fc516c71","type":"ui_led","z":"67d337ef020161d4","order":1,"group":"680cff3c5de3a744","width":"6","height":"5","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":530,"y":220,"wires":[]},{"id":"70940176.2b2d3","type":"mqtt-broker","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":4,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":"","credentials":{}},{"id":"680cff3c5de3a744","type":"ui_group","name":"LED ON OFF","tab":"68b2e080d17dd8ac","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"68b2e080d17dd8ac","type":"ui_tab","name":"LED","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

沒有留言:

張貼留言

WOKWI DHT22 & LED , Node-Red + SQLite database

 WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...