Community discussions

MikroTik App
 
npongracic
just joined
Topic Author
Posts: 3
Joined: Wed May 18, 2016 1:27 am

Winbox Wireless Scan/Connect with API

Wed May 18, 2016 1:33 am

Hello all,
I'm kind of a begginer in this MikroTik scripting world but i would like to be able to replicate Winbox's functionality, that is:
Wireless Scanner -> get a list of SSIDs, select one and click Connect and the SSID is set for wlan1.

I've tried using this:
var commands = new List<string>() {
"/interface/wireless/set",
"=.id=wlan1",
"=address=" + ap.Address,
"=ssid=" + ap.SSID,
"=channel=" + ap.Channel,
"=radio-name=" + ap.RadioName
};

if(ap.SNR.HasValue)
{
commands.Add("=snr=" + ap.SNR.ToString());
}

if (ap.Signal.HasValue)
{
commands.Add("=sig=" + ap.Signal.ToString());
}

if (ap.NF.HasValue)
{
commands.Add("=nf=" + ap.NF.ToString());
}

//if(!string.IsNullOrWhiteSpace(ap.Section))
//{
// commands.Add("=.section=" + ap.Section);
//}
// End sentence

But i don't see it doing anything. Not sure if it this is even valid code or api commands.
Does it have something to do with connect-list?

I'm sorry if this question has been asked and answered before, i've tried searching but couldn't find anything.
Thank you!
 
npongracic
just joined
Topic Author
Posts: 3
Joined: Wed May 18, 2016 1:27 am

Re: Winbox Wireless Scan/Connect with API

Wed May 18, 2016 11:54 pm

I did it :)
The problem was i ran interface/wireless/scan command before to get the list of SSIDs.
This continued working in the background and it (probably) kept messing up my communication with the api.

So i had to run Write("/cancel"); Read(); before doing:
var commands = new List<string>() {
"/interface/wireless/set",
"=ssid=" + ap.SSID,
"=.id=wlan1",
};

await Write(commands);
var data = await Read();

Also i thing that "=.id=wlan1" has to come last after all the other commands.
Hope it helps!

Kind regards,
 
santolag
just joined
Posts: 2
Joined: Thu Jul 21, 2016 8:57 am

Re: Winbox Wireless Scan/Connect with API

Wed Jul 27, 2016 11:20 am

Hi,

Can I see your whole source code?
I'm doing something similar to your code,
or just email to me @ martin_kolsawala94@yahoo.com
your code will be a huge help.

Thanks,