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

HOW CAN WE MAKE A MASTER TO CONNECT WITH A SLAVE COMPARING THE DEVICE NAME INSTEAD OF SLAVE ADDRESS IN S130

I am working on a ble project ,'ble_central_and_peripheral",s130.In this project the device acts as master and slave. It connects to the slave only if the address is predefined in the program.

So, can we edit the code and make the master connect to any slave ,whose address is not predefined??is it possible to compare the device name instead of address as done in s120 "ble_central"??

please help

  • static uint32_t adv_report_parse(uint8_t type, data_t * p_advdata, data_t * p_typedata)
    {
        uint32_t  index = 0;
        uint8_t * p_data;
    
        p_data = p_advdata->p_data;
    
        while (index < p_advdata->data_len)
        {
            uint8_t field_length = p_data[index];
            uint8_t field_type   = p_data[index+1];
    
            if (field_type == type)
            {
                p_typedata->p_data   = &p_data[index+2];
                p_typedata->data_len = field_length-1;
                return NRF_SUCCESS;
            }
            index += field_length + 1;
        }
        return NRF_ERROR_NOT_FOUND;
    }
    

    inside the event handler

       case BLE_GAP_EVT_ADV_REPORT:
        {
            data_t adv_data;
            data_t type_data;
    
            // Initialize advertisement report for parsing.
            adv_data.p_data = p_ble_evt->evt.gap_evt.params.adv_report.data;
            adv_data.data_len = p_ble_evt->evt.gap_evt.params.adv_report.dlen;
    
            err_code = adv_report_parse(BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME,
                                      &adv_data,
                                      &type_data);
            if (err_code != NRF_SUCCESS)
            {
                // Compare short local name in case complete name does not match.
                err_code = adv_report_parse(BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME,
                                          &adv_data,
                                          &type_data);
            }
    
            // Verify if short or complete name matches target.
            if ((err_code == NRF_SUCCESS) &&
               (0 == memcmp(TARGET_DEVICE_NAME,type_data.p_data,type_data.data_len)))
            {
                err_code = sd_ble_gap_scan_stop();
    							APPL_LOG("[APPL]: ADV report from target received, stopping scanner.\r\n");
                if (err_code != NRF_SUCCESS)
                {
                    APPL_LOG("[APPL]: Scan stop failed, reason %d\r\n", err_code);
                }
    
                err_code = sd_ble_gap_connect(&p_ble_evt->evt.gap_evt.params.adv_report.\
                                              peer_addr,
                                              &m_scan_param,
                                              &m_connection_param);
    
                if (err_code != NRF_SUCCESS)
                {
                    APPL_LOG("[APPL]: Connection Request Failed, reason %d\r\n", err_code);
                }
            }
            break;
        }
    
  • This is the code in s120 softdevice. How can we make the same logic work in s130"ble_central_and_peripheral".Pasting the code doesn't work,i have tried that.

    i think the only way is to access the variable to which the scanned address or device name is received ie,p_ble_evt->evt.gap_evt.params.adv_report.data,in s120.but not able to access this variable in s130.Also if we replace p_ble_evt with temp after declaring temp as" ble_evt_t temp",in S120 we don't get the device name .what may the reason?

  • This is the code from my internal S130 project, and it works just fine. What did you mean that it did not work? what error did you get.

  • is this the code for the device that can act as both master and slave??if so please mention the path to the project in the sdk.The thing is that i want to make the device act both as master and slave with this logic

Related