loadcell/btproxy/ble_uart_echo_test.py

28 lines
803 B
Python
Raw Permalink Normal View History

2024-05-08 20:31:38 +00:00
# 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)