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
585 views 0 comments
by anonymous
Hello to all,

I have a script that informs me about status (rissing - falling) change of input-output ports. (something like "curl 'https://api.telegram.org/botXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXX/sendMessage?chat_id=-XXXXXXXXX&text=BATTERY24V-OK'"). It works, but can I pass other input/output statuses as text strings (i.e. voltage reading of analog input) when the script executes? Wiki is not so explenatory about the arguments field. (As an example something like curl 'https://api.telegram.org/botXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXX/sendMessage?chat_id=-XXXXXXXXX&text=BATTERY24V-OK, Pin1 Status-" + %g1 + ", Pin2 Status-" + %g2 + ", Analog Voltage-" + %g6 + "VDC."')

Thanks in advance

2 Answers

0 votes
by anonymous

Ok folks, here's how I solved the abovementioned issue.

a)Foolish me, I've never checked the script file using vi. By saving the script using notepad++ in M$ windows, ^M carriage return character was added in the end of each line (In notepad++ the correct filetype was selected "Unix Script File"). [See picture]

My solution: Edited the file with vi by removing the extra \cr character and the script started to run correctly. See also at the bottom of the screenshot for the filename (was "TestScript"). RUT955 stores the uploaded script files in weird places other than the usual. To discover where your uploaded script files are, in CLI or via SSH run:

find . -type f -name "*.sh"

from your root folder. You will see your uploaded scripts in two places. I've picked to edit the top one on the list. (Can't remember right now the correct path, sorry!)

b) Reading the I/O ports statuses and pass them as an argument. Now that was just trial and error. Long story short, RUT955 passes a single string argument to the script even if you type multiple arguments to the arguments field. It is still a single argument. And by that the solution was to write a quite long text, something like, "bla bla bla sensor A %g1 (High=On, Low=Off), other bla bla sensor B %g3 (High=On, Low=Off) and bla bla bla Voltage reading %g6VDC". It worked like a charm. Crude but charming. Why? Cause you can't manipulate the returned I/O ports readings and place them in the Telegram text body as you like. Also as you can see in the picture the text argument in the script is just {$1} which simply means "the first argument" that was passed to the script from RUT995. I'm sure there is a limit to the string length but haven't found it yet. I leave that to the bold ones to discover.

Hope I've helped someone