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

UART + non-connectable advertisement

I am trying to broadcast a non-connectable advertisement (such as a beacon) while I am connected to a device that I am transferring data via TX. I am working with a nRF52840 on Segger Embedded Studio v3.4 with the nRF5_SDK_15 as the base for my code manipulation. More specifically I'm going off the ble_app_uart example for pca10040 s132. I don't care about receiving data through RX from the device I am connected to. By the way, I have tried using the Time Slot API where I try to initiate the advertising of the beacon when the device connects through UART. It is my understanding from projects such as the nRF51-multi-role-protocol-conn-observer-advertiser example on github but this is for nrf51 devices. I have tried to mimick this project as well as articles showing how the time slot api can be used to implement non-connectable advertising during a connection as a peripheral. I have also tried doing this without the Time Slot API but to no avail. My thinking is that the buffer transferring data out of the device can only handle 31 bytes of data per interval, but both the advertising and uart protocols take up 31 bytes so its not possible to do at the same time. There must be a way to switch between the two protocols (uart and advertisement) when the radio interrupt occurs. Please help.

  • Hello,

    When you say: "while I am connected to a device that I am transferring data via TX". Do you mean a physical UART, or UART over BLE (Nordic Uart Service/NUS)?

     

    Either way, I don't think you have to use the Timeslot API. You can connect to a device, and start advertising again. You can also start advertising non-connectable while in a connection. All you need to do is to wait for the connected event, set up a non-connectable advertising set (like it is done in the beacon examples), and start advertising again. However, you can't advertise with two advertising sets at the same time. If you want to advertise with the non-connectable advertising at the same time as regular/connectable advertising (for the NUS service), you must manually swap between these, but that is absolutely doable.

     

    So do you want to advertise with the non-connectable advertisements while in a BLE connection, or while connected to the physical UART?

     

    Best regards,

    Edvin

  • Thanks for getting back Edvin,

    I am referring to UART over BLE such as with the ble_app_uart example. What I tried that is pretty much what you are saying. I took the advertising_init and advertising_start methods from the ble_app_uart example and changed their names (advertising_init_beacon and advertising_start_beacon), brought them into the the ble_app_uart example, and when the gap_evt signals that a connection has been initiated, I call the advertising_init_beacon and advertising_start_beacon methods for the beacon in that order. It's failing after I'm calling this method:

    sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);

    which is at the end of the advertising_init_beacon method. This is the entire method:

    static void advertising_init_beacon(void)
    {
    uint32_t err_code; ble_advdata_t advdata; uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; ble_advdata_manuf_data_t manuf_specific_data; manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER; manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info; manuf_specific_data.data.size = APP_BEACON_INFO_LENGTH; // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_NO_NAME; advdata.flags = flags; advdata.p_manuf_specific_data = &manuf_specific_data; // Initialize advertising parameters (used when starting advertising). memset(&m_adv_params, 0, sizeof(m_adv_params)); m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED; m_adv_params.p_peer_addr = NULL; // Undirected advertisement. m_adv_params.filter_policy = BLE_GAP_ADV_FP_ANY; m_adv_params.interval = NON_CONNECTABLE_ADV_INTERVAL; m_adv_params.duration = 0; // Never time out. err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len); APP_ERROR_CHECK(err_code);
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
        APP_ERROR_CHECK(err_code);
    }
  • what does it return? err_code = sd_ble_gap_adv_set_configure(); what is err_code after this?

     

    Note: If you define "DEBUG" in your preprocessor defines, it should print in the log (RTT) what it is. But you can also debug and set a breakpoint on the line with APP_ERROR_CHECK(err_code); after sd_ble_gap_adv_set_configure() to see what value err_code has after this. Note that you may have to turn off optimization to be able to see the variable.

     

    Best regards,

    Edvin

  • I am getting an error_code of 4 which is NRF_ERROR_NO_MEM. This doesn't surprise me because it takes 31 bytes to transfer a beacon signal but the device can only send 31 bytes of information every interval, hence why I am trying to implement this solution with the timeslot API. This is my understanding of the result of the error_code, and I may be wrong. 

  • Hello,

    Is the advertising data that you are trying to initialize larger than 31 bytes? In that case, it will not work. Even if you manage to do this with the Timeslot API, no other device will recognize it as an advertisement packet.

     

    Another possible reason for why sd_ble_gap_adv_set_configure() returns NRF_ERROR_NO_MEM is that you are trying to pass a new advertising handle into the softdevice. If the softdevice is only set up to handle one advertising set, it will not have room for another. You can try to change the existing advertising set to your new, and hence, it will not take up any more memory.

     

    Have you tested your advertising set on a beacon example to see if if fits inside an advertising packet?

     

    If you need more data, you can see whether it is enough if you use scan response data. It is described in this guide.

     

    Best regards,

    Edvin

     
Related