def __init__(self, uuid, service_name, port=BT.PORT_ANY): """ Args: uuid (str): Universally Unique Identifier service_name (str): Name of servie port (:obj:`bluetooth port`): dynamically assigned port """ asyncore.dispatcher.__init__(self) if not BT.is_valid_uuid(uuid): raise ValueError("uuid %s is not valid", uuid) self.port = port self.uuid = uuid self.service_name = service_name self.set_socket(BT.BluetoothSocket(BT.RFCOMM)) self.bind(("", port)) self.listen(1) BT.advertise_service( self.socket, service_name, service_id=uuid, #service_clases = [uuid, SERIAL_PORT_CLASS], profiles=[BT.SERIAL_PORT_PROFILE] ) port = self.socket.getsockname()[1] LOGGER.info("Waiting for connection on RFCOMM channel %d", port)
#!/usr/bin/env python import bluetooth import time server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM) port = bluetooth.get_available_port(bluetooth.RFCOMM) uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848" server_sock.bind(("", port)) server_sock.listen(1) print "listening on port %d" % port try: if bluetooth.is_valid_uuid(uuid): bluetooth.advertise_service(server_sock, "nxt", bluetooth.to_full_uuid(uuid), service_classes=[ bluetooth.SERIAL_PORT_CLASS, ], profiles=[ bluetooth.SERIAL_PORT_PROFILE, ]) client_sock, address = server_sock.accept() print "Accepted connection from ", address while 1: cmd = raw_input("Action?") # Send an action to the client client_sock.send(cmd) time.sleep(1) # Recieve a response from the client f = open('out.jpg', 'w')
import pyautogui pyautogui.FAILSAFE = False X_SCALE_FACTOR = -10 Y_SCALE_FACTOR = 10 server_sock = bt.BluetoothSocket(bt.RFCOMM) server_sock.bind(("", bt.PORT_ANY)) server_sock.listen(1) port = server_sock.getsockname()[1] uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee" print bt.is_valid_uuid(uuid) bt.advertise_service( server_sock, "SampleServer", service_id=uuid, # service_classes=[uuid, bt.SERIAL_PORT_CLASS], # profiles=[bt.SERIAL_PORT_PROFILE], ) client_sock, address = server_sock.accept() print("Accepted connection from {0}".format(address)) data = "!" x_a = 0 y_a = 0 x_v = 0
#!/usr/bin/env python import bluetooth import time server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM) port = bluetooth.get_available_port(bluetooth.RFCOMM) uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848" server_sock.bind(("",port)) server_sock.listen(1) print "listening on port %d" % port try: if bluetooth.is_valid_uuid(uuid): bluetooth.advertise_service(server_sock, "nxt", bluetooth.to_full_uuid(uuid), service_classes=[bluetooth.SERIAL_PORT_CLASS,], profiles=[bluetooth.SERIAL_PORT_PROFILE,]) client_sock,address = server_sock.accept() print "Accepted connection from ",address while 1: cmd = raw_input("Action?") # Send an action to the client client_sock.send(cmd) time.sleep(1) # Recieve a response from the client f = open('out.jpg', 'w') f.write('') f.close() result = '' data = ''