Filtering advertisements based on target apperance

I am currently struggling with filtering based on appearance using the Scanning module.

I have a beacon that advertises some dummy data, appearance and service UUID. With the scanning module I was able to filter this advertisement from other advertisements by testing it in an environment with a lot of BLE devices. However, whenever I try to filter both service UUID and appearance or just appearance I do not receive any advertisements that matches with these filters.

The code below works fine.

err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, &beacon_service_uuid);
	if (err) {
		printk("Service UUID scan filter cannot be set (err %d)\n", err);

		return err;
	}
	
err = bt_scan_filter_enable(BT_SCAN_UUID_FILTER, true);
	if (err) {
		printk("UUID filters cannot be enabled (err %d)\n", err);
		return err;
	}


The following however does not work
err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_APPEARANCE, &beacon_appearance_uuid);
	if (err) {
	    printk("Appearance UUID scan filter cannot be set (err %d)\n", err);
	    return err;
	}

err = bt_scan_filter_enable(BT_SCAN_APPEARANCE_FILTER, true);
	if (err != 0) {
	    printk("Scan filters cannot be enabled (err %d)\n", err);
	    return err;
	}


I can try to do the filtering whenever I parse the data, but I would like to see if I can already filter advertisements with the filters.

Parents
  • We found the issue. we found that the issue is in ncs\v2.5.0\nrf\subsys\bluetooth\scan.c

    static bool find_appearance(const uint8_t *data,
    			    uint8_t data_len,
    			    const uint16_t *appearance)
    {
    	if (data_len != sizeof(uint16_t)) {
    		return false;
    	}
    
    	uint16_t decoded_appearance = sys_get_be16(data);
    
    	if (decoded_appearance == *appearance) {
    		return true;
    	}
    
    	/* Could not find the appearance among the encoded data. */
    	return false;
    }

    You need to change the sys_get_be16 -> sys_get_le16

    This is a bug, so I will create an internal bug tracker.

Reply
  • We found the issue. we found that the issue is in ncs\v2.5.0\nrf\subsys\bluetooth\scan.c

    static bool find_appearance(const uint8_t *data,
    			    uint8_t data_len,
    			    const uint16_t *appearance)
    {
    	if (data_len != sizeof(uint16_t)) {
    		return false;
    	}
    
    	uint16_t decoded_appearance = sys_get_be16(data);
    
    	if (decoded_appearance == *appearance) {
    		return true;
    	}
    
    	/* Could not find the appearance among the encoded data. */
    	return false;
    }

    You need to change the sys_get_be16 -> sys_get_le16

    This is a bug, so I will create an internal bug tracker.

Children
Related