From 82c00ac209e653017e7776b6f9f73f293a5d459f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 1 Feb 2019 11:02:37 -0500 Subject: [PATCH] Improve UARTServer example --- examples/ble_uart_echo_test.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/ble_uart_echo_test.py b/examples/ble_uart_echo_test.py index 9a1502c..40f1173 100644 --- a/examples/ble_uart_echo_test.py +++ b/examples/ble_uart_echo_test.py @@ -1,15 +1,19 @@ from adafruit_ble.uart import UARTServer uart = UARTServer() -uart.start_advertising() - -# Wait for a connection -while not uart.connected: - pass - -# When the client disconnects, the program will exit. -while uart.connected: - # Returns b'' if nothing was read. - one_byte = uart.read(1) - if one_byte: - uart.write(one_byte) + +while True: + uart.start_advertising() + + # Wait for a connection + while not uart.connected: + pass + + while uart.connected: + # Returns b'' if nothing was read. + one_byte = uart.read(1) + if one_byte: + uart.write(one_byte) + + # When disconnected, arrive here. Go back to the top + # and start advertising again.