I am trying to write a function to examine the status of a ui_switch and an http request to control the switch depending if the msg.payload of the http request exists.
I am getting a function error. I have narrowed it down to something related to the 'cli' variable.
When I look at the debug I see msg.payload with data. Here is the flow:
[{"id":"715afb2c.159e94","type":"http request","z":"e5f42280.90e5b","name":"GetClient","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":460,"y":260,"wires":[["c8e3d7b9.a16d48","8f2b0a81.6183d8"]]},{"id":"861598b8.a6e938","type":"status","z":"e5f42280.90e5b","name":"","scope":["d07f6cdd.fdc22"],"x":560,"y":320,"wires":[["8f2b0a81.6183d8"]]},{"id":"8f2b0a81.6183d8","type":"function","z":"e5f42280.90e5b","name":"","func":"var cli = flow.get(\"client\");\nvar sw = msg.status.text;\nif ((sw===undefined) && (cli===undefined)) //no client, radio off\n{\n return null;\n}\nif ((sw==='on') && (cli===undefined)) //no client, radio on\n{\n var swcontrol = {payload: 0}\n}\nif ((sw==='on') && (cli!==undefined)) // client on , radio on\n{\n return null; \n}\n\n// node.send({\"payload\":msg.status.text});\nreturn swcontrol;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":300,"wires":[["47cc81da.1660a"]]},{"id":"d07f6cdd.fdc22","type":"ui_switch","z":"e5f42280.90e5b","name":"","label":"<font size = 5> Flex 6400","tooltip":"","group":"e357ef02.ef3cb","order":1,"width":"6","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"fa-power-off fa-2x","oncolor":"lime","offvalue":"0","offvalueType":"num","officon":"fa-power-off fa-2x","offcolor":"gray","x":310,"y":360,"wires":[["d8545ad.2bbc9a8"]]},{"id":"d8545ad.2bbc9a8","type":"rpi-gpio out","z":"e5f42280.90e5b","name":"","pin":"7","set":true,"level":"0","freq":"","out":"out","x":740,"y":360,"wires":[]},{"id":"3ed530a6.cf73","type":"change","z":"e5f42280.90e5b","name":"getclientUrl","rules":[{"t":"set","p":"url","pt":"msg","to":"$globalContext(\"frstackurl\") & \"/Radio/CLIENT\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":280,"wires":[["715afb2c.159e94"]]},{"id":"434e0e28.56182","type":"inject","z":"e5f42280.90e5b","name":"3secs","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":80,"y":140,"wires":[["b313b612.ed68a8","b8326128.8410d","3ed530a6.cf73"]]},{"id":"e357ef02.ef3cb","type":"ui_group","z":"","name":"Radios","tab":"4bc17c6e.b74934","order":1,"disp":true,"width":"6","collapse":true},{"id":"4bc17c6e.b74934","type":"ui_tab","z":"","name":"Station","icon":"dashboard","order":6,"disabled":false,"hidden":false}]
Here is the function I have written. I am sure the problem will be something trivial. Thanks for the help on this...
var cli = flow.get("client");
var sw = msg.status.text;
if ((sw===undefined) && (cli===undefined)) //no client, radio off
{
return null;
}
if ((sw==='on') && (cli===undefined)) //no client, radio on
{
var swcontrol = {payload: 0}
}
if ((sw==='on') && (cli!==undefined)) // client on , radio on
{
return null;
}
// node.send({"payload":msg.status.text});
return swcontrol;