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

Modify ble_app_uart_c example to scan for custom UUID not working

I am trying to do the same thing that others have tried in the past, and that is to modify the ble_app_uart_c example to connect to our custom peripheral device.

I have gone through several blog posts regarding this issue, including: https://devzone.nordicsemi.com/f/nordic-q-a/20641/how-to-use-ble_app_uart_c-for-custom-uuid-service/80467#80467 and https://devzone.nordicsemi.com/f/nordic-q-a/12555/ble-central-custom-uuid and https://devzone.nordicsemi.com/f/nordic-q-a/44912/scan-filters-for-custom-uuid-is-not-matching and many others.  Unfortunately, I haven't been able to get a connection.  The code is failing the adv_uuid_compare function nrf_ble_scan_c. 

The changes that I made were to ble_nus_c are:

#define NUS_BASE_UUID {{0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00}} /**< Used vendor specific UUID. */  

(Note: The custom UUID is: 0000fff0-0000-1000-8000-00805f9b34fb). 

Made changes to the service/characteristics as well.  Note that 

#define BLE_UUID_NUS_SERVICE 0xFFF0                          /**< The UUID of the Nordic UART Service. */

(Note: We don't have a comparable service for the NUS 0001 so changed it to the FFF0 to match the main UUID).

#define BLE_UUID_NUS_RX_CHARACTERISTIC 0xFFF1   /**< The UUID of the RX Characteristic. */

#define BLE_UUID_NUS_TX_CHARACTERISTIC 0xFFF2   /**< The UUID of the TX Characteristic. */

I verified that the all_filters_mode is false so it should only match one UUID.

I added printf statements to nrf_ble_scan_c file to display the comparison values:

#if (NRF_BLE_SCAN_UUID_CNT > 0)
/**@brief Function for comparing the provided UUID with the UUID in the advertisement packets.
*
* @param[in] p_adv_report Advertising data to parse.
* @param[in] p_scan_ctx Pointer to the Scanning Module instance.
*
* @return True if the UUIDs match. False otherwise.
*/
static bool adv_uuid_compare(ble_gap_evt_adv_report_t const * const p_adv_report,
nrf_ble_scan_t const * const p_scan_ctx)
{

// Print out the compare values:
printf("p_adv_report value is: %x \r\n",p_adv_report);
printf("p_scan_ctx is: %x \r\n", p_scan_ctx);
printf("\r\n\r\n");

nrf_ble_scan_uuid_filter_t const * p_uuid_filter = &p_scan_ctx->scan_filters.uuid_filter;

bool const all_filters_mode = p_scan_ctx->scan_filters.all_filters_mode;
uint8_t const counter =
p_scan_ctx->scan_filters.uuid_filter.uuid_cnt;
uint8_t index;
uint16_t data_len;
uint8_t uuid_match_cnt = 0;

data_len = p_adv_report->data.len;

for (index = 0; index < counter; index++)
{

//printf("Entering UUID Compare function in nrf_ble_scan.c.\r\n");  (Note: We do get here.)

if (ble_advdata_uuid_find(p_adv_report->data.p_data,
data_len,
&p_uuid_filter->uuid[index]))

{

printf("If we got here then the UUID should have matched.\r\n");   (Note: We do not get here.)

uuid_match_cnt++;

// In the normal filter mode, only one UUID is needed to match.
if (!all_filters_mode)
{
break;
}
}
else if (all_filters_mode)
{
break;
}
else
{
// Do nothing.
}
}

// In the multifilter mode, all UUIDs must be found in the advertisement packets.
if ((all_filters_mode && (uuid_match_cnt == counter)) ||
((!all_filters_mode) && (uuid_match_cnt > 0)))
{
return true;
}

return false;
}

The compare values from successive scans are:  

p_adv_report value is: 2000fd1c

p_scan_ctx is: 20003684

p_adv_report value is: 2000fcec

p_scan_ctx is: 20003684

Clearly since the values are not the same, they won't match but I can't figure out where these values are coming from.  Also, why aren't the full 218 bits being displayed and compared?

Please advise.

Related