← index #6796Issue #10755
Related · high · value 2.750
QUERY · ISSUE

extmod/bluetooth: handling of disconnect in ble_simple_central.py example is misleading

openby tveopened 2021-01-25updated 2021-01-25

The handling of the disconnect event in ble_simple_central.py is misleading. The condition if conn_handle == self._conn_handle:
(line 108) makes it look as if a different value for conn_handle would mean that there's nothing to do, but this is not the case. In particular, a disconnect can happen during the connection process, at least with nimble on the esp32, in which case self._conn_handle is still None and conn_handle != self._conn_handle but calling self._reset() is necessary.

https://github.com/micropython/micropython/blob/203e1d2a65273db3f6ff063ba1124a89c3482c0f/examples/bluetooth/ble_simple_central.py#L108

CANDIDATE · ISSUE

There is mistake in BLE simple central when disconnect is called

closedby cz8pruopened 2023-02-14updated 2023-02-15

There is code in git:
https://github.com/micropython/micropython/blob/41ed01f1394ea608bf9d055120d671e2765cd9b7/examples/bluetooth/ble_simple_central.py#L181-L185

I used that code and my device never disconnected, I found problem in "if" condition and change it to following code, which works for me:

def disconnect(self):
        if self._conn_handle is None:
            return
        self._ble.gap_disconnect(self._conn_handle)):
        self._reset()

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied