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

Scan UUID increase after each scanning periods

Hi everyone,

I am using board PCA10040 v1.1.0, softdevice 13.0.0, Eclipse Oxygen. I am trying to scan my phone and communicate with it but the scaned UUID is increasing as you can see in the image below.

image description

Here is the ble_evt_handler function:

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            PrintInfo("BLE GAP event: Connected");
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            PrintInfo("BLE GAP event: Disconnected");
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            break;

        case BLE_GAP_EVT_ADV_REPORT:
        {
            // The advertisement report
            ble_gap_evt_adv_report_t const * p_adv_report = &p_gap_evt->params.adv_report;
            if(is_uuid_present(m_scan_uuids, p_adv_report))
            {

            }
        }
            break;

        default:
            // No implementation needed.
            break;
    }
}

The is_uuid_presentfunction is as same as the code in the "ble_app_uart_c" example, I just add below code to that:

else if (field_type == BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA)
{
    err_code = sd_ble_uuid_decode(UUID128_SIZE, &p_data[index + 2], &extracted_uuid);
    PrintDebug("err_code: %X", err_code);
    PrintInfo("Scan UUID: %X", extracted_uuid.uuid);
    if (err_code == NRF_SUCCESS)
    {
        if (   (extracted_uuid.uuid == p_target_uuid->uuid)
            && (extracted_uuid.type == p_target_uuid->type))
        {
            return true;
        }
    }
}

Could you help me please? Thanks

  • So, how can I know that advertising device is my phone or another one? And in this case, can I use sd_ble_gap_connect function to connect with mine?

  • Yes, you should be able to connect to the phone.

    Q:how can I know that advertising device is my phone or another one?

    A: You can identify the phone by its 6-byte MAC address. The phone uses a Private Resolvable address. So you have to pair/bond with the phone. See this post for information about BLE addresses.

  • Hi Sigurd, sorry but I'm not understand. Could you explain more detail please? Where can I get the phone 6-byte MAC address? Is it in the field ble_gap_evt_adv_report_t->peer_addr->addr or ble_gap_evt_adv_report_t->direct_addr->addr? Thanks for helping me!

  • It's in the ble_gap_evt_adv_report_t->peer_addr->addr.

    If we take a look at the original ble_app_uart_c code, we are first looking for the Nordic UART Service UUID, and if the UUID is found we connect. If the connect request is successful, we print the Bluetooth address of the peer device.

    Code snippet:

    case BLE_GAP_EVT_ADV_REPORT:
        {
            const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report;
    
            if (is_uuid_present(&m_nus_uuid, p_adv_report))
            {
    
                err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
                                              &m_scan_params,
                                              &m_connection_param,
                                              CONN_CFG_TAG);
    
                if (err_code == NRF_SUCCESS)
                {
                    // scan is automatically stopped by the connect
                    err_code = bsp_indication_set(BSP_INDICATE_IDLE);
                    APP_ERROR_CHECK(err_code);
                    NRF_LOG_INFO("Connecting to target %02x%02x%02x%02x%02x%02x\r\n",
                             p_adv_report->peer_addr.addr[0],
                             p_adv_report->peer_addr.addr[1],
                             p_adv_report->peer_addr.addr[2],
                             p_adv_report->peer_addr.addr[3],
                             p_adv_report->peer_addr.addr[4],
                             p_adv_report->peer_addr.addr[5]
                             );
                }
            }
    
  • Hi Sigurd,

    I get MAC address from my phone, but it is weird. The first bit of each byte is shifted to the last position.

    Phone MAC: 11100100-01011000-10111000-00101111-01010100-00000100

    Scanned MAC: 00001000-10101000-01011110-01110001-10110000-11100100

Related