Page 1 of 1

How to re-connect client / Is it possible? [SOLVED]

PostPosted: Tue Jan 30, 2018 7:34 am
by autolog
Hi Karl,
In the UniFi Dashboard Client tab, it is possible to click on a reconnect button to force a reconnect to a client device.
Is it possible to do this via the plugin?

Scenario is that I have a problematic LIFX bulb (a downlighter that has a large RSJ beam directly line of sight between it and the UniFi AP) that goes no-ack (MIA) and a reconnect seems to sort out the issue. I can detect when this happens in my LIFX plugin and if I could force a reconnect, it would help resolve my issue. :)

Re: How to re-connect client / Is it possible?

PostPosted: Tue Jan 30, 2018 10:09 am
by kw123
the plugin does NOT talk to the unifi key ..

if we can do this on the switch , router or AP yes ..

the POE power cycle is done on the switch level though an ssh session .. If you can find something on the discussion forums let me know .. I have not found anything

here is how the power cycle works:

Code: Select all
set userID [lindex $argv 0 ]
set password [lindex $argv 1 ]
set ipNumber [lindex $argv 2 ]
set port [lindex $argv 3]
set endToken [lindex $argv 4]

set timeout 10
spawn  ssh $userID@$ipNumber
expect {
    "(yes/no)? " {
        send "yes\n"
        sleep 0.1
        expect "assword: " { send "$password\n"}
    }
    "assword: " {
        send "$password\n"
    }
}

sleep 1
expect "$endToken" {
    sleep 0.1
    send "telnet localhost 23\r"
    sleep 0.1
    send "enable\r"
    sleep 0.05
    send "configure\r"
    sleep 0.05
    send "interface 0/$port\r"
    sleep 0.05
    send "poe opmode shutdown\r"
    sleep 0.3
    send "poe opmode auto\r"
    sleep 0.05
    send "exit\r"
    sleep 0.05
    send "exit\r"
    sleep 0.05
    send "exit\r"
    sleep 0.05
    send "exit\r"
    sleep 0.05
    send "exit\r"
    }
sleep 0.2
expect eof

Re: How to re-connect client / Is it possible?

PostPosted: Tue Jan 30, 2018 11:37 am
by autolog
Found this on github: Art-of-WiFi/UniFi-API-client

It is written for PHP and based on some info released by Ubiquiti and some wire-sharking.

There is a Request for an API thread here: API full documentation

Not sure if this is any help? :)

Re: How to re-connect client / Is it possible?

PostPosted: Tue Jan 30, 2018 11:54 am
by DaveL17
Code: Select all
expect "assword:

Is that anything like an #assToggle? :D

Re: How to re-connect client / Is it possible?

PostPosted: Tue Jan 30, 2018 12:06 pm
by Colorado4Wheeler
Yes, I think it is...

Re: How to re-connect client / Is it possible?

PostPosted: Wed Jan 31, 2018 4:34 pm
by kw123
this seem to do the trick:
Code: Select all
curl  --insecure -c /tmp/unificookie  --data "{'username':'YOURID','password':'YOURPWD'}" https://YOURIP:8443/api/login
curl  --insecure -b /tmp/unificookie  --data '{"cmd":"kick-sta","mac":"xx:xx:xx:xx:xx:xx"}'  https://YOURIP:8443/api/s/default/cmd/stamgr
1. login and store the login token in/tmp/unificookie ("-c"); "-- insecure" as you likely have not a registered certificate on your cloud-key
2. send cmd kick-sta for mac # xx.xx.xx.... to stamgr with "-b" read cookie
replace "default" with your site name and mac # must be lower case.. and ip and userid / pwd

will add this to the plugin

Karl

Re: How to re-connect client / Is it possible?

PostPosted: Wed Jan 31, 2018 9:55 pm
by kw123
Jon,

try v 7.10.80 it has re-connect as well as block / unblock menus/actions


Karl

Re: How to re-connect client / Is it possible?

PostPosted: Thu Feb 01, 2018 1:51 am
by autolog
Hi Karl,

Brilliant, it works very well. :D

Thank you for doing this, it really is appreciated. :)

Re: How to re-connect client / Is it possible? [SOLVED]

PostPosted: Thu Feb 01, 2018 12:26 pm
by kw123
looking into adding some more items to it ..

hesitating to add things like shutdown gateway .. setup networks .. they do not make sense to have them automated from indigo

could you check out https://github.com/Art-of-WiFi/UniFi-API-client/blob/master/src/Client.php

which of those makes sense to add?

have added print unifi system device info

Re: How to re-connect client / Is it possible? [SOLVED]

PostPosted: Thu Feb 01, 2018 12:50 pm
by autolog
Hi Karl,
I have had a quick look and not sure how much more needs adding?
I think one really needs a use case for each one to say why it would be useful and what issue it would solve.
You could spend a lot of time adding in function that will never get used. :)

Re: How to re-connect client / Is it possible? [SOLVED]

PostPosted: Thu Feb 01, 2018 1:38 pm
by kw123
Jo,
added 2 easy ones: print client, system device info, health info and fixed a smaller issue with GW device mac#
Karl

Re: How to re-connect client / Is it possible? [SOLVED]

PostPosted: Sun Feb 04, 2018 3:09 pm
by autolog
Hi Karl,
Upgraded to 7.10.82 and getting this error when executing an Action to reconnect:
uniFiAP Error Error in plugin execution ExecuteAction:

Traceback (most recent call last):
File "plugin.py", line 1246, in buttonConfirmReconnectCALLBACKaction
File "plugin.py", line 1249, in buttonConfirmReconnectCALLBACK
KeyError: key selectedDevice not found in dict

I selected a LIFX Lamp from the pulldown list. :)

Re: How to re-connect client / Is it possible? [SOLVED]

PostPosted: Sun Feb 04, 2018 3:52 pm
by kw123
sorry for that .. too many options to test .. this one should work:
https://www.dropbox.com/s/ha966s7kubu7k0g/uniFiAP-v-7.10.83.zip?dl=1

will also post the same on GitHub


Karl

Re: How to re-connect client / Is it possible? [SOLVED]

PostPosted: Sun Feb 04, 2018 4:40 pm
by autolog
Hi Karl,
Thanks - that fixed it. :)