local variable ssid scan

Hello, I would like to scan networks in the background and develop actions based on the networks found.

I can’t save the ssids found in the scan into a variable.

I attach the script

:foreach result in=([/interface wireless scan [find name=wlan1] background=yes duration=8]) do={
    :local ssid [/interface wireless get $result ssid]
    :put $ssid
    :log info ("Rete trovata: " . $ssid)
    }

A rule of the thumb (not necessarily applying in this particular case) Is to never use as variable names that are used by the OS .
Try using “myssid” instead, as “ssid” may be “reserved”.

@abbio90
1st - issue is that as-value is missing for wireless scan command used in :foreach and you don’t need to use find command, just put interface name as argument:

:foreach result in=([/interface wireless scan wlan1 background=yes duration=8 as-value]) do={
...

2nd - what you are trying to achieve with:

:local ssid [/interface wireless get $result ssid]

You want to find wireless interface with same SSID from scan result?
If you want to just assign to variable scanned SSID value use:

:local ssid ($result->"ssid")

This will get SSID value from $result key-value array by using “ssid” string as key and assign it to ssid variable. Also I agree with @jaclaz to avoid using variable names in script with same name as keys or command properties, but in this case it will work.

To see which are other available keys (like address, channel, security…) in scan $result key-value array variable add in :foreach code block:

:put $result