Skip to content

Commit 82c00ac

Browse files
committed
Improve UARTServer example
1 parent 1bc0f75 commit 82c00ac

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

examples/ble_uart_echo_test.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
from adafruit_ble.uart import UARTServer
22

33
uart = UARTServer()
4-
uart.start_advertising()
5-
6-
# Wait for a connection
7-
while not uart.connected:
8-
pass
9-
10-
# When the client disconnects, the program will exit.
11-
while uart.connected:
12-
# Returns b'' if nothing was read.
13-
one_byte = uart.read(1)
14-
if one_byte:
15-
uart.write(one_byte)
4+
5+
while True:
6+
uart.start_advertising()
7+
8+
# Wait for a connection
9+
while not uart.connected:
10+
pass
11+
12+
while uart.connected:
13+
# Returns b'' if nothing was read.
14+
one_byte = uart.read(1)
15+
if one_byte:
16+
uart.write(one_byte)
17+
18+
# When disconnected, arrive here. Go back to the top
19+
# and start advertising again.

0 commit comments

Comments
 (0)