def get_ip(): global flag blue = BluetoothServer(data_recieved, power_up_device=True) flag = True while flag: time.sleep(1) blue.send(host_IP) blue.stop()
def test_server_start_stop(): bts = BluetoothServer(None, auto_start = False) bts.start() assert bts.running bts.stop() assert not bts.running
def bluetooth_client(done_event): def data_received(data): print(data) # adds data to the queue and leaves s = BluetoothServer(data_received) #starts RFCOMM Server while not (done_event.wait(0.00001)): pass s.stop()
def run(event): def data_received(data): updated_data.append(data) # adds data to the queue and leaves s = BluetoothServer(data_received) #starts RFCOMM Server while True: event_set = event.wait(0.0001) if event_set: s.close() break pass
def test_server_default_values(): def data_received(data): pass bts = BluetoothServer(data_received) assert bts.data_received_callback == data_received assert bts.device == "hci0" assert bts.server_address == bta0.address assert bts.running assert bts.port == 1 assert bts.encoding == "utf-8" assert bts.when_client_connects == None assert bts.when_client_disconnects == None bts.stop()
def __init__(self, isDebug=False): self.__debug = isDebug self.joystick_action = JoystickAction(self.__debug) self.cannon_action = CannonAction(self.__debug) self.__bt_server = BluetoothServer(self.data_received, self.__debug) self.__bt_server.when_client_connects = self.bt_client_connected self.__bt_server.when_client_disconnects = self.bt_client_disconnected self.__bt_server.start() self.__cruncher_menu = CruncherMenu(self.__debug) self.__joystick_input = JoystickInput(self.__debug) self.__joystick_input.init_joystick() atexit.register(self.cleanup) if (self.__debug): print("Bluetooth Adapter Address:" + self.__bt_server.adapter.address)
def test_client_default_values(): def data_received(data): pass bts = BluetoothServer(data_received, device = "hci1") btc = BluetoothClient(bta1.address, data_received) assert btc.data_received_callback == data_received assert btc.device == "hci0" assert btc.server == bta1.address assert btc.client_address == bta0.address assert btc.connected assert btc.port == 1 assert btc.encoding == "utf-8" btc.disconnect() bts.stop()
def test_client_alt_values(): def data_received(data): pass bts = BluetoothServer(None, port = 2, encoding = None) btc = BluetoothClient(bta0.address, data_received, device = "hci1", auto_connect = False, port = 2, encoding = None) assert btc.data_received_callback == data_received assert btc.device == "hci1" assert btc.client_address == bta1.address assert not btc.connected assert btc.port == 2 assert btc.encoding == None btc.connect() assert btc.connected btc.disconnect() assert not btc.connected bts.stop()
def test_send_receive(): data_received_at_server = Event() data_received_at_client = Event() def data_received_server(data): assert data == "hiserver" data_received_at_server.set() def data_received_client(data): assert data == "hiclient" data_received_at_client.set() bts = BluetoothServer(data_received_server, device = "hci0") btc = BluetoothClient(bta0.address, data_received_client, device = "hci1") btc.send("hiserver") assert data_received_at_server.wait(1) bts.send("hiclient") assert data_received_at_server.wait(1) btc.disconnect() bts.stop()
def __init__(self): super(Ui, self).__init__() uic.loadUi(strLocal + '/UI/MatChinh.ui', self) self.TimeTxt = self.findChild(QtWidgets.QLabel, 'Time') self.DateTxt = self.findChild(QtWidgets.QLabel, 'Ngay') timer = QTimer(self) timer.timeout.connect(self.showTime) timer.start(1000) self.btn_count = 0 self.led_status = 0 self.led = LED("GPIO17") self.cutRun = LED("GPIO26") self.screen_btn = Button("BOARD7") clock_time = QTimer(self) clock_time.timeout.connect(self.actions) clock_time.start(100) def data_received(data): print(data) self.TimeTxt.setText(data) s.send(data) s = BluetoothServer(data_received)
if GPIO.input(ECHO) == GPIO.HIGH: break while True: pulso_fin = time.time() if GPIO.input(ECHO) == GPIO.LOW: break duracion = pulso_fin - pulso_inicio #cm distancia = (34300 * duracion) / 2 if distancia > 200: distancia = 200 print("Distancia: %.2f cm" % distancia) s.send(str(round(distancia, 2))) GPIO.cleanup() s = BluetoothServer(data_received_handler, port=1, when_client_connects=connect_handler, when_client_disconnects=disconnect_handler) print('Listening...') pause()
host_mac = re.split(' |\n|\t', result)[2] print("host_mac: " + host_mac) adapter = BluetoothAdapter() print("Powered = {}".format(adapter.powered)) print(adapter.paired_devices) num = 0 Connection = True conn = True def data_recieved(data): global num, conn print("received data #" + str(num)) print(data) c.send(host_IP) num += 1 conn = True c = BluetoothServer(data_recieved, power_up_device=True) while Connection: if (c.client_connected and conn): print("connection from: " + str(c.client_address)) conn = False try: time.sleep(1) except KeyboardInterrupt: print("disconnected by keyboard") Connection = False
sc.close() surf = pygame.image.load("test.png") # Load local image for piTFT buff = surf.get_rect() buff.left = 0 buff.top = 0 if state == 2: # If in camera display mode server.send('d') # When client connects, send ip def when_client_connects(): temp = check_output(['hostname', '-I']) server.send(re.sub('\n', '', temp)) server = BluetoothServer(data_received_callback=data_received, when_client_connects=when_client_connects) #WHILE PROGRAM IS RUNNING while isRunning: clockvar.tick(framerate) #manual framerate control so we can edit it screen.fill(LIGHTBLUE) #erase the work space if state == 0 or state == 1: screen.blit(chikin, chikinrect) if state == 0: #start screen # render start button text_surface = my_font.render("Start", True, WHITE) rect = text_surface.get_rect(center=center_button_loc) bkgd_rect = pygame.draw.rect(screen, YOLK, (rect.left - 15, rect.top - 15,
#detection.detect('Jordan','8329300230','9152273680', int(tmax), int(tmin)) # return detection.detect(primaryName, primaryNumber, secondaryNumber, int(tmax), int(tmin)) return detection.detect(primaryName, primaryNumber, secondaryNumber, int(tmax)) def stop(data): print("here2") print(thread.toString()) stringCmd = 'Command: ' + data[0] print(stringCmd) s.send(stringCmd) #detection.stop() thread.exit() def client_connects(): print('Client Connected!') def client_disconnects(): print('Client Disconnected!') s = BluetoothServer(data_received, True, 'hci0', 1, 'utf-8', False, client_connects, client_disconnects) print(s.client_address) pause()
#print(result) time.sleep(3) result = read_all_data_from_arduino() #print(result) result = do_stop() #print(result) result = read_all_data_from_arduino() #print(result) try: print('===> CREATING BLUETOOTH SERVER <===') s = BluetoothServer(data_received_callback=data_received, when_client_connects=client_connect, when_client_disconnects=client_disconnect) print('---> waiting for connection <---') pause() except ConnectionAbortedError as ex: print("*** ERROR ***: got connection request for closed socket: ex=" + str(ex)) sys.exit(5) except OSError as ex: print("*** ERROR ***: got mysterious OSError: ex=" + str(ex)) sys.exit(6) except Exception as ex: print("*** PROGRAM ERROR ***: ex=" + str(ex)) sys.exit(7)
#!/usr/bin/python3 from bluedot.btcomm import BluetoothServer from signal import pause import time def data_received(data): print(data) s.send(data) while True: try: s = BluetoothServer(data_received) pause() except Exception as e: print("ERROR: e=" + str(e)) time.sleep(2)
# sleep(0.1) # reset_display() def client_connected(): print("client connected") def client_disconnected(): print("client disconnected") print("init") server = BluetoothServer(data_received, auto_start=False, when_client_connects=client_connected(), when_client_disconnects=client_disconnected()) server.start() def run(): running = True button_down = False reset_display() try: while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN and button_down == False: