28 lines
803 B
Python
28 lines
803 B
Python
# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
"""
|
|
Can be used with ble_uart_echo_client.py or with the UART page on the
|
|
Adafruit Bluefruit Connect app. Receives characters from the UARTService
|
|
and transmits them back.
|
|
"""
|
|
|
|
from adafruit_ble import BLERadio
|
|
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
|
|
from adafruit_ble.services.nordic import UARTService
|
|
|
|
ble = BLERadio()
|
|
uart = UARTService()
|
|
advertisement = ProvideServicesAdvertisement(uart)
|
|
|
|
while True:
|
|
ble.start_advertising(advertisement)
|
|
while not ble.connected:
|
|
pass
|
|
while ble.connected:
|
|
# Returns b'' if nothing was read.
|
|
one_byte = uart.read(1)
|
|
if one_byte:
|
|
print(one_byte)
|
|
#uart.write(one_byte)
|