2020年10月17日 星期六

Node-RED選一位您心目中理想的班長

 Node-RED選一位您心目中理想的班長






<!DOCTYPE html>

<html>

<body>


<p>選一位您心目中理想的班長</p>


<form action="/count">

   <input type="radio" name="name" value="王小明" checked> 王小明<br>

  <input type="radio" name="name" value="李大大"> 李大大<br>

  <input type="radio" name="name" value="黃芬芳"> 黃芬芳  

  <br><br>

  <input type="submit">

</form>

</body>

</html>


Node-Red程式


[{"id":"e2cde4f0.65f098","type":"http in","z":"c609dc25.1d079","name":"","url":"/form","method":"get","swaggerDoc":"","x":140,"y":60,"wires":[["bee5aad5.2baed8"]]},{"id":"bee5aad5.2baed8","type":"template","z":"c609dc25.1d079","name":"選班長網頁","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<!DOCTYPE html>\n<html>\n<body>\n\n<p>選一位您心目中理想的班長</p>\n\n<form action=\"/count\">\n  <input type=\"radio\" name=\"name\" value=\"王小明\" checked> 王小明<br>\n  <input type=\"radio\" name=\"name\" value=\"李大大\"> 李大大<br>\n  <input type=\"radio\" name=\"name\" value=\"黃芬芳\"> 黃芬芳  \n  <br><br>\n  <input type=\"submit\">\n</form>\n\n</body>\n</html>","x":290,"y":60,"wires":[["9824c788.812a58"]]},{"id":"9824c788.812a58","type":"http response","z":"c609dc25.1d079","name":"","x":430,"y":60,"wires":[]},{"id":"f34f0dab.29985","type":"http in","z":"c609dc25.1d079","name":"","url":"/count","method":"get","swaggerDoc":"","x":147.29998779296875,"y":168.0600128173828,"wires":[["985d38fc.fa7978","a7c84ac6.83d8e8","975bf3b8.257e1"]]},{"id":"32cca0b4.1bf19","type":"http response","z":"c609dc25.1d079","name":"","x":611.2999877929688,"y":167.9499969482422,"wires":[]},{"id":"d4d8802a.e1c37","type":"template","z":"c609dc25.1d079","name":"唱票","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"\n<!DOCTYPE html>\n<html>\n<body>\n<h1>Thank you</h1>\n\n<p1>您投了 {{payload}} 一票</p1>\n</body>\n</html>\n","x":436.4799499511719,"y":167.88002014160156,"wires":[["32cca0b4.1bf19"]]},{"id":"985d38fc.fa7978","type":"debug","z":"c609dc25.1d079","name":"count in","active":true,"console":"false","complete":"payload","x":313.6199951171875,"y":226.0900115966797,"wires":[]},{"id":"975bf3b8.257e1","type":"function","z":"c609dc25.1d079","name":"累計票數","func":"\nvar d1=0;\nvar d2=0;\nvar d3=0;\n\n\n// Counter to select from array.\nvar counter1 = context.get('counter1')||0;\nvar counter2 = context.get('counter2')||0;\nvar counter3 =context.get('counter3')||0;\n\nif(msg.payload.name==\"王小明\")\n{\nd1=1;\n}\nelse if(msg.payload.name==\"李大大\")\n{\nd2 =1;\n}\nelse\n{\nd3 =1;\n}\n\ncounter1 = counter1+d1;\ncounter2 = counter2+d2;\ncounter3 = counter3+d3;\n\n \ncontext.set('counter1',counter1);\ncontext.set('counter2',counter2);\ncontext.set('counter3',counter3);\n \n\ncontext.global.cou1=counter1;\ncontext.global.cou2=counter2;\ncontext.global.cou3=counter3;\n\nmsg.payload=\n  {      \"cou1\":counter1,\n         \"cou2\":counter2,\n         \"cou3\":counter3\n  };\n\n\n\nreturn msg;\n\n\n \n","outputs":1,"noerr":0,"x":320,"y":280,"wires":[["def84fa4.1e0e4"]]},{"id":"def84fa4.1e0e4","type":"debug","z":"c609dc25.1d079","name":"count result","active":true,"console":"false","complete":"payload","x":490,"y":300,"wires":[]},{"id":"a962c3c1.d953a","type":"inject","z":"c609dc25.1d079","name":"","repeat":"6","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":160,"y":400,"wires":[["184dd6e0.9674d9"]]},{"id":"184dd6e0.9674d9","type":"function","z":"c609dc25.1d079","name":"產生資料陣列","func":"var msg1={};\nvar msg2={};\nvar msg3={};\n\nmsg1.topic=\"王小明\";\nmsg1.payload=context.global.cou1;\n\nmsg2.topic=\"李大大\";\nmsg2.payload=context.global.cou2;\n\nmsg3.topic=\"黃芬芳\";\nmsg3.payload=context.global.cou3;\n\nreturn [msg1, msg2,msg3];","outputs":"3","noerr":0,"x":360,"y":400,"wires":[["dc902edb.a2367","edf2c52d.674698"],["dc902edb.a2367","edf2c52d.674698"],["dc902edb.a2367","edf2c52d.674698"]]},{"id":"dc902edb.a2367","type":"ui_chart","z":"c609dc25.1d079","name":"長條圖","group":"526a8fb9.7ee9e","order":0,"width":0,"height":0,"label":"chart","chartType":"bar","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":550,"y":360,"wires":[[]]},{"id":"a7c84ac6.83d8e8","type":"function","z":"c609dc25.1d079","name":"監票","func":"\nmsg.payload=msg.payload.name;\nreturn msg;","outputs":1,"noerr":0,"x":305,"y":168.5600128173828,"wires":[["d4d8802a.e1c37","3ce8546c.9dc0fc","94e7a04f.58a12"]]},{"id":"edf2c52d.674698","type":"ui_chart","z":"c609dc25.1d079","name":"圓餅圖","group":"526a8fb9.7ee9e","order":0,"width":0,"height":0,"label":"chart","chartType":"pie","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":550,"y":460,"wires":[[]]},{"id":"c3cb8d14.1e842","type":"ui_audio","z":"c609dc25.1d079","name":"","group":"526a8fb9.7ee9e","voice":"zh-TW","always":false,"x":680,"y":220,"wires":[]},{"id":"5db3e780.808b88","type":"debug","z":"c609dc25.1d079","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":260,"wires":[]},{"id":"3ce8546c.9dc0fc","type":"function","z":"c609dc25.1d079","name":"監票","func":"\nvar st1= '您投了';\nvar st2= '一票';\nvar sr3= msg.payload;\n\nmsg.payload=st1+msg.payload+st2;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":220,"wires":[["c3cb8d14.1e842","5db3e780.808b88"]]},{"id":"94e7a04f.58a12","type":"debug","z":"c609dc25.1d079","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":120,"wires":[]},{"id":"526a8fb9.7ee9e","type":"ui_group","z":"","name":"Default","tab":"acb498da.72f338","order":1,"disp":true,"width":"6"},{"id":"acb498da.72f338","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...