FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14455 questions

17168 answers

28195 comments

0 members

We are migrating to our new platform at https://community.teltonika.lt. Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
119 views 0 comments
by anonymous

Hello community.

I have a question about possibility to check TRB245 DI value status. Accroding to official documentation after ubus call ioman.gpio.dio1 status command executing we get next result:

{
        "value": "0",
        "direction": "in",
        "bi_dir": true,
        "invert_input": false
}

I want to get "value" property of this object. And then check it. If value is "1" - then switch on value DO0 (set as output). I mean something like this:

 if [ ioman.gpio.dio1.value = "1" ]; then
    ubus call ioman.gpio.dio0 update '{"value":"1"}'
fi

I know it is not correct synyax for if statement. But I did not find correct. What is correct syntax of above mentioned if statement? Actuallly  it is my first experience with Teltonika device. So, any information will be usefull for me.  

1 Answer

0 votes
by anonymous

Hello,

You can add additional options to the end of your ubus call ioman.gpio.dio1 status command filter/cut its output, so that only desired character would remain. E.g. ubus call ioman.gpio.dio1 status | grep "value" | cut -c 12 command would only print the input value (0 or 1). I.e. grep "value" option would only show the line of the value, while "cut -c 12" would print 12th character of this line, which is the exact value of the input.

Your "IF statement" syntax is mostly correct, you just need to use two equal signs when making a comparison, and "encapsulate" the desired command in the IF condition in $(...) characters (so that would treat it as an executable command, not as plain text)

Please try to use the following IF statement. It should work:
if [ $(ubus call ioman.gpio.dio1 status | grep "value" | cut -c 12) == "0" ]; then
        ubus call ioman.gpio.dio0 update '{"value":"1"}'
fi
Best answer