Blank radio name in script

Hi All,

I’m tring to write a script like this :

# set variables
#
:global currentRN [/interface wireless registration-table get number=0 value-name=radio-name]
:global preferredAP [/interface wireless connect-list get number=0 value-name=ssid]
log warning message="Check AP connection vs. Connect List"
#
:if ([$currentRN] = [$preferredAP]) do={/log warning message="Correct AP"} else={/interface wireless enable wlan1;/log error message="Wrong AP, restarting wlan1"} 
#
/log info message="end script"

I need to check if my CPE is connected to preferred AP (the first in the connect-list); if yes nothing to do; if no the wlan is restarted to connect to first AP in the list.
This behavior is useful if the main AP in down for maintenance or outage and the CPE is connected to slave AP; but when the main AP return UP the same CPE, after a check (scheduled at 3.00 o’clock every day), must to back to correct AP.

The script don’t work because after the first run time, the radio-name came back without any value;
in fact if you enter:

:put [/in wireless registration-table get number=0 value-name=radio-name]

the return value is blank;

to have again the radio-name value you must enter this command:

/in wireless registration-table print

only after last print command, the previous return the correct value.

The ROS version is the 6.4

I hope to explain my need correctly.

It’s better to use [find] because it doesn’t depend on the number. For example, you could use the MAC or comment to target that CPE.
:global currentRN [/interface wireless registration-table get [find mac-address=“00:0C:42:00:00:00”] radio-name]
:global preferredAP [/interface wireless connect-list get [find comment=“myComment”] value-name=ssid]

Hello Skot,
thank you for your reply!

Your suggestion for “preferredAP” and command find vs. comment is valid!

For “currentRN” if I use find command vs. mac address and that AP goes down, if I go to change it, the find command to search that mac address is not longer valid.
I am forced to change the mac address in the script for hundred of CPE.

In my opinion the currentAP search must be dynamic!

Have you any other idea ?

Thank you, regards, Francesco.

If you do the print command before setting each variable, does this work?
/interface wireless registration-table print
:global currentRN [/interface wireless registration-table get number=0 value-name=radio-name]
/interface wireless connect-list print
:global preferredAP [/interface wireless connect-list get number=0 value-name=ssid]

Yes, it is only required the registration table print command. The second global parameter doesn’t need nothing, it work howerver.
Thank you, Francesco.