How to read advertisement data per device using a central device

Hi all

I am using the bluetooth central sample from zephyr. I can read the addresses of the devices but I would like to read each specific device's advertisement data. So, when the central device finds the ID AA:BB:CC:DD:EE:FF, i would like to read the advertisement data from this device. Does anyone have any advice for how I can go about doing this? Thanks

  • Here is some clarifying screenshots:

    I have since switched to the "observer" sample from zephyr.

    I am trying to read out the advertisement data the scanner receives by doing this

    And when I print out the output I get this

    My output doesn't make any sense. It is not matching what I am seeing when I find this c209 tag via the nRF Connect Scanner App on my iPhone.

    Does anyone have any advice on how I can approach this? I can find the device but none of the data readouts are correct (from the scanner side). Thanks.

  • Advertising data will be processed in your data_cb() function. Any printout should be above your [DEVICE] line.

    Also recommend replacing printk() with the LOG_ stuff at the earliest opportunity.

  • That makes sense, but I do not see where the program would be parsing for data like the service data for example. I thought data_cb would be parsing the entire advertisement message. It doesnt seem to be doing this. I could be misunderstanding though

  • Personally, I like the NCS\zephyr\samples\bluetooth\central.

    Out of the box, this sample just connects to anything it sees, but f you modify the device_found() callback, it holds the advertising data information.

    The struct net_buf_simple *ad parameter holds the advertising, and you can print it by using something like:

    device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
    			 struct net_buf_simple *ad)
    {
        LOG_INF("received advertisement, length %d", ad->len);
        for (int i=0; i<ad->len; i++){
            LOG_PRINTK("ad->data[i]:");
        }
        // Not sure if the below line is needed. Uncomment if it only receives one advertisement.
        // start_scan();
    }

    This also requires CONFIG_LOG_PRINTK=y in your prj.conf.

    The reason I use LOG_PRINTK() is that this doesn't add a timestamp and newline for every instance of LOG_PRINTK(). You can also use printk() for everything if you prefer, but I agree with   that you should switch to the log module sooner rather than later.

    Best regards,

    Edvin

  • Hi Edvin,

    Thanks for the reply. This makes sense to me. However, when I try this my advertisement data is not quite matching up.

    My code in device_found:

    My output

    Result from my c209 tag via the NRF Connect App

    I assume i should be getting the values from the "data" field

    Seems like the data fields are even different lengths too. Why would the NRF Connect App be seeing something different?

Related