Page 1 of 1

Status on CodeDevice

Posted: 20 Dec 2015 18:44
by Emilp
Hi,

I can“t figure out what to write to get the correct status on my switchBinary CodeDevice.
I have a shellscript turntv.sh with different inputs turns my tv on or off. I use it in Code Device like system("/opt/scripts/turntv.sh on").
The problem is that the device always shows it as off. If i run the script in shell it will echo on or off. I also have a status parameter that returns on or off but the device always shows off.

Can someone push me in the right direction here?

Re: Status on CodeDevice

Posted: 21 Dec 2015 13:36
by Guenter
what you echo inside the script will be printed to stdout, but is not the result value of the 'system' call.
you can use the exit code inside the script, e.g call 'exit 0' for 'on' and 'exit 1' for 'off' and let the CodeDevice do the rest:
system('/path/to/script')[0]==0 ? 'on' : 'off'

( I am new to JavaScript, so don't ask me why this system call returns an array )

Re: Status on CodeDevice

Posted: 21 Dec 2015 14:52
by Guenter
just tested the system call using the second array element, which seems to contain the Output of the script:

Code: Select all

system('/path/to/script')[1]
in this case you should avoid printing the newline at the end, like:

Code: Select all

echo -n on

Re: Status on CodeDevice

Posted: 21 Dec 2015 22:40
by Emilp
Adding [0]==0 ? 'on' : 'off' after calling the script did the trick! Big thank you Guenter!