Improve UARTServer example
This commit is contained in:
parent
1bc0f759bc
commit
82c00ac209
1 changed files with 14 additions and 10 deletions
|
|
@ -1,15 +1,19 @@
|
|||
from adafruit_ble.uart import UARTServer
|
||||
|
||||
uart = UARTServer()
|
||||
uart.start_advertising()
|
||||
|
||||
# Wait for a connection
|
||||
while not uart.connected:
|
||||
pass
|
||||
while True:
|
||||
uart.start_advertising()
|
||||
|
||||
# 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)
|
||||
# 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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue