Howdy!
I am working with the nRF52840 and currently getting a weird error. Whenever I set the data for the BT_DATA function as anything greater than 110, the system stops advertising. I have tried various different max array sizes from 114 up to 1600. No matter what I choose of these, it still stops transmitting all together. This is even after setting the max value accepted in the prj.conf file as 251. I am providing a snippet of my code below. Any help would be much appreciated.
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/uuid.h>
#define COMPANY_ID_LEN 2
#define SENSOR_DATA_LEN 10
#define SPI_DATA_LEN 98
struct adv_mfg_data {
uint16_t company_code[COMPANY_ID_LEN]; /* Company Identifier Code. */
uint8_t custom_data[SENSOR_DATA_LEN]; /* Custom 10-element array */
};
uint8_t The_Vocal_data[SPI_DATA_LEN] = {0}; /* Vocalization 98-element array */
struct adv_mfg_data adv_data_pre = {
.company_code = COMPANY_ID_CODE,
.custom_data = {0},
};
struct bt_le_ext_adv *adv;
static struct bt_le_adv_param adv_param = {
.options = BT_LE_ADV_OPT_USE_IDENTITY | BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_EXT_ADV,
.interval_min = BT_GAP_ADV_FAST_INT_MIN_1, // Every 1 to 3 seconds
.interval_max = BT_GAP_ADV_FAST_INT_MAX_1,
.peer = NULL
};
struct bt_data adv_data[] = {
//BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR),
BT_DATA(BT_DATA_MANUFACTURER_DATA, "just zeroes", 6),
};
uint8_t manufacturer_data[112];
static void set_advertising_data(struct adv_mfg_data *adv_data_set) {
uint8_t n_manufacturer_data = sizeof(adv_data_set->company_code) + sizeof(adv_data_set->custom_data) + sizeof(The_Vocal_data);
memcpy(manufacturer_data, adv_data_set->company_code, sizeof(adv_data_set->company_code));
memcpy(manufacturer_data + sizeof(adv_data_set->company_code), adv_data_set->custom_data, sizeof(adv_data_set->custom_data));
memcpy(manufacturer_data + sizeof(adv_data_set->company_code) + sizeof(adv_data_set->custom_data), The_Vocal_data, sizeof(The_Vocal_data));
struct bt_data adv_data_new[] = {
BT_DATA(BT_DATA_MANUFACTURER_DATA, manufacturer_data, n_manufacturer_data),
};
memcpy(&adv_data,&adv_data_new, sizeof(struct bt_data));
printk("Created adv: %p\n", adv);
printk("Size of bt_data struct: %d\n",sizeof(struct bt_data));
printk("Number of elements in adv_data set: %d\n", sizeof(adv_data) / sizeof(adv_data[0]));
int err = bt_le_ext_adv_set_data(adv, adv_data, ARRAY_SIZE(adv_data), NULL, 0);
if (err) {
printk("Failed to set advertising data (err %d)\n", err);
} else {
printk("Advertising data set successfully\n");
}
}