Replies: 1 comment 3 replies
-
This is blocking the async event loop from running. Use |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
On Windows, a bleak client will automatically reconnect when the peripheral disconnects. This is undesirable behaviour in cases where it is required to completely terminate the connection with the host. For example, consider a
DisconnectionService
with aa single characteristic:
disconnection_reason_char
. If a valid disconnection reason is written to the characteristic, the service immediately disconnects from the host. Such a service is useful when writing integration tests for BLE devices.What I Did
I wrote a BLE application using mbed-os that contains a
DisconnectionService
. Then, I built and flashed the application onto a NUCLEO-WB55RG; however, any Mbed BLE-enabled development board should work. Lastly, I wrote a Python script to interact with the service using bleak.The main
run
function is shown below. It scans for and attempts to connect to a device named "Disconnection", viz. the name of my peripheral. Once connected, it writes a valid disconnection reason todisconnection_reason_char
of theDisconnectionService
. Therefore, the peripheral immediately disconnects from the host.I set the log level to DEBUG and observed traces from bleak (see below). We see that
_ConnectionStatusChanged_Handler
gets flipped to 0 afterdisconnection_reason_char
is written with0x13
. This is expected because that corresponds to user termination, a valid disconnection reason. However, ~15 seconds later_ConnectionStatusChanged_Handler
gets flipped to 1; and, after the 1 minute pause, we see that the client has reconnected with the peripheral.Compiling and running the Mbed BLE application
Clone and enter the repository:
Link dependencies:
Build and flash for a given
<target>
and<toolchain>
:Attachments
automatic_reconnection_log.txt
P.S. apologies for all the Mbed-specific stuff.
Beta Was this translation helpful? Give feedback.
All reactions