Problem in advertising ibeacon in NRF52840

Hi

i want to create a bluetooth beacon which should get input in gatt(UUID,name,major,minor..then it should be advertise with the new UUID.

Iam configuring it with ibeacon.i can get the payload through gatt.but when readvertising there is an issue.

iam facing error in this line

BT_DATA(BT_DATA_MANUFACTURER_DATA, manufacturer_data, MANUFACTURER_DATA_LENGTH),

my error is

C:/ncs/v2.8.0/zephyr/include/zephyr/bluetooth/bluetooth.h:474:25: error: initializer element is not constant
  474 |                 .data = (const uint8_t *)(_data), \
      |                         ^
C:/Users/Sara/Documents/PlatformIO/Projects/workspace/ibeacon/src/main.c:219:5: note: in expansion of macro 'BT_DATA'
  219 |     BT_DATA(BT_DATA_MANUFACTURER_DATA, manufacturer_data, MANUFACTURER_DATA_LENGTH),  // Use sizeof to get length
      |     ^~~~~~~
C:/ncs/v2.8.0/zephyr/include/zephyr/bluetooth/bluetooth.h:474:25: note: (near initialization for 'ad[1].data')
  474 |                 .data = (const uint8_t *)(_data), \
      |                         ^
C:/Users/Sara/Documents/PlatformIO/Projects/workspace/ibeacon/src/main.c:219:5: note: in expansion of macro 'BT_DATA'
  219 |     BT_DATA(BT_DATA_MANUFACTURER_DATA, manufacturer_data, MANUFACTURER_DATA_LENGTH),  // Use sizeof to get length
      |     ^~~~~~~

static ssize_t write_received_data(struct bt_conn *conn, const struct bt_gatt_attr *attr,
                                   const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
{
    if (len > MAX_STRING_SIZE - 1) {
        return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
    }

    // Copy the received data
    memcpy(received_data, buf, len);
    received_data[len] = '\0';  // Null-terminate the received data
    printk("Received data: %s\n", received_data);

    // Parse the received JSON into the parameters structure
    int ret = json_obj_parse(received_data, sizeof(received_data),
                             parameters_descr, ARRAY_SIZE(parameters_descr),
                             &params);
    if (ret < 0) {
        printk("JSON Parse Error: %d\n", ret);
        return len;
    }

    // Print parsed values for verification
    printk("Device Name: %s, UUID: %s, TX Power: %d, Major: %d, Minor: %d\n",
           params.name, params.uuid, params.TX, params.Major, params.Minor);

    // Copy the device name to the buffer for advertising
    strncpy(name_buffer, params.name, sizeof(name_buffer) - 1);
    name_buffer[sizeof(name_buffer) - 1] = '\0';  // Ensure null-termination

    // Set the TX power level
    set_tx_power(BT_HCI_VS_LL_HANDLE_TYPE_ADV, 0, params.TX);

    // Convert UUID, Major, and Minor to their respective hex representations
    uint8_t uuid_hex[16];
    uint8_t major_hex[2];
    uint8_t minor_hex[2];

    uuid_string_to_hex(params.uuid, uuid_hex, sizeof(uuid_hex));

    major_hex[0] = (params.Major >> 8) & 0xFF;
    major_hex[1] = params.Major & 0xFF;
    minor_hex[0] = (params.Minor >> 8) & 0xFF;
    minor_hex[1] = params.Minor & 0xFF;


 uint8_t manufacturer_data[] = {
    0x4c, 0x00,               // Apple Manufacturer ID
    0x02, 0x15,               // iBeacon type
    uuid_hex[0], uuid_hex[1], uuid_hex[2], uuid_hex[3], uuid_hex[4], uuid_hex[5],
    uuid_hex[6], uuid_hex[7], uuid_hex[8], uuid_hex[9], uuid_hex[10], uuid_hex[11],
    uuid_hex[12], uuid_hex[13], uuid_hex[14], uuid_hex[15], // UUID
    major_hex[0], major_hex[1],  // Major
    minor_hex[0], minor_hex[1],  // Minor
    IBEACON_RSSI              // RSSI
};


static struct bt_data ad[] = {
    BT_DATA(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR, 1),
    BT_DATA(BT_DATA_MANUFACTURER_DATA, manufacturer_data, MANUFACTURER_DATA_LENGTH),  // Use sizeof to get length
};
Related