Community discussions

MikroTik App
 
Tarasin
just joined
Topic Author
Posts: 7
Joined: Thu May 27, 2021 7:53 pm

Access variable in execute

Tue Jun 22, 2021 4:02 pm

Hi,

I'm writing an update script that needs to check a parameter value on wlan interface. The problem is that, with a scheduler that runs on startup, the interface is not loaded yet. So, for performance reasons, instead of waiting x seconds, I decided to check if interface was loaded and wait until it loads. But when I do so, the script runs in 6.47.10 but not in 6.42 because the variable access seems different in the execute command.

Can someone solve the problem with that script or have any other way to wait until interface is fully loaded?
:global loaded false;
:execute ("
    :set \$loaded ([/interface wireless get wlan1 name] = \"wlan1\");");
:delay 1;
:put $loaded;
The thing is that when I use 6.47.10 the $loaded variable contains "false" but in 6.42 it contains nothing at all.

Thank you!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Access variable in execute

Tue Jun 22, 2021 4:07 pm

Is time to upgrade 6.42 (2018) full of "public backdoor", to 6.47.10

...for performance reasons,...
The solution is ":delay 10s", what performance are you talking about?

I do not like this script.
:global loaded false;
:execute ("
    :set \$loaded ([/interface wireless get wlan1 name] = \"wlan1\");");
:delay 1;
:put $loaded;
what does it mean?
Last edited by rextended on Tue Jun 22, 2021 4:21 pm, edited 2 times in total.
 
Tarasin
just joined
Topic Author
Posts: 7
Joined: Thu May 27, 2021 7:53 pm

Re: Access variable in execute

Tue Jun 22, 2021 4:19 pm

Yeah, I know it is time to upgrade. We are curently upgrading all our devices and that's why I'm builind this script.

The thing is that some equipment is old and other is not. If I just wait 4 seconds, some of them won't have loaded the interface yet and the script won't execute. If I wait too long, the updates will take forever. That's why I wanted performance.

Just waiting until something is up should be an easy task in a scripting language made for this type of equipment but it doesn't seem as it is.

I made a loop that checked for interface to be loaded and it seems it should work fine with newer versions (I did test the parts but not the whole thing yet) but if I can't use my script in older versions just because the execute command was not working the same way, that's quite an issue for MikroTik developers since making a "minor" release that breaks the past should not be done.

Yet thank you for your answer, I don't want to be disrespectful, just that I think this kind of "bug" is strange coming from something as great as MikroTik
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Access variable in execute

Tue Jun 22, 2021 4:21 pm

:while ([:len [/int wire find]] = 0) do={:delay 1s}
until the length of the search result of the wireless interfaces is 0, wait one more second

compatible on 6.x versions
Last edited by rextended on Tue Jun 22, 2021 4:28 pm, edited 2 times in total.
 
Tarasin
just joined
Topic Author
Posts: 7
Joined: Thu May 27, 2021 7:53 pm

Re: Access variable in execute

Tue Jun 22, 2021 4:26 pm

what does it mean?
This is just a part of the code (I wanted to put only the problem part to make it lighter). If you prefer, I have this solution :
:global loaded false;
:execute ("
    /interface wireless get wlan1;
    :set \$loaded true;");
:delay 1;
:put $loaded;
Or the full loop (just the interface load test part. It should be use with the update part) :
/system scheduler add disabled=no name="testInterface" \
    on-event=("
        :global loaded false;
        :while (!loaded) do={
            /log info \"Interface wlan1 not loaded yet\"
            :execute (\"
                /interface wireless get wlan1;
                :set \\$loaded true\");
                :delay 5;
        };
        /log warning \"Interface wlan1 loaded\"") \
    policy="write" start-time=startup;
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Access variable in execute

Tue Jun 22, 2021 4:27 pm

still prefer my simpler method...
Last edited by rextended on Tue Jun 22, 2021 4:30 pm, edited 2 times in total.
 
Tarasin
just joined
Topic Author
Posts: 7
Joined: Thu May 27, 2021 7:53 pm

Re: Access variable in execute

Tue Jun 22, 2021 4:30 pm

:while ([:len [/int wire find]] = 0) do={:delay 1s}
until the length of the search result of the wireless interfaces is 0, wait one more second

compatible on 6.x versions
Thank you for this. I did not think about checking the number of interfaces, just the interfaces themselves. This should do :)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Access variable in execute

Tue Jun 22, 2021 4:31 pm

When you ask for help, sometimes you actually ask for another point of view... ;)

Is also why OPEN software is better than CLOSED source...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Access variable in execute

Tue Jun 22, 2021 4:34 pm

Thank you for this. I did not think about checking the number of interfaces, just the interfaces themselves. This should do :)

WARNING: migrating from 6.42 to 6.47.10 destroy some wireless settings:
"antenna-gain", "frequency-mode", and "installation" change the behavior on how frequency and TX power are managed from radio!!!
before upgrading do some test for set the CPE to those values and apply the correct value after upgrade:

:if ( ([/int wire get wlan1 country] != "debug") ||
      ([/int wire get wlan1 frequency-mode] != "superchannel")
    ) do={/int wire set wlan1 country=debug frequency-mode=superchannel} 
Last edited by rextended on Tue Jun 22, 2021 4:43 pm, edited 1 time in total.
 
Tarasin
just joined
Topic Author
Posts: 7
Joined: Thu May 27, 2021 7:53 pm

Re: Access variable in execute

Tue Jun 22, 2021 4:43 pm

Thank you for this. I did not think about checking the number of interfaces, just the interfaces themselves. This should do :)

WARNING: migrating from 6.42 to 6.47.10 destroy some wireless settings:
"antenna-gain", "frequency-mode", and "installation" change the behavior on how frequency and TX power are managed from radio!!!
before upgrading do some test for set the CPE to those values and apply the correct value after upgrade:
:if  ( ( [ /int wire get wlan1 country ] != "debug" ) ||
      ( [ /int wire get wlan1 frequency-mode ] != "superchannel" )
         )  do={ /int wire set [find] country=debug frequency-mode=superchannel location=any }
I already knew for "Instalaltion" (that's why I made the post the other day) but I did not know for "antenna-gain" and "frequency-mode". I'll check for that and do some testing before going to production.

Thanks

Who is online

Users browsing this forum: No registered users and 34 guests