Node-Red Dashboard + MongoDB
源自於 https://nodered-dashboards.gitbook.io/node-red-dashboards/workshop/historical-data-dashboard-example
http://alex9ufoexploer.blogspot.com/2021/01/node-red-mongodb.html
Node-Red程式
[{"id":"5d36769a.e6cf4","type":"inject","z":"6cdc3f3d.d9bdd8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"4","crontab":"","once":false,"onceDelay":"","topic":"","payloadType":"date","x":110,"y":140,"wires":[["bbb082fc.9e1988"]]},{"id":"819d8419.7a4e68","type":"function","z":"6cdc3f3d.d9bdd8","name":"Random #s","func":"if( msg.payload === false ) {\n return null;\n}\nmsg.payload = Math.round(Math.random()*100);\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":140,"wires":[["eff8762c.c62588"]]},{"id":"72358503.9614fc","type":"ui_chart","z":"6cdc3f3d.d9bdd8","name":"Chart","group":"3364ba7.0c020c6","order":0,"width":0,"height":0,"label":"Random #","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"Querying Entropy","dot":false,"ymin":"0","ymax":"100","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"60","cutout":"","useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":270,"y":220,"wires":[[]]},{"id":"e00b5147.15ac5","type":"ui_gauge","z":"6cdc3f3d.d9bdd8","name":"Gauge","group":"3364ba7.0c020c6","order":0,"width":0,"height":0,"gtype":"gage","title":"Gauge","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":270,"y":260,"wires":[]},{"id":"e8152004.5f00d8","type":"ui_slider","z":"6cdc3f3d.d9bdd8","name":"","label":"Slider","group":"3364ba7.0c020c6","order":0,"width":0,"height":0,"passthru":true,"topic":"","min":0,"max":"100","step":"","x":270,"y":300,"wires":[[]]},{"id":"a41117fb.938838","type":"ui_text","z":"6cdc3f3d.d9bdd8","group":"3364ba7.0c020c6","order":0,"width":0,"height":0,"name":"","label":"Text","format":"{{msg.payload}}","layout":"row-spread","x":270,"y":360,"wires":[]},{"id":"bbb082fc.9e1988","type":"ui_switch","z":"6cdc3f3d.d9bdd8","name":"","label":"Switch","tooltip":"","group":"1153ee5f.3a519a","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","topicType":"str","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":true,"className":"","x":270,"y":140,"wires":[["819d8419.7a4e68"]]},{"id":"d92f2cb5.84712","type":"function","z":"6cdc3f3d.d9bdd8","name":"Time Series DB","func":"return {\n payload: {\n time: new Date().getTime(),\n data: msg.payload\n }\n};","outputs":1,"noerr":0,"x":160,"y":500,"wires":[["fefdde6e.cfb36","1fc7330cb40663ee","9de5e9f52cfa5240"]]},{"id":"fefdde6e.cfb36","type":"function","z":"6cdc3f3d.d9bdd8","name":"Modulo","func":"var splitdata = msg.payload.time % 3;\nif( splitdata === 0 ) {\n return [msg, null, null];\n} \nelse if( splitdata == 1 ) {\n return [null, msg, null];\n} \n\nelse if( splitdata == 2) {\n return [null, null, msg];\n}\nreturn [null, null, null];","outputs":"3","noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":580,"wires":[["0219239f76971c1d","443519c50752b1d3"],["ca75cd248175e232","09e9a474d76079e2"],["0784a8710acdd5d9","2b5676668f8d12f8"]]},{"id":"de273cc6.72ece8","type":"ui_text","z":"6cdc3f3d.d9bdd8","group":"1153ee5f.3a519a","order":1,"width":"8","height":"3","name":"","label":"","format":"{{msg.payload}}","layout":"row-spread","className":"","x":270,"y":60,"wires":[]},{"id":"36b7dc98.607674","type":"inject","z":"6cdc3f3d.d9bdd8","name":"Instructions","repeat":"","crontab":"","once":true,"topic":"","payload":"Use the toggle switch to start / stop the generation of random numbers","payloadType":"str","x":110,"y":60,"wires":[["de273cc6.72ece8","ab35e9af296c45b4"]]},{"id":"84a5e84f.487ce","type":"ui_toast","z":"6cdc3f3d.d9bdd8","position":"top right","displayTime":"5","highlight":"","outputs":0,"ok":"OK","cancel":"","topic":"","name":"","x":700,"y":400,"wires":[]},{"id":"f77274f8.9d7e48","type":"switch","z":"6cdc3f3d.d9bdd8","name":"Warn on High Values","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"80","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":320,"y":400,"wires":[["59e04d02.276edc"]]},{"id":"59e04d02.276edc","type":"template","z":"6cdc3f3d.d9bdd8","name":"Alert Msg","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Alert : Critical Value Detected {{payload}}","output":"str","x":520,"y":400,"wires":[["84a5e84f.487ce"]]},{"id":"eff8762c.c62588","type":"link out","z":"6cdc3f3d.d9bdd8","name":"","links":["13ea2af3.d58b6d"],"x":555,"y":140,"wires":[]},{"id":"13ea2af3.d58b6d","type":"link in","z":"6cdc3f3d.d9bdd8","name":"","links":["eff8762c.c62588"],"x":95,"y":260,"wires":[["72358503.9614fc","e00b5147.15ac5","e8152004.5f00d8","a41117fb.938838","f77274f8.9d7e48","d92f2cb5.84712"]]},{"id":"0219239f76971c1d","type":"mongodb out","z":"6cdc3f3d.d9bdd8","mongodb":"5a50c348a5b4b2e6","name":"","collection":"No1","payonly":false,"upsert":false,"multi":false,"operation":"insert","x":580,"y":540,"wires":[]},{"id":"ca75cd248175e232","type":"mongodb out","z":"6cdc3f3d.d9bdd8","mongodb":"5a50c348a5b4b2e6","name":"","collection":"No2","payonly":false,"upsert":false,"multi":false,"operation":"insert","x":580,"y":580,"wires":[]},{"id":"0784a8710acdd5d9","type":"mongodb out","z":"6cdc3f3d.d9bdd8","mongodb":"5a50c348a5b4b2e6","name":"","collection":"No3","payonly":false,"upsert":false,"multi":false,"operation":"insert","x":580,"y":620,"wires":[]},{"id":"1fc7330cb40663ee","type":"mongodb out","z":"6cdc3f3d.d9bdd8","mongodb":"5a50c348a5b4b2e6","name":"","collection":"RandomNo","payonly":false,"upsert":true,"multi":true,"operation":"insert","x":400,"y":500,"wires":[]},{"id":"9de5e9f52cfa5240","type":"debug","z":"6cdc3f3d.d9bdd8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":370,"y":440,"wires":[]},{"id":"ab35e9af296c45b4","type":"debug","z":"6cdc3f3d.d9bdd8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":300,"y":100,"wires":[]},{"id":"443519c50752b1d3","type":"debug","z":"6cdc3f3d.d9bdd8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":540,"wires":[]},{"id":"09e9a474d76079e2","type":"debug","z":"6cdc3f3d.d9bdd8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":580,"wires":[]},{"id":"2b5676668f8d12f8","type":"debug","z":"6cdc3f3d.d9bdd8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":620,"wires":[]},{"id":"3364ba7.0c020c6","type":"ui_group","z":"6cdc3f3d.d9bdd8","name":"Dashboard Controls","tab":"df1d3372.200e","order":2,"disp":true,"width":"10","collapse":false,"className":""},{"id":"1153ee5f.3a519a","type":"ui_group","name":"Start / Stop","tab":"df1d3372.200e","order":1,"disp":true,"width":"8","collapse":false,"className":""},{"id":"5a50c348a5b4b2e6","type":"mongodb","hostname":"127.0.0.1","topology":"direct","connectOptions":"","port":"27017","db":"Dashboard","name":"Dashboard"},{"id":"df1d3372.200e","type":"ui_tab","z":"6cdc3f3d.d9bdd8","name":"Introduction","icon":"dashboard","order":2}]
沒有留言:
張貼留言