Script to change channel widths on clients for 5.2?

I really wish I new how to script but I am just dangerous when I try.

I am looking for an updated script of the old one that used to change wireless mode "b/g/nstreme/ and channel widths that will work with 5.2. Now that 5.2 has the “any” mode all I need is a script that will change the channel widths. Anyone out there that could help me out or possibly modify the old script for me?

Here is the old script I was using


:local delais 5s
:local liste 2.4ghz-b/g,2ghz-5mhz,2ghz-10mhz;

:foreach band in=$liste do={
:if (![/interface wireless get wlan1 running]) do={
/interface wireless set wlan1 band=$band
:delay $delais
}
}

:if (![/interface wireless get wlan1 running])
do={
:if [/interface wireless nstreme get wlan1 enable-nstreme]
do={
/interface wireless nstreme set wlan1 enable-nstreme=no
} else={
/interface wireless nstreme set wlan1 enable-nstreme=yes
}
}


Thanks,
Chadd

I was running a similar script. I have tried to edit it, but I do not have the understanding of scripting to get it sorted. This is holding me back from v5.

Someone out there has to know…

Try this: It works for 5.4…

All this script does is to study the “running” status of the wlan1 interface, if the wlan looses connection (0) then the script will start to change bandwidths, firstly 5mhz. It will scan (whatever is in the scanlist or default), It will do this for 5 secs, then it will try the next bandwidth.

It will also put the mode to “any”.

I assume your need was the same as mine, and that was to defeat those customers who keep turning their units off at night, preventing us from working effectively on our networks, then the next day they bitch that they don’t have the internet!!

The script was hashed together the other day in order to help myself and Rudy whilst we experiment and change our networks from 20mhz bandwidths to 10 or 5mhz. Also god to put it into the clients cpe’s, since its a pain in the arse when a client turns off their cpe whilst we as admins are changing networks over..

The scheduler is initiated by boot.. And carries on running for 180 times, after which time it is disabled. (note that even after the next boot, the scheduler will remain disabled)

I added a second scheduler to re-enable the first scheduler from a reboot to overcome that.

Once the client cpe’s have re-established connection ( I assume after you have done your network experimentation, you can off course disable the scheduler/s and the script will be idle)

If you like you could use the “Identiity” field in the AP and have the cpe’s globally disable their schedulers, by adding a few lines to script to find this field and act accordingly!

In ALL the relevant cpe’s put this:

Call this script schedcheckWiFi

and paste this lot into the source box

:local count [/sys scheduler get 0 value-name=run-count]
:if (count>180) do= {/system scheduler disable 0}
:local delais 5s
:local liste 5mhz,10mhz,20mhz;
:foreach band in=$liste do={
:if (![/interface wireless get wlan1 running]) do={
/interface wireless set wlan1 channel-width=$band wireless-protocol=any
:delay $delais
}
}

Then you need to add a scheduler to call the script…



put this in the “on event box”

/system scheduler enable schedcheckWiFi


starttime = startup
interval 0


PS.. I don’t accept liabilty for errors and suggest you try it out on the workbench first, give Rudy a shout, he was also playing with the script, making it more tidy, and trying to do away with a second scheduler.. His posts are below and the title is like “getting a scheduler to run x times” or something like that… But it relates to exactly the same subject.

If this is not what you want, then get back to me with your requirements and I’ll have a fiddle, but I dont have too much time.

Regards

Simon

That looks good to me.

I am going to look at this and the script I have and see if I can get a better understanding.

Thanks!!

Oldman.

I re-read my post and its not 100% clear.

The script is fine, but the scheduler/s are not crystal clear.

I omitted the schedule which calls the script in the first place.

That is simple, it is initiated from a boot, then should run every 20 seconds.

Thus you see each channel width called after every 5 second pause, then a scan etc, until scheduler reaches 180. It is then disabled.. (some may not want it disabled!)

The scheduler in the former post, re-enables the 1st scheduler (after it has been disabled by the former script)

The problem we found, was that once the scheduler is disabled, it remains disabled, even after a re-boot.. Hence the second scheduler re-enabling it.

MAKE SURE THAT THE ORIGINAL SCHEDULER IS AT POSITION 0 and that the second (re-enabling scheduler is after it (in the list of schedulers))


For those people who arent bothered about the scheduler running every 20 seconds, and who would prefer to disable the script by logging into each cpe manually, then remove the FIRST 2 LINES of the script.

Good luck

Simon

I’ve got to stop and take some time to test this.

Between lightning and all sorts of other emergencies, I’ve been run ragged.

I’ve been working on this today, hit a bit of a problem.

I have a txt file, paste into a terminal to configure the CPE. I can’t seem to get this script to go in. I can manually create the script in Winbox, paste it into the script window and it works, but I can’t get it to work over terminal. I have this already working on v3 and v4, picked up the config from someone on this forum a couple of years ago.

/


/system script
add name="ChangeBand" source=":local count [/sys scheduler get 0 value-name=run-count]
:if (count>180) do= {/system scheduler disable 0}
:local delais 5s
:local liste 5mhz,10mhz,20mhz;
:foreach band in=$liste do={
:if (![/interface wireless get wlan1 running]) do={
/interface wireless set wlan1 channel-width=$band wireless-protocol=any
:delay $delais
}
}
" \
    on-event=ChangeBand start-time=startup
/system scheduler disable schedcheckWifi
/

my old working config

/


/system script
add name="ChangeBand" \
    source=":local delais 5s\r\n:local liste 2.4ghz-b/g,2ghz-5mhz,2ghz-10mhz;\r\n \
    \r\n:foreach band in=\$liste \
    do={\r\n:if (![/interface wireless get wlan1 running]) do={\r\n/interface \
    wireless set wlan1 band=\$band\r\n:delay \$delais\r\n}\r\n}\r\n\r\n:if \
    (![/interface wireless get wlan1 running]) \\\r\ndo={\r\n    :if \
    [/interface wireless nstreme get wlan1 enable-nstreme] \\\r\n    do={\r\n  \
          /interface wireless nstreme set wlan1 enable-nstreme=no\r\n    } \
    else={\r\n        /interface wireless nstreme set wlan1 \
    enable-nstreme=yes\r\n    }\r\n}"
/system scheduler
add comment="" disabled=no interval=20s name="schedcheckWifi" \
    on-event=ChangeBand start-time=startup
/system scheduler disable schedcheckWifi
/

Well, I edited the initial script that came to me by Simon into a very short version that suit my needs. The 5Ghz was eliminated and the wireless protocol was set to “nv2-nstreme-802.11”
After I changed all my networks into 10Mhz some months ago I actuall removed the scripts and scheduler from the CPE’s.
All I had left was the following code written on a piece of paper:

/name=“ChangeBand” owner=“admin”

paste the following text into the source window.
:local delais 5s
:local liste 5mhz,10mhz,20mhz;

:foreach band in=$liste do={
:if (![/interface wireless get wlan1 running]) do={
/interface wireless set wlan1 channel-width=$band wireless-protocol=nv2-nstreme-802.11
:delay $delais
}
}


/system script
add name=A policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=
“log info "Script A start"\r
\n:global counter\r
\n:set counter ($counter+1)\r
\n:if ($counter <= 5) do={/system script run B}\r
\n:log info "Script A end"”
add name=B policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=
“:global counter\r
\n:log info ("Script B run number:".$counter)”
add name=simulatereboot policy=
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=
“:global counter 0”
/system scheduler
add disabled=no interval=3s name=schedule2 on-event=A policy=
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=jun/17/2011
start-time=13:15:16

\

This one hereafter works continously:

/system script
add name=ChangeBand policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=“:local delais 5s\r
\n:local liste 10mhz,20mhz;\r
\n \r
\n:foreach band in=$liste do={\r
\n:if (![/interface wireless get wlan1 running]) do={\r
\n/interface wireless set wlan1 channel-width=$band wireless-protocol=nv2-nstreme-802.11\r
\n:delay $delais\r
\n}\r
\n}\r
\n”



If I remember well the counter didn’t work well. The script always worked. But it did do its job. Switching the bandwith on the AP made all clients to follow within some time.
The reason I removed the scripts later was when clients were for whatever reason disconnected from AP the sripts started to test and swap the bandwidths which cost them at times quit some time to come back on time. On marginal links (and at the time the disconnection issues with NV2) this was disrupting my whole network. (Because of the NV2 process).

But thanks Simon, for giving some credit to the mutual developed script.

OH, forgot to mention that the script should be tested first and that I cannot bear any responsibility for any failures. In fact I do remember the script was not perfect in all aspects…

/system script
add name=ChangeBand policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=":local delais 5s\r\
\n:local liste 5mhz,10mhz,20mhz;\r\
\n \r\
\n:foreach band in=\$liste do={\r\
\n:if (![/interface wireless get wlan1 running]) do={\r\
\n/interface wireless set wlan1 channel-width=\$band wireless-protocol=any\r\
\n:delay \$delais\r\
\n}\r\
\n}\r\
\n"
\

/system scheduler
add comment="" disabled=no interval=20s name="schedcheckWifi" \
    on-event=ChangeBand start-time=startup
/system scheduler disable schedcheckWifi
/

This is what I’m trying to get working now, but it will not connect to my AP after changes are made. I’ve made some changes back and forth and I think it may have gone back to almost exactly what you posted. Currently running 5Mhz 802.11. The CPE changes through 5MHz wide channel with the correct info too quickly then goes to 10MHz, 20MHz, just doesn’t scan long enough to find the AP.

I think I may have gotten it. The “local delais 5s” is how long to stay on a certain setting before it attempts another width, correct?

Yes that is the delay, I got everything working a while back but had to increase the delay also.

Chadd

Here is my final edit, building on what others have done before me. I do need to find out how to automate the HT extension channel for the future.

/system script
add name=ChangeBand policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=":local delais 10s\r\
\n:local liste 5mhz,10mhz,20mhz;\r\
\n \r\
\n:foreach band in=\$liste do={\r\
\n:if (![/interface wireless get wlan1 running]) do={\r\
\n/interface wireless set wlan1 channel-width=\$band wireless-protocol=any\r\
\n:delay \$delais\r\
\n}\r\
\n}\r\
\n"
\

/system scheduler
add comment="" disabled=no interval=20s name="schedcheckWifi" \
    on-event=ChangeBand start-time=startup
/system scheduler disable schedcheckWifi
/