예제 #1
0
        def autodetect(self):
            list_of_pebbles = list()

            if self.mac_address is not None and len(self.mac_address) is 4:
                # we have the friendly name, let's get the full mac address
                log.warn("Going to get full address for device %s, ensure device is broadcasting." % self.mac_address)
                # scan for active devices
                devices = finddevices(timeout=8)

                for device in devices:
                    if re.search(r"Pebble " + self.mac_address, device[1], re.IGNORECASE):
                        log.debug("Found Pebble: %s @ %s" % (device[1], device[0]))
                        list_of_pebbles.append(device)

                if len(list_of_pebbles) is 1:
                    return list_of_pebbles[0][0]
                else:
                    raise LightBluePebbleError(self.mac_address, "Failed to find Pebble")
            else:
                # no pebble id was provided... give them the GUI selector
                try:
                    return selectdevice()[0]
                except TypeError:
                    log.warn("failed to select a device in GUI selector")
                    self.mac_address = None
예제 #2
0
        def autodetect(self):
            list_of_pebbles = list()

            if self.mac_address is not None and len(self.mac_address) is 4:
                # we have the friendly name, let's get the full mac address
                log.warn(
                    "Going to get full address for device %s, ensure device is broadcasting."
                    % self.mac_address)
                # scan for active devices
                devices = finddevices(timeout=8)

                for device in devices:
                    if re.search(r'Pebble ' + self.mac_address, device[1],
                                 re.IGNORECASE):
                        log.debug("Found Pebble: %s @ %s" %
                                  (device[1], device[0]))
                        list_of_pebbles.append(device)

                if len(list_of_pebbles) is 1:
                    return list_of_pebbles[0][0]
                else:
                    raise LightBluePebbleError(self.mac_address,
                                               "Failed to find Pebble")
            else:
                # no pebble id was provided... give them the GUI selector
                try:
                    return selectdevice()[0]
                except TypeError:
                    log.warn("failed to select a device in GUI selector")
                    self.mac_address = None
예제 #3
0
    def client_socket():
        log("Attempting to discover servers")
        # Get the device from a menu
        device = lightblue.selectdevice()

        # Was a device chosen
        if device:
            try:
                # Connect to the device
                conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
                conn.connect((device[0], BT_CHANNEL))
                return conn
            except:
                log("Failed to connect to %s" % device[1])

        # We get here, we didn't connect
        return None
예제 #4
0
 def client_socket():
     log("Attempting to discover servers")
     # Get the device from a menu
     device=lightblue.selectdevice()
     
     # Was a device chosen
     if device:
         try:
             # Connect to the device
             conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
             conn.connect((device[0], BT_CHANNEL))
             return conn
         except:
             log("Failed to connect to %s"%device[1])
     
     # We get here, we didn't connect
     return None
예제 #5
0
파일: pong.py 프로젝트: lastminutelabs/pong
def join_two_player():
    global two_player
    global server
    global connection
    
    # Print a message
    menu_message(u"Please wait, searching...")
    
    # Select the device from the list
    device=lightblue.selectdevice()
    menu_message(u"Conecting to %s"%device[1])

    # Connect to the channel
    try:
        connection = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
        connection.connect((device[0], BT_CHANNEL))
    except:
        menu_message(u"Failed to connect to %s"%device[1])
        return

    try:
        # If we connected, send the starting flag
        connection.send("start")
        
        # Start the game in 2 player client mode
        two_player=True
        server=False
        initialize_game()
        play_game()
    except:
        pass

    initialize_menu()
    
    # Close the connection when we are done
    connection.close()
예제 #6
0
import lightblue

hostaddr = lightblue.selectdevice()[0]

service = lightblue.findservices(addr=hostaddr, name='Wireless iAP')[0]
print 'service:', service
serviceport = service[1]

s = lightblue.socket()
s.connect((hostaddr, serviceport))

d = "\xFF\x55\x02\x00\xEE\x10"
print "Send data:", d.encode('hex')
s.send(d)

data = s.recv(1024)
print "Got data:", data.encode('hex')
s.close()

예제 #7
0
    def __init__(self):
        threading.Thread.__init__(self)

    def callback(self, id):
        box = inbox.Inbox()
        #if id in box.sms_messages():
        sms = SMS(str(id), "9033588066", box.address(id), box.content(id),
                  str(box.time(id)))
        toSend = sms.toXML()
        self.sndSkt.send(toSend)
        box.delete(id)

    def run(self):
        print "Inside Client receiver Thread :D"
        self.sndSkt = lightblue.socket()
        self.sndSkt.connect((device[0], 2))
        box = inbox.Inbox()
        box.bind(self.callback)
        app_lock = e32.Ao_lock()
        app_lock.wait()
        self.sndSkt.close()


device = lightblue.selectdevice()
print "Connecting to Device" + device[1]
ReceiverThread().start()
SenderThread().start()
print "Waiting for new SMS messages.."
app_lock = e32.Ao_lock()
app_lock.wait()
예제 #8
0
"""
Shows how to send "Hello world" over a RFCOMM client socket.
"""
import lightblue

# ask user to choose the device to connect to
hostaddr = lightblue.selectdevice()[0]        

# find the EchoService advertised by the simple_server.py example
echoservice = lightblue.findservices(addr=hostaddr, name="EchoService")[0]
serviceport = echoservice[1]

s = lightblue.socket()
s.connect((hostaddr, serviceport))
s.send("Hello world!")
print "Sent data, waiting for echo..."
data = s.recv(1024)
print "Got data:", data
s.close()


# Note:
# Instead of calling selectdevice() and findservices(), you could do:
#       hostaddr, serviceport, servicename = lightblue.selectservice()
# to ask the user to choose a service (instead of just choosing the device).