This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Peripheral Connection Issues When Configured as Dual Central and Peripheral

I am working on integrated peripheral and central device used for indoor positioning.  The device has two modes, at boot it is a peripheral for some duration of time then it stops advertising and becomes a central to perform the positioning activities.  When the device is central functionality works as expected.  When the device is a peripheral advertising works but I can no longer connect to the device it immediately disconnects.  I have tried both nRFConnect for Windows and my iPhone.  I am using SDK 14.2 and SD 132 v5.0.0.

The desktop nRFConnect gives me this message the following:

And I see the following in RTT <error> ble_gatt: sd_ble_gap_data_length_update() (reply) returned unexpected value 0x8

I have the following SDH values set:

// <i> These values are not used directly by the SoftDevice handler but the application or other libraries might depend on them.
// <i> Keep them up-to-date with the desired configuration.
//==========================================================
// <o> NRF_SDH_BLE_PERIPHERAL_LINK_COUNT - Maximum number of peripheral links. 
#ifndef NRF_SDH_BLE_PERIPHERAL_LINK_COUNT
#define NRF_SDH_BLE_PERIPHERAL_LINK_COUNT 1
#endif

// <o> NRF_SDH_BLE_CENTRAL_LINK_COUNT - Maximum number of central links. 
#ifndef NRF_SDH_BLE_CENTRAL_LINK_COUNT
#define NRF_SDH_BLE_CENTRAL_LINK_COUNT 1
#endif

// <o> NRF_SDH_BLE_TOTAL_LINK_COUNT - Maximum number of total concurrent connections using the default configuration. 
#ifndef NRF_SDH_BLE_TOTAL_LINK_COUNT
#define NRF_SDH_BLE_TOTAL_LINK_COUNT 1
#endif

// <o> NRF_SDH_BLE_GAP_EVENT_LENGTH - The time set aside for this connection on every connection interval in 1.25 ms units. 
#ifndef NRF_SDH_BLE_GAP_EVENT_LENGTH
#define NRF_SDH_BLE_GAP_EVENT_LENGTH 5
#endif

// <o> NRF_SDH_BLE_GATT_MAX_MTU_SIZE - Static maximum MTU size. 
#ifndef NRF_SDH_BLE_GATT_MAX_MTU_SIZE
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 247
#endif

// <o> NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE - Attribute Table size in bytes. The size must be a multiple of 4. 
#ifndef NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE
#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408
#endif

// <o> NRF_SDH_BLE_VS_UUID_COUNT - The number of vendor-specific UUIDs. 
#ifndef NRF_SDH_BLE_VS_UUID_COUNT
#define NRF_SDH_BLE_VS_UUID_COUNT 6
#endif

// <q> NRF_SDH_BLE_SERVICE_CHANGED  - Include the Service Changed characteristic in the Attribute Table.
 

#ifndef NRF_SDH_BLE_SERVICE_CHANGED
#define NRF_SDH_BLE_SERVICE_CHANGED 1
#endif

And here is sample of the debug output:

00> RESET
000> SDK: FWID=157, VERSION=5.0.0
00> [00000000] <info> app: HFCLK running: N
00> [00000000] <info> app: Watchdog enabled and runs in sleep
00> [00000000] <info> app: Reboot reason: 0x00000004 Decode:
00> Software Reset
00> [00000000] <info> app: Dfu ver=255
00> [00000000] <error> app: No bootloader was found
00> [00000000] <error> app: No bootloader found!! Skipping DFU service init
00> [00000014] <debug> ble_gatt: Requesting to update ATT MTU to 247 bytes on connection 0x0.
00> [00000014] <debug> ble_gatt: Requesting to update data length to 251 on connection 0x0.
00> [00000014] <debug>app: Ble Evt: Handle 0, role: 1, ID: 16
00> [00000014] <debug> app: BLE Periph Evt handler 16
00> [00000014] <info> app: Connected
00> [00000014] <debug> ble_gatt: Data length updated to 27 on connection 0x0.
00> [00000014] <debug> ble_gatt: max_rx_octets: 27
00> [00000014] <debug> ble_gatt: max_tx_octets: 27
00> [00000014] <debug> ble_gatt: max_rx_time: 328
00> [00000014] <debug> ble_gatt: max_tx_time: 328
00> [00000014] <debug> app: Ble Evt: Handle 0, role: 1, ID: 36
00> [00000014] <debug> app: BLE Periph Evt handler 36
00> [00000014] <debug> ble_gatt: Peer on connection 0x0 requested a data length of 251 bytes.
00> [00000014] <debug> ble_gatt: Updating data length to 251 bytes on connection 0x0.
00> [00000014] <error> ble_gatt: sd_ble_gap_data_length_update() (reply) returned unexpected value 0x8.
00> [00000014] <debug> app: Ble Evt: Handle 0, role: 1, ID: 35
00> [00000014] <debug> app: BLE Periph Evt handler 35
00> [00000014] <debug> app: Ble Evt: Handle 0, role: 1, ID: 17
00> [00000014] <debug> app: BLE Periph Evt handler 17
00> [00000014] <info> app: Disconnected

# Logging stopped @ 23 Nov 2018 12:47:23 

Thanks in advance!

Parents
  • Hi,

    Just to avoid race conditions I suggest you set NRF_SDH_BLE_TOTAL_LINK_COUNT to 2, this means you can have both a peripheral and central link at the same time.

    Make sure that you have control of the conn_handle's, since it may for instance be 0 or 1 (or more). This may explain why sd_ble_gap_data_length_update() return NRF_ERROR_INVALID_STATE (No link has been established, see ble_gap.h), if for instance you are trying to initiate the procedure on the wrong conn_handle (link is not established).

    I notice it says Disconnected, but what is the disconnect reason? E.g. check p_ble_evt->evt.gap_evt.params.disconnected.reason on BLE_GAP_EVT_DISCONNECTED event. Various reasons listed in ble_hci.h. 

    Best regards,
    Kenneth

Reply
  • Hi,

    Just to avoid race conditions I suggest you set NRF_SDH_BLE_TOTAL_LINK_COUNT to 2, this means you can have both a peripheral and central link at the same time.

    Make sure that you have control of the conn_handle's, since it may for instance be 0 or 1 (or more). This may explain why sd_ble_gap_data_length_update() return NRF_ERROR_INVALID_STATE (No link has been established, see ble_gap.h), if for instance you are trying to initiate the procedure on the wrong conn_handle (link is not established).

    I notice it says Disconnected, but what is the disconnect reason? E.g. check p_ble_evt->evt.gap_evt.params.disconnected.reason on BLE_GAP_EVT_DISCONNECTED event. Various reasons listed in ble_hci.h. 

    Best regards,
    Kenneth

Children
Related