I'm connecting my nrf51 with my phone and when I move far from the microcontroller (long distance) the connection is lost what's the function witch rise this error and what's the error code?
I'm connecting my nrf51 with my phone and when I move far from the microcontroller (long distance) the connection is lost what's the function witch rise this error and what's the error code?
There is obviously no "distance" detection. What will happen is that packets get lost and at some point supervision timeout expires without any connection event completed. That's why this parameter of LE Logical Link (LL) layer exists and is part of connection parameters negotiated by Master and Slave (GAP Central and Peripheral if you want). I believe you will get from Soft Device
BLE_GAP_EVT_TIMEOUT, /**< Timeout expired. \n See @ref ble_gap_evt_timeout_t. */
event with
p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN
which is defined as
#define BLE_GAP_TIMEOUT_SRC_CONN 0x03 /**< Connection timeout. */
See ble_gap.h
file and SDK examples for more.
Note that you will get the same event if the counter part simply drop connection without proper termination on LE LE layer (e.g. when there is POWER OFF, Reset, you put it to metal box etc.) So you should know that this isn't 100% indication that device is out of reach due to distance (there is no such magic in BLE;).
Cheers Jan
the reset is happened only when notification is activated for a single characteristic. I think the error is rised from sd_ble_gatts_hvx
but I'm not sure. I followed all where BLE_GAP_EVT_TIMEOUT
is called, I put a flag to see if this code is executed but nothing happened
Now I'm lost how we came from link termination due to missing packets (= maybe the peer device is too far) to notifications and reset;) It looks like you are having another problem and your hypothesis that it's due to distance and link termination is invalid... I'd suggest to open another question with full description of the problem (what are your two devices, what is running there - HW/FW/SW, what are you trying to achieve, what debug information you have and what is the error observed).
Cheers Jan