Here is the client code for the echo test, the code on the nRF52840 is stock.
Code: Select all
# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
Used with ble_uart_echo_client.py. 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
from adafruit_airlift.esp32 import ESP32
esp32 = ESP32()
adapter = esp32.start_bluetooth()
ble = BLERadio(adapter)
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)