Exemplo n.º 1
0
    def checkConnection(self):
        command = "iwconfig " + self.interface
        status = weioSubprocess.shellBlocking(command)

        print(str(status))
        # We are in STA mode, so check if we are connected
        if (status == "ERR_CMD") or "No such device" in status:
            # WiFi is DOWN
            print "Wifi is DOWN"
            self.mode = None
        # Check if wlan0 is in Master mode
        elif "Mode:Master" in status:
            print "AP Mode"
            self.mode = "ap"
            #self.essid = status.strip().startswith("ESSID:").split(':')[1]
        elif "Mode:Managed" in status:
            if "Access Point: Not-Associated" in status:
                self.mode = None
            else:
                self.mode = "sta"

        # We can not serve anything if we are not in sta or ap mode
        print "CHECKING WIFI!"
        if (self.mode != None):
            print "self.mode = " + self.mode
        print "weioIpAddress.getLocalIpAddress() = " + weioIpAddress.getLocalIpAddress(
        )

        if (self.mode == None):
            self.disconnectedCounter = self.disconnectedCounter + 1
        else:
            self.disconnectedCounter = 0

        if (self.disconnectedCounter >= 2 or
            (self.mode == "sta" and weioIpAddress.getLocalIpAddress() == '')):
            # Move to Master mode
            print "Trying to move to AP RESCUE mode..."
            subprocess.call("scripts/wifi_set_mode.sh rescue", shell=True)

            self.disconnectedCounter = 0

            # Restart Tornado (shell script bring it up whenever it exits)
            #cmd = "/etc/init.d/weio_run restart"
            #weioSubprocess.shellBlocking(cmd)
            print "************* EXITING ****************"
            os._exit(os.EX_OK)

        # At this point connection has been maid, and all we have to do is check ESSID
        #print "WIFI ESSID : ", status
        pat = r"(?<=ESSID:\")(.*\n?)(?=\")"
        #print "RESULT", re.findall(pat, status)[0]
        essidName = re.findall(pat, status)
        if (len(essidName) > 0):
            self.essid = essidName[0]
Exemplo n.º 2
0
    def checkConnection(self) :
        command = "iwconfig " + self.interface
        status = weioSubprocess.shellBlocking(command)

        print(str(status))
        # We are in STA mode, so check if we are connected
        if (status == "ERR_CMD") or "No such device" in status :
            # WiFi is DOWN
            print "Wifi is DOWN"
            self.mode = None
        # Check if wlan0 is in Master mode
        elif "Mode:Master" in status :
            print "AP Mode"
            self.mode = "ap"
            #self.essid = status.strip().startswith("ESSID:").split(':')[1]
        elif "Mode:Managed" in status :
            if "Access Point: Not-Associated" in status :
                self.mode = None
            else :
                self.mode = "sta"

        # We can not serve anything if we are not in sta or ap mode
        print "CHECKING WIFI!"
        if (self.mode != None):
           print "self.mode = " + self.mode
        print "weioIpAddress.getLocalIpAddress() = " + weioIpAddress.getLocalIpAddress()

        if (self.mode == None):
            self.disconnectedCounter = self.disconnectedCounter + 1
        else:
            self.disconnectedCounter = 0

        if ( self.disconnectedCounter >= 2 or (self.mode == "sta" and weioIpAddress.getLocalIpAddress() == '') ):
            # Move to Master mode
            print "Trying to move to AP RESCUE mode..."
            subprocess.call("scripts/wifi_set_mode.sh rescue", shell=True)

            self.disconnectedCounter = 0

            # Restart Tornado (shell script bring it up whenever it exits)
            #cmd = "/etc/init.d/weio_run restart"
            #weioSubprocess.shellBlocking(cmd)
            print "************* EXITING ****************"
            os._exit(os.EX_OK)

        # At this point connection has been maid, and all we have to do is check ESSID
        #print "WIFI ESSID : ", status
        pat = r"(?<=ESSID:\")(.*\n?)(?=\")"
        #print "RESULT", re.findall(pat, status)[0]
        essidName = re.findall(pat, status)
        if (len(essidName)>0):
            self.essid = essidName[0]
Exemplo n.º 3
0
    def sendIp(self,rq):

        # get configuration from file
        config = weioConfig.getConfiguration()

        data = {}
        ip = weioIpAddress.getLocalIpAddress()
        #publicIp = weioIpAddress.getPublicIpAddress()
        data['requested'] = rq['request']
        data['status'] = config["dns_name"] + " on " + ip
        # Send connection information to the client
        self.broadcast(clients, json.dumps(data))
Exemplo n.º 4
0
    def sendIp(self, rq):

        # get configuration from file
        config = weioConfig.getConfiguration()

        data = {}
        ip = weioIpAddress.getLocalIpAddress()
        #publicIp = weioIpAddress.getPublicIpAddress()
        data['requested'] = rq['request']
        data['status'] = config["dns_name"] + " on " + ip
        # Send connection information to the client
        self.broadcast(clients, json.dumps(data))
Exemplo n.º 5
0
    def pushBasicInfo(self,rq):
        # here we get basic info from WeIO

        myIp = weioIpAddress.getLocalIpAddress()

        if (platform=='mips') :
            myAvahiName = weioAvahi.getAvahiName()
        else :
            myAvahiName = 'weio'

        data = {}
        data['requested'] = rq['request']
        data['ip'] = myIp
        data['dnsName'] = myAvahiName
        self.send(json.dumps(data))
Exemplo n.º 6
0
    def pushBasicInfo(self, rq):
        # here we get basic info from WeIO

        myIp = weioIpAddress.getLocalIpAddress()

        if (platform == 'mips'):
            myAvahiName = weioAvahi.getAvahiName()
        else:
            myAvahiName = 'weio'

        data = {}
        data['requested'] = rq['request']
        data['ip'] = myIp
        data['dnsName'] = myAvahiName
        self.send(json.dumps(data))