This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Not receiving the complete advertisement

I have a project where I use the nrf9160dk as a gateway between a BLE sensor and LTE.

The hci_lpuart sample is flashed tonrf9160dk_nrf52840 and the nrf9160dk_nrf9160_ns has code for scanning for advertisements and receiving the advertisement data. 

The advertisement data is 27 bytes and I have confirmed that these are all recieved in nrfconnect app and also in a custom gateway made for windows.

When I read the advertisement data in my application the first 21 bytes corresponds to the advertisement sent, while the rest seems random.

Part of my function where I read the advertisement. 

void scan_filter_match(struct bt_scan_device_info *device_info,
					   struct bt_scan_filter_match *filter_match,
					   bool connectable)
{
	struct net_buf_simple advbuf = *device_info->adv_data;
	char advertisement[27]; 
	strcpy(advertisement, advbuf.data);
}

I also have a ticket posted earlier https://devzone.nordicsemi.com/f/nordic-q-a/79926/bluetooth-le-scan-warnings with some warnings I am getting, not sure if this is related.

The length is 27:

 

Data received:

 

Data sent from BLE sensor: 02010617FFDE08FFFFFFFFFFFFFFFFFFFFDA6F01006400C701FC00

I have tried increasing some buffers in the prj.conf settings for hci_lpuart, but I'm not really sure where the issue is, and I haven't been able to fix it. 

BUF and STACK configs:

CONFIG_BT_BUF_ACL_RX_SIZE=300
CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255
CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1024

Can anyone help me figure out what the issue might be?

Parents
  • Hi,

    strcpy() copies a null-terminated string (c string) up until the terminating NULL character (0x00). Since you have a null byte (0x00) on byte 21 of your BLE data, it is expected that the portion copied by strcpy() is "02010617FFDE08FFFFFFFFFFFFFFFFFFFFDA6F0100".

    For getting the full package, you can use memcpy:

    memcpy(advertisement, advbuf.data, advbuf.len);

    Regards,
    Terje

Reply
  • Hi,

    strcpy() copies a null-terminated string (c string) up until the terminating NULL character (0x00). Since you have a null byte (0x00) on byte 21 of your BLE data, it is expected that the portion copied by strcpy() is "02010617FFDE08FFFFFFFFFFFFFFFFFFFFDA6F0100".

    For getting the full package, you can use memcpy:

    memcpy(advertisement, advbuf.data, advbuf.len);

    Regards,
    Terje

Children
No Data
Related