@shrickus Thanks! You not only had the idea but did the work. You even picked up the corresponding change in JSONata. Well done.
@TotallyInformation These two flows are trivial cases where a change
node could easily replace a function
if it had access to node.status
.
[{"id":"8f20d429.7359b","type":"inject","z":"7925ee05.cefd08","name":"good request","topic":"","payload":"https://www.npmjs.com/package/node-red","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":130,"y":200,"wires":[["fef21224.b26d58"]]},{"id":"8d21f60d.734478","type":"http request","z":"7925ee05.cefd08","name":"","method":"GET","ret":"txt","url":"","tls":"","x":470,"y":220,"wires":[["7fc9ce30.aaf89"]]},{"id":"fef21224.b26d58","type":"change","z":"7925ee05.cefd08","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":220,"wires":[["8d21f60d.734478"]]},{"id":"4aa8135e.14befc","type":"inject","z":"7925ee05.cefd08","name":"bad request","topic":"","payload":"https://www.npmjs.com/package/node-blue","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":130,"y":240,"wires":[["fef21224.b26d58"]]},{"id":"7fc9ce30.aaf89","type":"function","z":"7925ee05.cefd08","name":"status","func":"node.status({shape:'dot',text:msg.statusCode,fill:msg.statusCode == 200 ? 'green' : 'red'});\nmsg.status = (msg.statusCode == 200) ? 'nr-dashboard-ok' : 'nr-dashboard-error';\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":220,"wires":[["1ab61b19.a324b5"]]},{"id":"1ab61b19.a324b5","type":"ui_text","z":"7925ee05.cefd08","group":"172cda24.4d5896","order":1,"width":"6","height":"1","name":"","label":"Server","format":"<i class=\"fa fa-circle fa-1x {{msg.status}}\"></i>","layout":"row-left","x":730,"y":220,"wires":[]},{"id":"28159810.7a6338","type":"exec","z":"7925ee05.cefd08","command":"","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":290,"y":320,"wires":[["d0029500.0ab12"],[],[]]},{"id":"28be5199.02b4de","type":"inject","z":"7925ee05.cefd08","name":"good command","topic":"","payload":"cd /usr","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":300,"wires":[["28159810.7a6338"]]},{"id":"5212b0e4.e9e73","type":"inject","z":"7925ee05.cefd08","name":"bad command","topic":"","payload":"cd /foo","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":340,"wires":[["28159810.7a6338"]]},{"id":"d0029500.0ab12","type":"function","z":"7925ee05.cefd08","name":"rc","func":"node.status({shape:'dot',text:msg.rc.message,fill:msg.rc.code === 0 ? 'green' : 'red'});\nmsg.status = (msg.rc.code === 0) ? 'nr-dashboard-ok' : 'nr-dashboard-error';\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":320,"wires":[["1fc2a24b.d9d04e"]]},{"id":"1fc2a24b.d9d04e","type":"ui_text","z":"7925ee05.cefd08","group":"172cda24.4d5896","order":2,"width":"6","height":"1","name":"","label":"OS","format":"<i class=\"fa fa-circle fa-1x {{msg.status}}\"></i> {{msg.rc.message}}","layout":"row-left","x":550,"y":320,"wires":[]},{"id":"172cda24.4d5896","type":"ui_group","z":"","name":"","tab":"8ab9a99d.fc461","disp":true,"width":"6","collapse":false},{"id":"8ab9a99d.fc461","type":"ui_tab","z":"7925ee05.cefd08","name":"Server","icon":"dashboard","order":4}]
Better examples would use node.log
or node.warn
, but the ones in my code are difficult to simplify. You get the idea, and as I said, it's not a big deal. To be honest, I raised the question of node.status
in an earlier discussion and ended by agreeing with Dave that the function
node was the right way to go.