try: time_out_counter = 0 while not connected_to_peripheral: # Checks if a connection been made if "CONNECTED." in str(response): connected_to_peripheral = True print("\nConnected to {}".format(target_device_address)) sleep(3) # Tries to connect 5 times elif time_out_counter < 5: print("Trying to connect to target device") sleep(3) time_out_counter += 1 else: print("Connection timed out") break if connected_to_peripheral: while True: message = input("\nEnter a message to send to the peripheral:\n") # Sends provided message to the connected device my_dongle.at_spssend(message) except KeyboardInterrupt: # Disconnects and stops the dongle my_dongle.at_gapdisconnect() my_dongle.stop_daemon() exit()
connected = True break if "\r\nNot Connected" in connected_status[0]: sender_dongle.at_gapconnect(mac_addr_to_repeater) time.sleep(5) print("Trying to connect...") time.sleep(2) print("Connected.") print("Getting services...") get_services = sender_dongle.at_get_services() sender_dongle.rx_state = "rx_waiting" time.sleep(2) ready = input("Press enter to start sending data to the repeater dongle.") while 1: data = scan_and_get_results() time.sleep(1) if not data == "": sent = sender_dongle.at_spssend(data) time.sleep(0.1) if len(sent) == 1: if "[Sent]" in sent[0]: print("Data = (" + data + ") sent.") time.sleep(1) data = "" time.sleep(1) sender_dongle.rx_state = "rx_waiting" except KeyboardInterrupt: sender_dongle.at_gapdisconnect() print("Shutting down script.")