Community discussions

 
franaz
just joined
Topic Author
Posts: 8
Joined: Sat Nov 03, 2018 2:24 am

Quick help for short code line

Sun May 19, 2019 8:52 pm

hello to everyone here,

i would like to automatically switch off the wifi after a certain time at night if no user is connected anymore.
I inserted the following code (which btw I found in this forum) in the "on event" field of a schedule task but it's not working:

if ( ([/interface wireless monitor wlan1 as-value once]->"connected-clients")=0 ) do={/interface wireless disable wlan1}

I also tried with "authenticated-clients" and "registered-clients" but no one is doing the job. I guess I have an error in the code , so I would be very thankful if someone who is familiar with the script language could give a look!

(btw: the task to switch on the wifi in the morning is working fine which the following line: /interface wireless enable wlan1)
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 217
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Quick help for short code line

Mon May 20, 2019 4:47 am

:if ( [/interface wireless registration-table print as-value count-only]=0 ) do={/interface wireless disable wlan1} else={}
Last edited by ADahi on Thu May 23, 2019 2:51 am, edited 1 time in total.
 
franaz
just joined
Topic Author
Posts: 8
Joined: Sat Nov 03, 2018 2:24 am

Re: Quick help for short code line

Mon May 20, 2019 4:25 pm

unfortunately it's simply not working

I even tried with =1 (while I was the only connected) but no reaction

strangely (as it worked before!) this morning even the activation of the wifi did not work... morning for testing purpose then I set the interval to 1 minute and it worked. for my activation once a day I set the time to 09:00 and the interval to 00:00:00 as it is the 24 hours interval right?)
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 217
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Quick help for short code line

Tue May 21, 2019 2:18 am

interval should be "1d 00:00:00" to work properly
Last edited by ADahi on Thu May 23, 2019 2:53 am, edited 1 time in total.
 
franaz
just joined
Topic Author
Posts: 8
Joined: Sat Nov 03, 2018 2:24 am

Re: Quick help for short code line

Tue May 21, 2019 3:09 pm

Thanks for the hint with the 1d .... it works!!

Regarding the other code line there is something fundamentally wrong or at least strange!

It's only doing it's job if I put a ! in front of the =0, so !=0 (or whatever other number), for example:

if ( [(/interface wireless registration-table print as-value count-only)] !=0 ) do={/interface wireless disable wlan1} else={}
this disables the wifi whenever I'm connected or not!

if ( [(/interface wireless registration-table print as-value count-only)] !=1 ) do={/interface wireless disable wlan1} else={}
so with value 1 while I'm connected alone on the wifi it should not disable right? but it does so...

did you make tests on your own? maybe a bug in the software somehow?

thanks again a lot for your time!
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 217
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Quick help for short code line

Wed May 22, 2019 9:26 pm

=0 : mean false or wireless registration table is empty
both are same
other solutions
<=0 : mean less or equal zero
!=0 : mean any number except zero
!=1 : mean any number except one
>0 : mean greater than zero.
etc.
 
franaz
just joined
Topic Author
Posts: 8
Joined: Sat Nov 03, 2018 2:24 am

Re: Quick help for short code line

Wed May 22, 2019 9:34 pm

yes I know but thank you!

how come it's not working with =0 then??

can you test it please on your own mikrotik for a second?
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 217
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Quick help for short code line

Thu May 23, 2019 2:52 am

yes
problem fixed by remove ( ) from script
You do not have the required permissions to view the files attached to this post.
 
franaz
just joined
Topic Author
Posts: 8
Joined: Sat Nov 03, 2018 2:24 am

Re: Quick help for short code line

Fri May 24, 2019 11:16 pm

sorry I don get it...

a parte the additional code added there, the basic line is just the same... and ( ) still there...?!
 
franaz
just joined
Topic Author
Posts: 8
Joined: Sat Nov 03, 2018 2:24 am

Re: Quick help for short code line

Sun Jun 16, 2019 12:27 am

Anyone else could give me a short help?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1294
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Quick help for short code line

Sun Jun 16, 2019 12:33 pm

This script does work fin on my hap lite
:if ([/interface get  wlan1 disabled ]=false && [/interface wireless registration-table print as-value count-only]=0) do={
	:log info message="No more clients, shutting down interface"
	/interface wireless disable wlan1}
Schedule it to run every 5m and it should shutdown the interface after max 5 min of last client leaving.

PS I did add a test to see if interface was enabled. No need to shutdown it more than once.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
franaz
just joined
Topic Author
Posts: 8
Joined: Sat Nov 03, 2018 2:24 am

Re: Quick help for short code line

Sun Aug 04, 2019 12:52 am

great it works perfectly, thank you so much!!

Who is online

Users browsing this forum: No registered users and 6 guests