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

Parents
  • 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;
        }
    
  • OK but with this code the device can act as master only.Comparing the device name, how can i make it to act as both master and slave??Actually the code is available in S130 ble_central_and_peripheral,but the problem is only with those whose address is given the master gets connected.But i want to make it connect with any slave who is advertising.It is possible if we can have access to the variable to which the address is received.

Reply
  • OK but with this code the device can act as master only.Comparing the device name, how can i make it to act as both master and slave??Actually the code is available in S130 ble_central_and_peripheral,but the problem is only with those whose address is given the master gets connected.But i want to make it connect with any slave who is advertising.It is possible if we can have access to the variable to which the address is received.

Children
No Data
Related