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

Use BLE_GAP_EVT_ADV_REPORT to scan for beacon

Setup:

Module: nRF51822.

SDK version:nRF5_SDK_11.0.0_89a8197.

Example: ble_app_uart.

Softdevice: S130.

I use ble_nus_string_send on the BLE_GAP_EVT_ADV_REPORT in on_ble_evt tring to scan for

beacon and found that it only outputs strings less than 20 bytes. Dig a little further, I found it's

because of

if (length > BLE_NUS_MAX_DATA_LEN)
{
return NRF_ERROR_INVALID_PARAM;
}

in ble_nus.c while BLE_NUS_MAX_DATA_LEN is defined as (GATT_MTU_SIZE_DEFAULT - 3) and

GATT_MTU_SIZE_DEFAULT is defined to be 23.

My question is how to modify so I can scan for beacon whose data length is about 30? Or it's just

not supported in S130 to scan for beacons this way?

  • Hi Max, 
    I assume you are using S130. 

    Unfortunately larger ATT_MTU and longer Datalengh is not supported by S130. 

    So if you want to send via notification more than 23 bytes, you need to segment the data send it in multiple packets. 

    On S132 (for nRF52) it's supported up to 247 byte ATT_MTU that you can use to send notification. 

  • Hi Bui,

    Yes, I am using S130. The thing is that I am not trying to send beacon signals. Instead, I want to scan for it. is there a workaround in BLE_GAP_EVT_ADV_REPROT?

    Also, I am targeting nrf51822 module and S132 is not applicable.

  • Hi Max, 

    Yes I understood that you want to scan and then send the beacon signal to the peer device. But the way you are sending the beacon data to the peer device is via notification (ble_nus_string_send ) 
    So you have 3 options. 
    1. Use notification but segment the beacon data into 2 packets. So for example if you need to send 30 bytes. You can send first 20 bytes, then send the last 10 bytes on a second call ble_nus_string_send  . 

    2. You can send a notification telling the central to do a read. With read request there is no restriction on 20 bytes payload size (read response is automatically segmented to multiple packets on the ATT layer)

    3. You can implement a server on the central, and do a write from the peripheral to the central, with this you can write more than 20 bytes (write response is also automatically segmented). 

  • Hi Bui,

    My problem is not sending beacon signals. Just scanning. What I want to achieve is to scan for a specific beacon signal and wake up from BLE idle to advertising.

  • Could you explain why you call ble_nus_string_send() ? I have no idea why it's related to BLE_GAP_EVT_ADV_REPORT and to scanning. 
    Please provide your full code. 

Related