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

Sending data from single peripheral to multiple central.

Hi,

My aim is on button press in peripheral side ,it should do advertise and sent data from single peripheral to multiple central(total two central).

I am using nrf52810 ,soft device 132, code used ble_app_uart(peripheral),be_app_uart_c(central).

I am able to make connection between one peripheral and two central but not able to send the data.When i press the button advertisement is starting and connection have been done but not able to receive data on central side.

The changes that i have done for sending data and for making central connection with peripheral are below :

main.c

static void led_status_send_to_button(uint8_t key)
{
    ret_code_t                        err_code;
   // uint8_t key = '1';
    ble_conn_state_conn_handle_list_t conn_handles = ble_conn_state_periph_handles();
   // printf("in led\r\n");
    //printf("led_status_send_to_button | conn_handles.len=%d\r\n",conn_handles.len);
    for (uint8_t i = 0; i < conn_handles.len; i++)
    {
       printf("Iteration-%d\r\n",i);
       //nrf_delay_ms(2000);
      // printf("led_status_send_to_button | calling...ble_nus_data_send(key=%c)\r\n",key);
     
       err_code = ble_nus_data_send(&m_nus,&key,&length,conn_handles.conn_handles[i]);
       printf("led_status_send_to_button | called...ble_nus_data_send(key) %c\r\n",key);

       // if(err_code != BLE_ERROR_INVALID_CONN_HANDLE)
        if ((err_code != NRF_SUCCESS) &&
            (err_code != BLE_ERROR_INVALID_CONN_HANDLE) &&
            (err_code != NRF_ERROR_INVALID_STATE) &&
            (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING))
        {
            printf("Error\r\n");
            APP_ERROR_CHECK(err_code);
       //     NRF_LOG_DEBUG("Sent button change 0x%x on connection handle 0x%x.", ke, conn_handles.conn_handles[i]);
        }
       
    }
    return NRF_SUCCESS;
}



/**@brief Function for handling the Connected event.
 *
 * @param[in] p_gap_evt GAP event received from the BLE stack.
 */
static void on_connected(const ble_gap_evt_t * const p_gap_evt)
{
    ret_code_t  err_code;
    periph_link_cnt = ble_conn_state_peripheral_conn_count(); // Number of peripheral links.

    NRF_LOG_INFO("Connection with link 0x%x established.", p_gap_evt->conn_handle);

    // Assign connection handle to available instance of QWR module.
    for (uint32_t i = 0; i < NRF_SDH_BLE_PERIPHERAL_LINK_COUNT; i++)
    {
        if (m_qwrs[i].conn_handle == BLE_CONN_HANDLE_INVALID)
        {
            err_code = nrf_ble_qwr_conn_handle_assign(&m_qwrs[i], p_gap_evt->conn_handle);
            APP_ERROR_CHECK(err_code);
            break;
        }
    }

    // Update LEDs
    bsp_board_led_on(CONNECTED_LED);
    if (periph_link_cnt == NRF_SDH_BLE_PERIPHERAL_LINK_COUNT)
    {
        bsp_board_led_off(ADVERTISING_LED);
    }
    else
    {
        // Continue advertising. More connections can be established because the maximum link count has not been reached.
      advertising_start();
     nrf_delay_ms(1000);         

      led_status_send_to_button(key);
    }
}

void bsp_event_handler(bsp_event_t event)
{
    uint32_t err_code;
 
    if (periph_link_cnt == 0 && advt_val == false)
    {
    advertising_start();
    advt_val = true;
    }

    switch (event)
    {
        case BSP_EVENT_SLEEP:
            sleep_mode_enter();
            break;

        case BSP_EVENT_DISCONNECT:
            err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }
            break;

        case BSP_EVENT_WHITELIST_OFF:
            if (m_conn_handle == BLE_CONN_HANDLE_INVALID)
            {
                err_code = ble_advertising_restart_without_whitelist(&m_advertising);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
            }
            break;

          case BSP_EVENT_KEY_0 :
          {
           uint8_t key = '1';
     
          led_status_send_to_button(key);
          }
          break;
               
        case BSP_EVENT_KEY_1 :
        {
        key = '2';
        if (advt_val == false)
          {
     //     printf("do nothing\r\n");
          }
          else
          {
           led_status_send_to_button(key);
       //    printf("send key = %c\r\n",key);
          }
          }
          break;

Is there is any problem in my code or i am missing something for sending the data ? Any suggestion is appreciable.

Related