Reply
Highlighted
New Member
Posts: 4
Registered: ‎03-14-2019
Accepted Solution

Using the CLI to turn off WLAN

TLDR;

I manually turn a controller-defined WLAN off, and I would like to schedule its enabling a specific time each day. How do I go about? 

 

Full(er) story

This is admittedly a noob questions (apologies in advance for that), but my googling has only partially solved my problem, and hopefully some expert user here may guide me where to look further.

 

My situation is this. I have a specific WLAN for my kids' devices, which I now manually disable and then enable via the Controller GUI, since the scheduled time function is too static for my use-case (the turn-off time varies too much). I would like to automate the enabling (but not the disabling) of this WLAN. But although I have seen reference to the “Controller API”, I have failed to find any guide or instructions for it. What I have found, however, is a set of command lines that seems very promising indeed:

 

unifi_api /upd/wlanconf/<Id> '{"enabled": false}'

unifi_api /upd/wlanconf/<Id> '{"enabled": true}'

 

So I want to check if I understand how to utilise this (and corrected if not). My best guess is that I:

  1. log into the controller using my admin account
  2. use the second command line above to turn the on WLAN.

 

If that is possible, I can then use a script to run this command at the right time each day, and problem solved. So far I have not been able to test this, since I have not yet been able to ssh into my controller, which is a docker container on my Synology NAS.

 

So: Is this the command to use (and the right circumstance to use it)? And in that case, how do I access the controller CLI when it is in a docker container (the 'web' port is obviously not an option, and using port 22 only get me to my NAS)?


Accepted Solutions
Veteran Member
Posts: 5,043
Registered: ‎06-13-2015
Kudos: 1356
Solutions: 235

Re: Using the CLI to turn off WLAN

@knyckis  The parameter to pass to the API route isn't the name of the WLAN but it's the "_id" property. This can be found by either inspecting API output through your browser dev tools or by using my API browser tool.

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.

View solution in original post


All Replies
New Member
Posts: 4
Registered: ‎03-14-2019

Re: Using the CLI to turn off WLAN

[ Edited ]

I never received any answers or suggestions, probably since I was too much of a novice to know what to ask for. But I have now returned to the question and done some research, and so maybe I can now ask a more specific question and thus hopefully get some hints from you pros out there.

 

It seems that the 'commands' I got hold of in the above-mentioned thread is a call to a function in a unifi api shell script, "unifi_sh_api". So I have now downloaded the script to the server, made is executable, and tried to get it working. But I can't seem to get it to work.

 

This is what I do:

 

First, I define the environment variables commended out in the api shell script:

 

$ username=_my_username
$ password=_my_password
$ baseurl=https://unifi:8443
$ site=default
$ [ -f ./unifi_sh_env ] && . ./unifi_sh_env

 

I then 'source' the script

 

$ source /directory_for_the_script/unifi_sh_api

 

after which I thought everything would be ready for my calling on the function to get things done. But when I write

 

$ unifi_api /upd/wlanconf/KidsWifi '{"enabled": false}'

("KidsWifi" being the name of my kids' network), I only get an error message:

 

{"meta":{"rc":"error","msg":"api.err.LoginRequired"},"data":[]}

 

It seems as if it does not think I am logged in. OK, I thought, then calling on the login function first should do the trick. No such luck, however. If I fo the same routine as above, but before calling on the unifi_api function, I call on the unifo_login function, this is what happens:

 

$ unifi_login
{"meta":{"rc":"ok"},"data":[]}
$ unifi_api /upd/wlanconf/KidsWifi '{"enabled": false}'
{"meta":{"rc":"error","msg":"api.err.Invalid"},"data":[]}

 

The first terminal output seems fine, given that it is correct that it is an 'everything is good' response, as has been suggested

But even after this, the unifi_api call does not change the wifi status (in this case disabling it), but only return a new 'error message'.

 

Ideas on where I go wrong and what to do?

Veteran Member
Posts: 5,043
Registered: ‎06-13-2015
Kudos: 1356
Solutions: 235

Re: Using the CLI to turn off WLAN

@knyckis  The parameter to pass to the API route isn't the name of the WLAN but it's the "_id" property. This can be found by either inspecting API output through your browser dev tools or by using my API browser tool.

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
New Member
Posts: 4
Registered: ‎03-14-2019

Re: Using the CLI to turn off WLAN

Sir, you have saved my day -- it worked as a charm (and gave me tons of terminal output as well ;-)! Automatisation, here I come!

Veteran Member
Posts: 5,043
Registered: ‎06-13-2015
Kudos: 1356
Solutions: 235

Re: Using the CLI to turn off WLAN

@knyckis That's good to hear!Icon Smile

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
Reply