Beispiel #1
0
    def run(self):
        self.running = True
        

        deviceIDStr = fileconfig.config.get('TRIGGERS','bluetooth_device_id')
        deviceID = hardwareconfig.BTStrToHex(deviceIDStr)
        
        if ':' not in deviceIDStr:
            eventQueue.put(("Status",'bluetooth','Error: Not configured'))
            eventQueue.put(("Log",'Bluetooth monitor error: Device not configured'))
            return
        eventQueue.put(("Status",'bluetooth','Connecting to device...'))
        
        #lack of timeout on this is not good
        error, result = winsockbtooth.connect(deviceID)
        if error == True:
            if result == 10060:
                eventQueue.put(("Status",'bluetooth',"Error: Connect failed"))
                eventQueue.put(("Log",'Bluetooth: Could not connect to %s'%deviceIDStr))
            elif result == 10050:
                eventQueue.put(("Status",'bluetooth',"Error: No Bluetooth"))
                eventQueue.put(("Log","Bluetooth: Error 10050: Bluetooth not enabled"))
            else:
                eventQueue.put(("Status",'bluetooth','Error: %s'%result))
                eventQueue.put(("Log",'Bluetooth: other error: %s'%result))
                
            return 
        
        self.socket = result
        eventQueue.put(("Log",'Bluetooth: Connected to device %s'%deviceIDStr))
        eventQueue.put(("Status",'bluetooth','Active'))
        while self.running == True:
            error,result=winsockbtooth.recv(self.socket)
            if error == True:
                    if self.running == False: 
                        eventQueue.put(("Status",'bluetooth','Not Running'))
                        return
                    
                    eventHandle('E_BLUETOOTH',"Bluetooth connection lost")
                    eventQueue.put(("Status",'bluetooth','Error: Connection Lost'))
                    
                    #if we didnt lose connection under trigger conditions
                    #assume user wants auto-reconnect (?)
                    error = True
                    attempts = 0
                    while error == True and attempts < 7:
                        eventQueue.put(("Status",'bluetooth','Error: Connection Failed'))
                        time.sleep(10*1+(attempts*5))
                        eventQueue.put(("Status",'bluetooth','Connecting...'))
                        error, result = winsockbtooth.connect(deviceID)
                        attempts = attempts + 1
                    self.socket = result
                    
                    eventQueue.put(("Log",'Bluetooth: Reconnected to device %s'%deviceIDStr))
                    eventQueue.put(("Status",'bluetooth','Active'))

                
        eventQueue.put(("Status",'bluetooth','Not Running'))       
Beispiel #2
0
 def run(self):
     error, result = winsockbtooth.connect(deviceID = self.deviceID)
     if error == False:
         winsockbtooth.closesocket(result)
         winsockbtooth.WSACleanup()
     
     self.callback(error,result)
     return
    def run(self):
        self.running = True

        deviceIDStr = fileconfig.config.get('TRIGGERS', 'bluetooth_device_id')
        deviceID = hardwareconfig.BTStrToHex(deviceIDStr)

        if ':' not in deviceIDStr:
            eventQueue.put(("Status", 'bluetooth', 'Error: Not configured'))
            eventQueue.put(
                ("Log", 'Bluetooth monitor error: Device not configured'))
            return
        eventQueue.put(("Status", 'bluetooth', 'Connecting to device...'))

        #lack of timeout on this is not good
        error, result = winsockbtooth.connect(deviceID)
        if error == True:
            if result == 10060:
                eventQueue.put(
                    ("Status", 'bluetooth', "Error: Connect failed"))
                eventQueue.put(
                    ("Log",
                     'Bluetooth: Could not connect to %s' % deviceIDStr))
            elif result == 10050:
                eventQueue.put(("Status", 'bluetooth', "Error: No Bluetooth"))
                eventQueue.put(
                    ("Log", "Bluetooth: Error 10050: Bluetooth not enabled"))
            else:
                eventQueue.put(("Status", 'bluetooth', 'Error: %s' % result))
                eventQueue.put(("Log", 'Bluetooth: other error: %s' % result))

            return

        self.socket = result
        eventQueue.put(
            ("Log", 'Bluetooth: Connected to device %s' % deviceIDStr))
        eventQueue.put(("Status", 'bluetooth', 'Active'))
        while self.running == True:
            error, result = winsockbtooth.recv(self.socket)
            if error == True:
                if self.running == False:
                    eventQueue.put(("Status", 'bluetooth', 'Not Running'))
                    return

                eventHandle('E_BLUETOOTH', "Bluetooth connection lost")
                eventQueue.put(
                    ("Status", 'bluetooth', 'Error: Connection Lost'))

                #if we didnt lose connection under trigger conditions
                #assume user wants auto-reconnect (?)
                error = True
                attempts = 0
                while error == True and attempts < 7:
                    eventQueue.put(
                        ("Status", 'bluetooth', 'Error: Connection Failed'))
                    time.sleep(10 * 1 + (attempts * 5))
                    eventQueue.put(("Status", 'bluetooth', 'Connecting...'))
                    error, result = winsockbtooth.connect(deviceID)
                    attempts = attempts + 1
                self.socket = result

                eventQueue.put(
                    ("Log",
                     'Bluetooth: Reconnected to device %s' % deviceIDStr))
                eventQueue.put(("Status", 'bluetooth', 'Active'))

        eventQueue.put(("Status", 'bluetooth', 'Not Running'))