uniFi-WiFI-AP: discussions

Posted on
Thu May 26, 2016 10:46 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

uniFi-WiFI-AP: discussions

how to get the current info from all access points into a dict:
Code: Select all
import json
import subprocess

uid = "ap-userid"
pwd = "ap-pwd"
piN = ["192.168.1.x","192.168.1.y"] ## up to number of aps
cmd = "mca-dump"


apInfo=[]
errorMsg=""
for ll in range(len(piN)):
    ret= subprocess.Popen("/usr/bin/expect /users/YOURUSERID/documents/unifi/exec.exp "+uid+" "+pwd+" "+piN[ll]+" "+cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()


    firstTag = "# mca-dump \r\n"
    lastTag  = "}\r\nBZ."

    z=""
    y = ret[0].split(firstTag)
    if len(y) !=2:
        errorMsg = "bad data, first tag not found"
    else:   
        z = y[1].split(lastTag)
        if len(z) !=2:
            errorMsg = "bad data, last tag not found"
        else:   
            apInfo.append(json.loads(z[0]+"}")


if errorMsg !="":  print errorMsg
else: print json.dumps(apInfo,sort_keys=True, indent=2)


and you need:
Code: Select all
set userID [lindex $argv 0 ]
set password [lindex $argv 1 ]
set ipNumber [lindex $argv 2 ]
set cmd [lindex $argv 3]

set timeout 15
spawn -noecho ssh $userID@$ipNumber
expect {
        "assword:" {
                exp_send -- "$password\r"
        }
}


expect "BZ." {
    expect "#"
    sleep 0.1
    send "$cmd \r"
    }
expect "BZ." {}
set timeout 0.1
expect eof
in ~/documents/unifi/

that will give you something like this :
Code: Select all
[
  {
    "bootrom_version": "unifi-v1.5.2.206-g44e4c8bc",
    "cfgversion": "eef5327e2847029b",
    "connect_request_ip": "192.168.1.3",
    "connect_request_port": "41621",
    "country_code": 840,
    "default": false,
    "discovery_response": false,
    "guest_token": "xxxx",
    "hostname": "xxxx",
    "if_table": [
      {
        "full_duplex": true,
        "ip": "0.0.0.0",
        "mac": "xxxx",
....
    "radio_table": [
      {
        "athstats": {
          "ast_ath_reset": 0,
          "ast_be_xmit": 65856,
          "ast_cst": 0,
          "ast_deadqueue_reset": 0,
          "ast_fullqueue_stop": 0,
          "ast_txto": 0,
          "n_rx_aggr": 0,
          "n_rx_pkts": 215857,
....
        "scan_table": [
          {
            "age": 0,
            "bssid": "xxxx",
            "channel": 36,
            "essid": "5",
            "freq": 5180,
            "is_adhoc": false,
            "is_default": false,
            "is_isolated": false,
            "is_locating": false,
....
        "scan_table": [
          {
            "age": 0,
            "bssid": "xxxx",
            "channel": xxx,
            "essid": "xxxx",
            "freq": 2412,
            "is_adhoc": false,
            "is_default": false,
            "is_isolated": false,
            "is_locating": false,
            "is_ubnt": true,
         {
            "age": 2,
            "bssid": "20:18:d6:4f:4c:c3",
            "channel": 1,
            "essid": "xxx",
            "freq": 2412,
            "is_adhoc": false,
            "is_default": false,
            "is_isolated": false,
            "is_locating": false,
            "is_ubnt": true,
            "is_unifi": true,
            "is_vport": false,
            "is_vwire": false,
            "model": "BZ2",
            "model_display": "UAP",
            "rssi": 7,
            "security": "secured",
            "serialno": "0418D636EB03"
          },


....
          {
            "auth_time": 4294967271,
            "authorized": true,
            "ccq": 935,
            "dhcpend_time": 4960,
            "dhcpstart_time": 0,
            "hostname": "raspberrypi",
            "idletime": 2,
            "ip": "192.168.1.21",
            "is_11n": true,
            "mac": "00:13:ef:65:03:41",
            "noise": -86,
            "rssi": 35,
a list of the config of each AP, the neighbor Wifi routers and a list of each connected Wifi device to your AP's

Access to activities: with
Code: Select all
ssh uid@ipNumber "tail -f /var/log/messages" > /users/YOURUSERID/documents/unifi/ap.log    then enter password

you get all authorizations(connect) and disassociations(disconnects from the AP's) including when they switch from one to the other
to a continuously growing file on your Mac:
Code: Select all
May 27 07:55:39 4-karl daemon.info hostapd: ath1: STAxxxxx WPA: pairwise key handshake completed (RSN)
May 27 07:55:43 4-karl daemon.info hostapd: ath1: STA xxxx IEEE 802.11: sta_stats
May 27 07:55:43 4-karl daemon.info hostapd: ath1: STA xxx IEEE 802.11: disassociated
May 27 07:55:43 4-karl daemon.notice hostapd: AP-STA-DISCONNECTED xxxx
May 27 07:55:44 4-karl user.info kernel: [37006.028000] ubnt_roam [BASIC]:Authenticating STA xxxx our signal 44, other signal 0
May 27 07:55:44 4-karl daemon.info hostapd: ath1: STA xxx IEEE 802.11: associated
May 27 07:55:44 4-karl daemon.notice hostapd: AP-STA-CONNECTED xx
May 27 07:55:44 4-karl daemon.info hostapd: ath1: STA xxxx RADIUS: starting accounting session 00000015-0000000B
May 27 07:55:44 4-karl daemon.info hostapd: ath1: STA xxxxx WPA: pairwise key handshake completed (RSN)
May 27 07:56:17 4-karl authpriv.notice dropbear[5190]: Password auth succeeded for 'xxx' from 1xxxx
May 27 07:56:35 4-karl user.info kernel: [37057.278000] ubnt_roam [BASIC]:Authenticating STA xxx our signal 52, other signal 0
May 27 07:56:35 4-karl daemon.info hostapd: ath1: STA xxx IEEE 802.11: sta_stats
May 27 07:56:35 4-karl daemon.info hostapd: ath1: STA xxx IEEE 802.11: disassociated
May 27 07:56:35 4-karl daemon.notice hostapd: AP-STA-DISCONNECTED xxx
May 27 07:56:35 4-karl daemon.info hostapd: ath1: STA xxx IEEE 802.11: associated
May 27 07:56:35 4-karl daemon.notice hostapd: AP-STA-CONNECTED xxx
May 27 07:56:35 4-karl daemon.info hostapd: ath1: STA xxx RADIUS: starting accounting session 00000015-0000000C
May 27 07:56:35 4-karl daemon.info hostapd: ath1: STA 5xxx WPA: pairwise key handshake completed (RSN)
 


To get some detailed info available, we then could create a plugin that use these info and creates devices with states that reflect the info from the AP's

This was the difficult path to figure out..

There are also APIs available to get to some of the info, but they require some installs of packages.


Karl

Posted on
Fri May 27, 2016 3:52 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: UBIQUITY UNIFI AP-WiFi: discussions

Thanks for sharing this Karl.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Fri May 27, 2016 11:19 am
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: UBIQUITY UNIFI AP-WiFi: discussions

for "zero handoff"

on page 19 of the manual:https://dl.ubnt.com/guides/UniFi/UniFi_Controller_V4_UG.pdf
Name Enter or edit a descriptive name for the WLAN group.
Mobility To enable seamless roaming (Zero Handoff ), select the checkbox.
Note: The UAP-AC, UAP-AC-Outdoor, UAP-AC-LITE, UAP-AC-LR, UAP-AC-PRO, and UAP-AC-EDU do not support Zero Handoff Roaming.
When you enable this option, multiple Access Points (APs) act as an AP cluster, appearing as a single AP. The wireless client detects only one AP, so it seamlessly roams from AP to AP – there is no need to re-negotiate. The APs determine which AP has the best connection and should serve the client. They use multicasting to communicate so they must be wired in the same Layer 2 domain.
...


You must purchase the right device. Their web page is really confusing and some of the 3rd party vendors (on amazon) do not use the same name ( i.e. add "enterprise" and add $30 to it. )

What seems to work are "UniFi AP(-Pro)" on their web page go to all productshttps://www.ubnt.com/products/

essentially anything that starts with AC-xxx is not supporting zero handoff

Then select unifi-ap https://www.ubnt.com/unifi/unifi-ap/. there you find the -PRO listed. it as 2.4 + 5 Ghz, (it only supports 450Mbit not 1300Mbit, but I don't have anything that could use that and if I would, I would add string ethernet cable to the device )

The AP outdoor "should" also supports zero hand off, but has only a 10/100Mbit ethernet cable connection


Karl

Posted on
Fri May 27, 2016 9:59 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: UBIQUITY UNIFI AP-WiFi: discussions

For those that would like to play around with the APs: with this you can listen in python on your mac to the activities on the APs
Code: Select all
import subprocess
import fcntl
import os
import time
uid    = "xx"
pwd    = "xx"
piN    = ["192.168.1.x","192.168.1.x"] ## up to number of APs
cmd0    = "'/usr/bin/tail -f /var/log/messages'"  # this will be send to each AP
USERIDpath ="youruserhomedir"

p=[]
## setup the listening
for ll in range(len(piN)):
    cmd="/usr/bin/expect /users/"+USERIDpath+"/documents/unifi/exec.exp "+uid+" "+pwd+" "+piN[1]+" "+cmd0
    p.append(subprocess.Popen(cmd,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True))
    msg = unicode(p[ll].stderr)
    if msg.find("[Err ") > -1:  # try this again
        print msg
        exit()
    # set the O_NONBLOCK flag of p.stdout file descriptor:
    flags = fcntl.fcntl(p[ll].stdout, fcntl.F_GETFL) # get current p.stdout flags
    fcntl.fcntl(p[ll].stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)


# now listen to the messages
while True:
    for ll in range(len(p)):
        try:
            data= os.read(p[ll].stdout.fileno(), 20000)
        except  Exception, e:
            if unicode(e).find("[Errno 35]") ==-1: #  "Errno 35" is the normal response if no data, if other error: exit
                print "error",  e
                break
            continue
        if data !="":
            print "AP# ",ll,"  data \n",ll, data  ####   <=== here you would do something beside printing with the data
        time.sleep(0.1)

for ll in range(len(p)):
    p[ll].close()
and here the exec.exp file:
Code: Select all
set userID [lindex $argv 0 ]
set password [lindex $argv 1 ]
set ipNumber [lindex $argv 2 ]
set cmd [lindex $argv 3]

set timeout 15
spawn  ssh $userID@$ipNumber 
expect {
        "assword:" {
                exp_send -- "$password\r"
        }
}
expect "BZ." {send $cmd\r\n}
interact

Posted on
Sat May 28, 2016 7:08 pm
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: UBIQUITY UNIFI AP-WiFi: discussions

This is cool. I'd love to figure out something useful to do with this.

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Sun May 29, 2016 11:21 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: UBIQUITY UNIFI AP-WiFi: discussions

here a more complete python program that reads the syslog file and the AP-dict i.e.:

1. init parameters :userid, setup dirs .
2. create threads for each AP that will read the syslogfiles on each AP
3. check if every this is running and restart if needed, e.g. if you restart an AP the listener has to be restarted too.
4. get the "dict" with the more static data once every xx seconds.
5. two methods for logfile and dict that print the data. These you should modify to do something with it.

I indicated which part should go where in a plugin.

Three programs are attached.
1. the main python program, (unfiread.py) ===> replace userid, password and IP numbers of your APs
2. expect program to get the syslog (exec.exp)
3. expect program to get the dict (getDict.exp)

change these lines in unifiread.py to your environment
Code: Select all
    unifiUserID                 = "xxx"                                 ## unifi AP userid
    unifiPassWd                 = "xxx"                            ## unifi AP password
    ipNumbersOfAPs              = ["192.168.1.x","192.168.1.x","192.168.1.x"] ## one ip # for each ap, add/delete if you have more.less AP than 3
    APsEnabled                  = [0,1,2]                                     ## which of the above are enabled

these files must go to ~ /documents/unifi

then open terminal,
cd ~/documents/unifi
python unifiread.py

and you should see the output on your screen.


Karl

================================
readunifi.py:
Code: Select all
###
# read unifi Ap data 
# Karl Wachs may 30
# use as you see fit.
###

import subprocess
import fcntl
import os
import sys
import pwd
import time
import Queue
import signal
import threading
import copy
import json



###  setup CTRL reaction
def Exit_gracefully(signal, frame):
    global stopCTRLC
    print "CTRL-C pressed"
    stopCTRLC = True
   
### start the expect command to get the logfile
def startConnect(ipNumber):
    global unifiUserID, unifiPassWd, listLogFileCommand
    for ii in range(20):
        cmd="/usr/bin/expect "+unifiPath+"exec.exp "+unifiUserID+" "+unifiPassWd+" "+ipNumber+" "+listLogFileCommand
        pOpen = subprocess.Popen(cmd,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
        ##pid = pOpen.pid
        ##print " pid= ", pid
        msg = unicode(pOpen.stderr)
        if msg.find("[Err ") > -1:  # try this again
            print " error connecting ", msg
            time.sleep(20)
            continue
           
        # set the O_NONBLOCK flag of pOpen.stdout file descriptor:
        flags = fcntl.fcntl(pOpen.stdout, fcntl.F_GETFL) # get current p.stdout flags
        fcntl.fcntl(pOpen.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
        return pOpen,""

###  kill expect pids if running
def  killIfRunning(ipNumber):
    ret = subprocess.Popen("ps -ef | grep "+ipNumber+ " | grep /usr/bin/expect | grep -v grep" ,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True).communicate()[0]
    if len(ret) < 5:
        return
       
    lines = ret.split("\n")
    for line in lines:
        if len(line) < 5:
            continue
           
        items = line.split()
        if len(items) < 5:
            continue
           
        pid = items[1]
        try:
            ipid = int(pid)
            ret = subprocess.Popen("/bin/kill -9  "+pid,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True).communicate()
            print u"killing ip#, pid# ", ipNumber, pid
            continue
           
        except:
            pass

### test if AP are up, first ping then check if expect is running
def testAPandPing(ipNumber,pOpen):
    print "testing if "+ ipNumber +" pid "+ str(pOpen.pid)+" is running "
    if testPing(ipNumber) !=0: return False
    ret = subprocess.Popen("ps -ef | grep "+str(pOpen.pid)+ " | grep /usr/bin/expect | grep -v grep" ,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True).communicate()[0]
    if len(ret) < 5: False
    lines= ret.split("\n")
    for line in lines:
        if len(line) < 5:
            continue
           
        ##print line
        items = line.split()
        if len(items) < 5:
            continue
           
        if items[1] != str(pOpen.pid):
            continue
           
        if line.find("expect") > -1:
            #print "expect found ", line
            return True
           
    return False
     

### do the ping test   
def testPing( ipNumber):
        try:
            ret = os.system("/sbin/ping  -c 4 -W 1 -o " + ipNumber +">/dev/null ") # send max 4 packets, wait 0.5 secs between each and if one gets back stop
            if int(ret) ==0: 
                return 0
               
            print u" ping return-code not 0: " + unicode(ret)
            time.sleep(2)
            ret = os.system("/sbin/ping  -c 4 -W 1 -o " + ipNumber +">/dev/null ")
            if int(ret) ==0: 
                return 0
               
            print u" ping return-code not 0: " + unicode(ret)
            return 1
        except  Exception, e:
            print  u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e)
        return 1



### here we do the work, setup the logfiles listening and read the logfiles and check if everything is running, if not restart
def getMessages(ipNumber):
    global stop, connectPids, stopCTRLC,  unifiUserID, unifiPassWd, ipNumbersOfAPs, listLogFileCommand, unifiPath,restartIfNoMessageSeconds, verifyUpEverySeconds, stop, stopCTRLC, logQueue, loopCounterRestart, APsEnabled
    loopCounter=0
    ## print "launching " + ipNumber
    pOpen, msg = startConnect(ipNumber)
    if msg !="":
        print " fatal error, connect for ip#: " + ipNumber
        return
    lastTest           = time.time()
    lastForcedRestart  = time.time()
   
 
#### for ever, until stop is set
    while True:
        time.sleep(0.1)
        tt= time.time()
       
        ## time to verify if every is still running?
        if (tt - lastTest) > verifyUpEverySeconds:
            lastTest = time.time()
            if not testAPandPing(ipNumber, pOpen):
                killIfRunning(ipNumber)
                pOpen, msg = startConnect(ipNumber)
               
        ## force restart after xx seconds no matter what?
        if (tt - lastForcedRestart) > restartIfNoMessageSeconds:
            print "AP# " + ipNumber + " forcing restart of msg after " + str(int(time.time() - lastForcedRestart)) + " sec without message"
            lastForcedRestart = time.time()
            lastTest          = time.time()
            killIfRunning(ipNumber)
            pOpen, msg = startConnect(ipNumber)
           
        ## should we stop?, is our IP number listed?
        if ipNumber in stop:
            print " stop in getMessage stop=True"
            #pOpen.close()
            return
            while stop.count(ipNumber) > 0:
                stopremove(ipNumber)
               
        ## here we actually read the stuff
        try:
            r= os.read(pOpen.stdout.fileno(), 20000)
        except  Exception, e:
            if unicode(e).find("[Errno 35]") ==-1: #  "Errno 35" is the normal response if no data, if other error: exit
                print "error",  e
                #pOpen.close()
                stop.append(ipNumber)
            continue
        ## did we get anything?   
        if r !="":
            ## any error messages from OSX?
            if (
                r.find("closed by remote host") >-1  or
                r.find("Killed by signal") >-1  ):
                    print " returning " +ipNumber + " " +unicode(r)
                    killIfRunning(ipNumber)
                    pOpen, msg = startConnect(ipNumber)
                    continue
                   
            lastForcedRestart = time.time()     

            ## fill the queue and send to the method that uses it
            logQueue.put((ipNumber,r))
            doSomethingWithLog()  #####################  here we call method to do something with the data
           
            ## loop counter, test if we should restart litening
            loopCounter +=1
            if loopCounter > loopCounterRestart:
                lastForcedRestart = 0
                loopCounter       = 0
                print "AP# " +ipNumber+" forcing restart of msg after "+ str(ccc) +" loops"


### get the dict from the APs
def getapDict(ipNumber):
    global unifiUserID, unifiPassWd, listDictCommand, unifiPath
    ret= subprocess.Popen("/usr/bin/expect  "+unifiPath+"getDict.exp "+unifiUserID+" "+unifiPassWd+" "+ipNumber+" "+listDictCommand,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()

    firstTag = "# mca-dump \r\n"
    lastTag  = "}\r\nBZ."

    apDict  = {}

    y = ret[0].split(firstTag)
    if len(y) !=2:
        errorMsg = "bad data, first tag not found"
    else:   
        z = y[1].split(lastTag)
        if len(z) !=2:
            errorMsg = "bad data, last tag not found"
        else: 
            try:
                apDict=json.loads(z[0]+"}")
            except:
                print " error encoding json for " +z[0][0:100]
           
    return apDict


#######  for the logfile this you should replace if you want to do something with it
def doSomethingWithLog():
    global logQueue
    while not logQueue.empty():
        item = logQueue.get()
        print "\n>    from: " + unicode(item[0])
        lines= item[1].split("\r\n")
        for line in lines:
            if len(line) < 2: continue
            if   line.find("spawn ssh") > -1:  ## this is command output, can be ignored
                print "---- "+line
            elif line.find("'s password:") > -1:   ## this is command output, can be ignored
                print "---- "+line
            elif line.find("BusyBox v") > -1:   ## this is command output, can be ignored
                print "---- "+line
            elif line.find("Enter 'help' for a list of built-in commands.") > -1: ## this is command output, can be ignored 
                print "---- "+line
            elif line.find("BZ.")==0:   ## this is command output, can be ignored
                print "---- "+line
            elif line.find(listLogFileCommand) > -1:  ## this is command output, can be ignored
                print line
               
            ##### this is the real daata   
            else:
                print ">>>> "+ line
        logQueue.task_done()


### for the dict, replace with something useful
def doSomethingWithDict(apDict):
    print ">>>> Dict" + unicode(apDict)[0:100]+"...."
    return
   


### init parameters, ..  this should go to  def startup(self):
def initMain():
    global stop, connectPids, stopCTRLC, unifiUserID, unifiPassWd, ipNumbersOfAPs, listLogFileCommand, listDictCommand, unifiPath,restartIfNoMessageSeconds, verifyUpEverySeconds,readDictEverySeconds, stop, stopCTRLC, logQueue, loopCounterRestart, APsEnabled

######################################################################################################################
########################   set parameters   #########################################################################
######################################################################################################################
    unifiUserID                 = "xxx"                                 ## unifi AP userid
    unifiPassWd                 = "xxx"                            ## unifi AP password
    ipNumbersOfAPs              = ["192.168.1.x","192.168.1.x","192.168.1.x"] ## one ip # for each ap
    APsEnabled                  = [0,1,2]                                     ## which of the above are enabled
    listLogFileCommand          = "'/usr/bin/tail -f /var/log/messages'"      ## this is the command send to AP to get the logfile
    listDictCommand             = "mca-dump"                                  ## this is the command  to get the dict from each AP
    restartIfNoMessageSeconds   = 500                                         ## #of seconds without any msg do a restart expect listen
    verifyUpEverySeconds        = 20                                          ## do a ping and check if expect is still running every xx seconds
    loopCounterRestart          = 1000000                                     ## force getmsg restart after n loops , just a safety net
    readDictEverySeconds        = 120                                         ##
######################################################################################################################
########################   set parameters   end  #####################################################################
######################################################################################################################

    MACuserName = pwd.getpwuid( os.getuid() )[ 0 ]
    MAChome     = os.path.expanduser("~")


    unifiPath  = MAChome+"/documents/unifi/"
    print unifiPath
    ret = subprocess.Popen("mkdir "+unifiPath+" > /dev/null 2>&1 &",shell=True)


    stop        = []
    stopCTRLC   = False

    logQueue= Queue.Queue()

    signal.signal(signal.SIGINT, Exit_gracefully)

    for ll in range(len(ipNumbersOfAPs)):
        killIfRunning(ipNumbersOfAPs[ll])





### main routine that starts things, this should go to    def runConcurrentThread(self):
def _main():
    global stop, connectPids, stopCTRLC, readDictEverySeconds, unifiUserID, unifiPassWd, ipNumbersOfAPs, listLogFileCommand, unifiPath,restartIfNoMessageSeconds, verifyUpEverySeconds, stop, stopCTRLC, logQueue, loopCounterRestart, APsEnabled
    initMain()
    apDict={}

###########  set up threads  ########
    try:
        tr=[]
        for ll in range(len(APsEnabled)):
            ipn = ipNumbersOfAPs[APsEnabled[ll]]
            tr.append(threading.Thread(name='getMessages', target=getMessages,args=(ipn,)))
            tr[ll].start()
            time.sleep(3)

        lastTimeDictRead =0
        ddd=0
    except  Exception, e:
            print  u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e)
            stop = copy.copy(ipNumbersOfAPs)
            return
 
###########  loop for get dict and to stop if requested  ##### 
    try:
        while True:
            if time.time() - lastTimeDictRead > readDictEverySeconds:
                lastTimeDictRead = time.time()
                for ll in range(len(APsEnabled)):
                    ## print " getting dict for #", ll
                    apDict[str(ll)] = getapDict(ipNumbersOfAPs[APsEnabled[ll]])
                doSomethingWithDict(apDict) ## <--------- here we should do something with the dict
   
            if stopCTRLC:
                stop = copy.copy(ipNumbersOfAPs)
                print " in loop stop= ", stop
            ddd +=1
            if ddd> 300000 or stop == ipNumbersOfAPs:  # safety to just stop after 30k seconds
                print "stop in main " + str(ddd)
                stop= copy.copy(ipNumbersOfAPs)
                time.sleep(1)
                for ll in range(len(APsEnabled)):
                    tr[ll].join()
                return
            time.sleep(1)
    except  Exception, e:
            print  u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e)
    stop = copy.copy(ipNumbersOfAPs)
    time.sleep(2)


_main()
exit()


exec.exp:
Code: Select all
set userID [lindex $argv 0 ]
set password [lindex $argv 1 ]
set ipNumber [lindex $argv 2 ]
set cmd [lindex $argv 3]

set timeout 15
spawn  ssh $userID@$ipNumber 
expect {
        "assword:" {
                exp_send -- "$password\r"
        }
}
expect "BZ." {
    send $cmd\r\n
    interact
}

getDict.exp:
Code: Select all
set userID [lindex $argv 0 ]
set password [lindex $argv 1 ]
set ipNumber [lindex $argv 2 ]
set cmd [lindex $argv 3]

set timeout 15
spawn -noecho ssh $userID@$ipNumber
expect {
        "assword:" {
                exp_send -- "$password\r"
        }
}


expect "BZ." {
    expect "#"
    sleep 0.1
    send "$cmd \r"
    }
expect "BZ." {}
set timeout 0.1
expect eof

Posted on
Tue May 31, 2016 1:48 pm
WouterK offline
Posts: 167
Joined: Aug 19, 2015

Re: UBIQUITY UNIFI AP-WiFi: discussions

Hi Karl,

Just installed the new plugin, great! All devices show up :!:
I know you have tested it for a da,y but this is looking very promising.
Looking forward to the next versions :D

One thing I noticed: after installing the eventlog show the following:

    Installing and enabling plugin uniFiAP v0.1.5
    Loading plugin "uniFiAP 0.1.5"
    Starting plugin "uniFiAP 0.1.5" (pid 10074)
    Z-Wave received "Kapschuur - Lux" sensor update to 400 lux
    Started plugin "uniFiAP 0.1.5"
    Z-Wave received "Temperatuur schuur" sensor update to 21.31 °C
    uniFiAP .. initalized
    uniFiAP Error Error in plugin execution UiValidate:

    Traceback (most recent call last):
    File "plugin.py", line 182, in validatePrefsConfigUi
    ValueError: invalid literal for int() with base 10: ''

After a reload everything worked and I did not see the message again.

Regards,

Wouter

Posted on
Tue May 31, 2016 3:01 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: UBIQUITY UNIFI AP-WiFi: discussions

this is an error message when an entry field is not populated. its one of the "expert" fields.
It was not entered. will be fixed in the next release..

And does anyone want any of these fields - this is the dict available through mac-dump on each AP, all of the states currently in the plugin are from this listing (besides timestamps )
you can get your settings in a terminal:
ssh userid@ipn enter password
then type
mca-dump

Code: Select all
BZ.v3.3.20# mca-dump
{
        "bootrom_version": "unifi-v1.5.2.206-g44e4c8bc",
        "cfgversion": "6730d7db7e758acc",
        "connect_request_ip": "192.168.1.3",
        "connect_request_port": "35774",
        "country_code": 840,
        "default": false,
        "discovery_response": false,
        "guest_token": "F731EE912C32D4769288A677D9F191B4",
        "hostname": "3-Study",
        "if_table": [
                {
                        "full_duplex": true,
                        "ip": "0.0.0.0",
                        "mac": "44:d9:e7:02:4e:9e",
                        "name": "eth0",
                        "netmask": "0.0.0.0",
                        "num_port": 2,
                        "rx_bytes": 1759690385,
                        "rx_dropped": 26,
                        "rx_errors": 0,
                        "rx_multicast": 1017947,
                        "rx_packets": 17590768,
                        "speed": 1000,
                        "tx_bytes": 1483850487,
                        "tx_dropped": 0,
                        "tx_errors": 0,
                        "tx_packets": 19396585,
                        "up": true
                }
        ],
        "inform_url": "http://192.168.1.176:8080/inform",
        "ip": "192.168.1.3",
        "isolated": false,
        "locating": false,
        "mac": "44:d9:e7:02:4e:9e",
        "model": "U7P",
        "model_display": "UAP-Pro",
        "netmask": "255.255.255.0",
        "radio_table": [
                {
                        "athstats": {
                                "ast_ath_reset": 0,
                                "ast_be_xmit": 832192,
                                "ast_cst": 1,
                                "ast_deadqueue_reset": 0,
                                "ast_fullqueue_stop": 0,
                                "ast_txto": 70,
                                "n_rx_aggr": 497931,
                                "n_rx_pkts": 1824579,
                                "n_tx_bawadv": 211002,
                                "n_tx_bawretries": 14826,
                                "n_tx_pkts": 235482,
                                "n_tx_queue": 182728,
                                "n_tx_retries": 14826,
                                "n_tx_xretries": 112,
                                "n_txaggr_compgood": 167820,
                                "n_txaggr_compretries": 14938,
                                "n_txaggr_compxretry": 0,
                                "n_txaggr_prepends": 6191,
                                "name": "wifi0"
                        },
                        "builtin_ant_gain": 0,
                        "builtin_ant_gain": 0,
                        "builtin_antenna": true,
                        "max_txpower": 23,
                        "min_txpower": 4,
                        "name": "wifi0",
                        "nss": 2,
                        "radio": "na",
                        "scan_table": [
                                {
                                        "age": 35,
                                        "bssid": "90:a7:c1:07:09:13",
                                        "channel": 36,
                                        "essid": "BlockHome",
                                        "freq": 5180,
                                        "is_adhoc": false,
                                        "is_ubnt": false,
                                        "rssi": 5,
                                        "security": "secured"
                                },
                                {
                                        "age": 0,
                                        "bssid": "50:d9:e7:03:4e:9e",
                                        "channel": 36,
                                        "essid": "5",
                                        "freq": 5180,
                                        "is_adhoc": false,
                                        "is_default": false,
                                        "is_isolated": false,
                                        "is_locating": false,
                                        "is_ubnt": true,
                                        "is_unifi": true,
                                        "is_vport": false,
                                        "is_vwire": false,
                                        "model": "U7P",
                                        "model_display": "UAP-Pro",
                                        "rssi": 6,
                                        "security": "secured",
                                        "serialno": "44D9E7025254"
                                }
                        ]
                },
                {
                        "athstats": {
                                "ast_ath_reset": 0,
                                "ast_be_xmit": 831396,
                                "ast_cst": 485890,
                                "ast_deadqueue_reset": 0,
                                "ast_fullqueue_stop": 0,
                                "ast_txto": 562,
                                "n_rx_aggr": 29714800,
                                "n_rx_pkts": 42754421,
                                "n_tx_bawadv": 15714494,
                                "n_tx_bawretries": 323623,
                                "n_tx_pkts": 15970955,
                                "n_tx_queue": 11384630,
                                "n_tx_retries": 323623,
                                "n_tx_xretries": 2014,
                                "n_txaggr_compgood": 9825405,
                                "n_txaggr_compretries": 325637,
                                "n_txaggr_compretries": 325637,
                                "n_txaggr_compxretry": 0,
                                "n_txaggr_prepends": 137846,
                                "name": "wifi1"
                        },
                        "builtin_ant_gain": 0,
                        "builtin_antenna": true,
                        "max_txpower": 30,
                        "min_txpower": 12,
                        "name": "wifi1",
                        "nss": 3,
                        "radio": "ng",
                        "scan_table": [
                                {
                                        "age": 0,
                                        "bssid": "20:d9:e7:03:4e:9e",
                                        "channel": 1,
                                        "essid": "2",
                                        "freq": 2412,
                                        "is_adhoc": false,
                                        "is_default": false,
                                        "is_isolated": false,
                                        "is_locating": false,
                                        "is_ubnt": true,
                                        "is_unifi": true,
                                        "is_vport": false,
                                        "is_vwire": false,
                                        "model": "U7P",
                                        "model_display": "UAP-Pro",
                                        "rssi": 28,
                                        "security": "secured",
                                        "serialno": "44D9E7025254"
                                },
                                {
                                        "age": 1,
                                        "bssid": "20:18:d6:4f:4c:c3",
                                        "channel": 1,
                                        "essid": "St-HomeWifi",
                                        "freq": 2412,
                                        "is_adhoc": false,
                                        "is_default": false,
                                        "is_isolated": false,
                                        "is_locating": false,
                                        "is_ubnt": true,
                                        "is_unifi": true,
                                        "is_vport": false,
                                        "is_vwire": false,
                                        "model": "BZ2",
                                        "model_display": "UAP",
                                        "rssi": 12,
                                        "security": "secured",
                                        "serialno": "0418D636E576"
                                }
                        ]
                }
        ],
        "required_version": "3.2.4",
        "selfrun_beacon": true,
        "serial": "44D9E7024E9E",
        "state": 2,
        "time": 1464641478,
        "uplink": "eth0",
        "uptime": 85216,
        "vap_table": [
                {
                        "bssid": "50:d9:e7:03:4e:9e",
                        "ccq": 977,
                        "channel": 36,
                        "essid": "5",
                        "id": "574a70e8c2e68828fe383735",
                        "name": "ath0",
                        "num_sta": 1,
                        "radio": "na",
                        "rx_bytes": 18405190,
                        "rx_crypts": 0,
                        "rx_dropped": 0,
                        "rx_errors": 0,
                        "rx_frags": 0,
                        "rx_nwids": 1014,
                        "rx_packets": 134469,
                        "sta_table": [
                                {
                                        "auth_time": 4294967294,
                                        "authorized": true,
                                        "ccq": 979,
                                        "dhcpend_time": 3285251,
                                        "dhcpstart_time": 3285249,
                                        "hostname": "karls-iPad",
                                        "idletime": 3,
                                        "ip": "192.168.1.215",
                                        "is_11a": true,
                                        "is_11n": true,
                                        "mac": "f0:f6:1c:d5:51:16",
                                        "noise": -95,
                                        "noise": -95,
                                        "rssi": 15,
                                        "rx_bytes": 7138329,
                                        "rx_mcast": 0,
                                        "rx_packets": 57373,
                                        "rx_rate": 24000,
                                        "rx_retries": 0,
                                        "signal": -80,
                                        "state": 27,
                                        "state_ht": true,
                                        "state_pwrmgt": true,
                                        "tx_bytes": 160493312,
                                        "tx_packets": 117245,
                                        "tx_power": 46,
                                        "tx_rate": 78000,
                                        "tx_retries": 2803,
                                        "uptime": 60659
                                }
                        ],
                        "state": "RUN",
                        "tx_bytes": 377192142,
                        "tx_dropped": 5900,
                        "tx_errors": 0,
                        "tx_packets": 1099769,
                        "tx_power": 23,
                        "tx_retries": 0,
                        "up": true,
                        "usage": "user"
                },
                {
                        "bssid": "20:d9:e7:03:4e:9e",
                        "ccq": 957,
                        "channel": 1,
                        "essid": "2",
                        "id": "574a70c3c2e68828fe383733",
                        "name": "ath1",
                        "num_sta": 5,
                        "radio": "ng",
                        "rx_bytes": 3875581611,
                        "rx_crypts": 122286,
                        "rx_dropped": 0,
                        "rx_errors": 0,
                        "rx_frags": 0,
                        "rx_nwids": 82017,
                        "rx_packets": 18687139,
                        "sta_table": [
                                {
                                        "auth_time": 4294967280,
                                        "authorized": true,
                                        "ccq": 991,
                                        "dhcpend_time": 28,
                                        "dhcpstart_time": 19,
                                        "hostname": "ESP_F17C20",
                                        "idletime": 1,
                                        "ip": "192.168.1.183",
                                        "is_11n": true,
                                        "mac": "18:fe:34:f1:7c:20",
                                        "noise": -88,
                                        "rssi": 43,
                                        "rx_bytes": 96823,
                                        "rx_mcast": 0,
                                        "rx_packets": 1229,
                                        "rx_rate": 1000,
                                        "rx_retries": 0,
                                        "signal": -45,
                                        "state": 29,
                                        "state_ht": true,
                                        "state_pwrmgt": true,
                                        "tx_bytes": 73241,
                                        "tx_packets": 1354,
                                        "tx_power": 60,
                                        "tx_rate": 65000,
                                        "tx_retries": 191,
                                        "tx_retries": 191,
                                        "uptime": 7945
                                },
                                {
                                        "auth_time": 4294967251,
                                        "authorized": true,
                                        "ccq": 991,
                                        "dhcpend_time": 0,
                                        "dhcpstart_time": 0,
                                        "idletime": 0,
                                        "ip": "192.168.1.77",
                                        "is_11n": true,
                                        "mac": "28:10:7b:0c:cb:4b",
                                        "noise": -88,
                                        "rssi": 38,
                                        "rx_bytes": 2556496154,
                                        "rx_mcast": 0,
                                        "rx_packets": 1784850,
                                        "rx_rate": 39000,
                                        "rx_retries": 0,
                                        "signal": -50,
                                        "state": 15,
                                        "state_ht": true,
                                        "state_pwrmgt": false,
                                        "tx_bytes": 82495294,
                                        "tx_packets": 1459681,
                                        "tx_power": 60,
                                        "tx_rate": 72222,
                                        "tx_retries": 64058,
                                        "uptime": 10308
                                },
                                {
                                        "auth_time": 4294967263,
                                        "authorized": true,
                                        "ccq": 960,
                                        "dhcpend_time": 1813,
                                        "dhcpstart_time": 1812,
                                        "hostname": "rpi8",
                                        "idletime": 8,
                                        "ip": "192.168.1.28",
                                        "is_11n": true,
                                        "mac": "00:13:ef:71:02:3a",
                                        "noise": -88,
                                        "rssi": 56,
                                        "rx_bytes": 5074370,
                                        "rx_mcast": 0,
                                        "rx_packets": 28894,
                                        "rx_rate": 24000,
                                        "rx_retries": 0,
                                        "signal": -32,
                                        "state": 31,
                                        "state_ht": true,
                                        "state_pwrmgt": true,
                                        "tx_bytes": 5642181,
                                        "tx_packets": 30190,
                                        "tx_power": 60,
                                        "tx_rate": 65000,
                                        "tx_retries": 5528,
                                        "uptime": 56976
                                },
                                {
                                        "auth_time": 4294967240,
                                        "authorized": true,
                                        "ccq": 532,
                                        "dhcpend_time": 1351,
                                        "dhcpstart_time": 0,
                                        "hostname": "raspberrypi",
                                        "idletime": 0,
                                        "ip": "192.168.1.21",
                                        "is_11n": true,
                                        "mac": "00:13:ef:65:03:41",
                                        "noise": -88,
                                        "rssi": 27,
                                        "rx_bytes": 4548578,
                                        "rx_mcast": 0,
                                        "rx_packets": 20068,
                                        "rx_rate": 24000,
                                        "rx_retries": 0,
                                        "signal": -61,
                                        "state": 15,
                                        "state_ht": true,
                                        "state_pwrmgt": false,
                                        "tx_bytes": 3993706,
                                        "tx_packets": 22219,
                                        "tx_power": 60,
                                        "tx_rate": 26000,
                                        "tx_retries": 8445,
                                        "uptime": 57010
                                },
                                {
                                        "auth_time": 4294967280,
                                        "authorized": true,
                                        "ccq": 986,
                                        "dhcpend_time": 0,
                                        "dhcpstart_time": 0,
                                        "idletime": 0,
                                        "ip": "192.168.1.74",
                                        "is_11n": true,
                                        "mac": "b0:c5:54:10:17:df",
                                        "noise": -88,
                                        "rssi": 44,
                                        "rx_bytes": 8709386319,
                                        "rx_mcast": 0,
                                        "rx_packets": 6671427,
                                        "rx_rate": 7222,
                                        "rx_retries": 0,
                                        "signal": -44,
                                        "state": 15,
                                        "state_ht": true,
                                        "state_pwrmgt": false,
                                        "tx_bytes": 313799890,
                                        "tx_packets": 5585837,
                                        "tx_power": 60,
                                        "tx_rate": 72222,
                                        "tx_retries": 316011,
                                        "uptime": 85163
                                }
                        ],
                        "state": "RUN",
                        "tx_bytes": 1852513606,
                        "tx_dropped": 31,
                        "tx_errors": 0,
                        "tx_packets": 16667916,
                        "tx_power": 30,
                        "tx_retries": 0,
                        "up": true,
                        "usage": "user"
                }
        ],
        "version": "3.3.20.4019"
}
   



i don't know what:
"state": 15,
"state_ht": true,
are. anyone any idea.

the RSSI field is defined differently by each hardware supplier. the SIGNAL field used should be in dBm.




Karl

Posted on
Tue May 31, 2016 9:24 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: UBIQUITY UNIFI AP-WiFi: discussions

for ZH vs minimum RSSI: if RSSI min is used ZH is disabled!

https://help.ubnt.com/hc/en-us/articles/205146050-OD-UniFi-How-does-minimum-RSSI-work-
Code: Select all
Behind the scenes, the controller/AP will send a de-authentication packet to this client to kick it right away, similar to the button "Reconnect" found in the controller. It is then up to the client implementation to find a better AP (unlike ZH where among APs themselve decide which one to take over a client). If a client is stubborn enough to stay on the same AP, the controller/AP will NOT force its moving and will trust its decision for a duration before sending another de-authentication packet. In short, this is a soft approach


Karl

Posted on
Wed Jun 01, 2016 4:44 pm
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: UBIQUITY UNIFI AP-WiFi: discussions

FYI, I'm getting the following error:

uniFiAP bad ip in config >>10.0.0.10 <<
uniFiAP bad ip in config >>10.0.0.11 <<
uniFiAP bad ip in config >>10.0.0.12 <<
uniFiAP bad ip in config >>10.0.0.13 <<


Yes, the four APs are at those addresses.

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Wed Jun 01, 2016 5:08 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: UBIQUITY UNIFI AP-WiFi: discussions

ooops

if len(ip) < 10 ==> bad IP
10.0.0.10 is 9 long ..
192.168.x.x works but yours does not ..


fixed in version 0.2.2

Karl

Posted on
Wed Jun 01, 2016 6:58 pm
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: UBIQUITY UNIFI AP-WiFi: discussions

kw123 wrote:
ooops

if len(ip) < 10 ==> bad IP
10.0.0.10 is 9 long ..
192.168.x.x works but yours does not ..


fixed in version 0.2.2

Karl

Thx. We've moved to a different problem now:

Code: Select all
  Stopping plugin uniFiAP (pid 63878)
  uniFiAP                          stopping plugin due to:  :::::  restart / self.stop requested  :::::
  uniFiAP Error                   Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 347, in runConcurrentThread
KeyError: ('0',)

  Stopped plugin uniFiAP
  Upgrading plugin uniFiAP to newer version 0.2.2 (previous version moved to trash)
  Loading plugin "uniFiAP 0.2.2"
  Starting plugin "uniFiAP 0.2.2" (pid 72432)
  Started plugin "uniFiAP 0.2.2"
  uniFiAP                         error, bad ipNumber given to get Dict: 10.0.0.10
  uniFiAP                         empty dict return from 10.0.0.10
  uniFiAP                         error, bad ipNumber given to get Dict: 10.0.0.11
  uniFiAP                         empty dict return from 10.0.0.11
  uniFiAP                         error, bad ipNumber given to get Dict: 10.0.0.12
  uniFiAP                         empty dict return from 10.0.0.12
  uniFiAP                         error, bad ipNumber given to get Dict: 10.0.0.13
  uniFiAP                         empty dict return from 10.0.0.13
  uniFiAP                          .. initalized


From there, the "empty dict" errors repeat every couple of minutes.

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Wed Jun 01, 2016 8:33 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: UBIQUITY UNIFI AP-WiFi: discussions

posted 0.2.3

:oops: there was one more if len(ip) < 10: in the code.

that should be fixed now

Karl

Posted on
Wed Jun 01, 2016 8:38 pm
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: UBIQUITY UNIFI AP-WiFi: discussions

kw123 wrote:
posted 0.2.3

:oops: there was one more if len(ip) < 10: in the code.

that should be fixed now

Karl

Getting closer?

Code: Select all
  uniFiAP                         killing ip#, pid# 10.0.0.10  97064
  uniFiAP                         empty dict return from 10.0.0.10
  uniFiAP                         killing ip#, pid# 10.0.0.11  97088
  uniFiAP                         empty dict return from 10.0.0.11
  uniFiAP                         killing ip#, pid# 10.0.0.12  97109
  uniFiAP                         empty dict return from 10.0.0.12
  uniFiAP                         killing ip#, pid# 10.0.0.13  97131
  uniFiAP                         empty dict return from 10.0.0.13
  uniFiAP                          .. initialized

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Wed Jun 01, 2016 9:44 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: UBIQUITY UNIFI AP-WiFi: discussions

could you switch logging on for (3) dict messages and = (3) details
then copy the/usr/bin/expect line to a terminal and execute


it should look like:
Code: Select all
  /usr/bin/expect  '/Library/Application Support/Perceptive Automation/Indigo 6/plugins/uniFiAP.indigoPlugin/Contents/Server Plugin/getDict.exp' userid password 10.0.0.10 mca-dump
just with your userid password and ip-number


Karl

Who is online

Users browsing this forum: No registered users and 3 guests