Hello ,
I’m having a strange problem with a script
when I run a it on the terminal or even as “Run Script” - it work just fine
but when I put it on scheduler once every 2 min I get en error
and if I run it after it manually - it work again
what could it be?
Thanks,
The “run” part is the oddest of them all… I mean, there’s some stuff that differs between scripts and terminal, for sure, but between scripts and scheduler scripts is new (for me at least).
What’s the source of the entire scheduler script? Is there a second scheduler script running at the same time (if so, it could be concurrency issues)?
no other script ,just this one run
my script is this:
receive a sms - see if he equal to a word and the, turn on LED
I can see that when it run on scheduler , it can’t get the $SmsMsg (it stay empty ) and doesn’t finish the script
:global msg1 "Open";
:global msg2 "Close";
;global DavidPhone "+912345676543";
:global NumberSms [/tool sms inbox print count-only];
delay 4;
if ($NumberSms!=0) do={
/tool sms set receive-enabled=yes;
:global SmsMsg [/tool sms inbox get value-name=message number=0];
delay 4;
:log warning "The SMS is - $SmsMsg";
:if ($SmsMsg=$msg1 ) do={beep length=1;/tool sms send usb2 phone-number=$DavidPhone message="$msg1";:log warning "$msg1"; /system leds set [find where leds=user-led] type=on} else={:if ($SmsMsg=$msg2) do={beep length=1;/tool sms send usb2 phone-number=$DavidPhone message="$msg2";:log warning "$msg2";system leds set [find where leds=led4] type=on;} else={:if ($SmsMsg="") do={} else={/tool sms send usb2 phone-number=$DavidPhone message="Unknown"; :log warning "Unknown SMS!"; blink duration=2}}};
delay 4;
/tool sms inbox remove numbers=0;
delay 2;
/system leds set [find where leds=user-led] type=off;
/system leds set [find where leds=led4] type=off;
:log warning "SMS Finish!";
} else={:log warning "No SMS Found :-( "};
this is the output when i run the script with scheduler :
23:53:11 script,warning The SMS is -
23:53:11 script,warning Unknown SMS!
and this is when I run it from terminal (manually):
23:53:42 script,warning The SMS is - Close
23:53:43 script,warning Close
23:53:43 system,info item changed by admin
23:53:49 system,info item changed by admin
23:53:49 script,warning SMS Finish!
maybe you can see something ?
Strange , no ?
Thanks ,
:global SmsMsg [/tool sms inbox get value-name=message number=0];
Never ever use numbers directly in ‘get’ statements, they are only meant for use in console (as returned from a print), in scripts you get the number with ‘find’. I’ll be happy to rewrite it for you if needed.
And here’s a tip - on the terminal,
/system script run 0
See if you get any error messages from running it that way. It’s helped me catch some syntax errors before.
(of course if your script is #17 then run 17 not 0.
)
o.k , I understand
but how can I do this ? how can I tell him to take only the first massage ?
I have try
[/tool sms inbox get value-name=message [find where message!=0]
but I get an error , also if there are 2 new SMS I will get an error
what do you think? , how can I make him take the first massage only?
Thanks ,
I rewrote it slightly, to make it more readable, but it should be fairly obvious to see what you need to change. I haven’t tried it, since I have no SMS device to try it out on. I don’t know what the delays are good for so i kept them, and not sure either what the set receive-enabled=yes; is good for, as I read the documentations, it has to be activate to receive SMSs in the first place, but again, I have never tried the SMS command set.
The key point is :local Sms [:pick [inbox find] 0]; which returns an index for the first entry, or nothing if none.
In the current form it will only process one message (if any) per run, it could easily be changes to run through all there are.
/tool sms {
:local msg1 "Open";
:local msg2 "Close";
:local DavidPhone "+912345676543";
:local Sms [:pick [inbox find] 0];
:delay 4;
:if ([:len $Sms] = 0) do={
:log warning "No SMS Found :-( "
} else={
set receive-enabled=yes;
:local SmsMsg [inbox get $Sms message];
:delay 4;
:log warning "The SMS is - $SmsMsg";
:if ($SmsMsg=$msg1) do={
:beep length=1;
send usb2 phone-number=$DavidPhone message="$msg1";
:log warning "$msg1";
/system leds set [find where leds=user-led] type=on
} else={
:if ($SmsMsg=$msg2) do={
:beep length=1;
send usb2 phone-number=$DavidPhone message="$msg2";
:log warning "$msg2";
/system leds set [find where leds=led4] type=on;
} else={
:if ($SmsMsg="") do={
} else={
send usb2 phone-number=$DavidPhone message="Unknown";
:log warning "Unknown SMS!";
:blink duration=2
}
}
};
:delay 4;
inbox remove $Sms;
:delay 2;
/system leds set [find where leds=user-led] type=off;
/system leds set [find where leds=led4] type=off;
:log warning "SMS Finish!";
}
}
EDIT: Fixed a == to =, this is not C
I understand what you said ,
but I get en error after using the
:pick
command
this is the what I wrote
:global SmsMsg [tool sms inbox $Sms massage];
but is doesn’t work
I’m sure its a syntax error
Thanks ,
Apart from the typo I just fixed, there shouldn’t be any syntax errors. If you have only cherry picked, then write the pick like this:
:local Sms [:pick [/tool sms inbox find] 0];
I understand my mistake
the syntax of the command was wrong
now it’s O.K.
Thanks ,