正在加载···
AI摘要
HunYuan-Lite

本教程使用的SDK版本为 nRF5_SDK_17.1.0

  1. 将蓝牙广播名的定义从 flash 改到 ram

    1
    2
    3
    #define DEVICE_NAME                     "Nordic_UART"                               /**< Name of device. Will be included in the advertising data. */

    static uint8_t device_name[BLE_GAP_DEVNAME_DEFAULT_LEN] = DEVICE_NAME;
  2. 添加以下函数修改蓝牙广播名:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    int ble_device_name_set(uint8_t *val, uint8_t len)
    {
    if (len + 1 > sizeof(device_name))
    return -1;

    memcpy(device_name, val, len);
    device_name[len] = 0;

    uint32_t err_code;
    ble_advdata_t adv_data;
    ble_gap_conn_sec_mode_t sec_mode;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    err_code = sd_ble_gap_device_name_set(&sec_mode, device_name, strlen((const char*)device_name));
    APP_ERROR_CHECK(err_code);

    memset(&adv_data, 0, sizeof(adv_data));

    adv_data.name_type = BLE_ADVDATA_FULL_NAME;
    adv_data.include_appearance = false;
    adv_data.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

    err_code = ble_advertising_advdata_update(&m_advertising, &adv_data, NULL);
    APP_ERROR_CHECK(err_code);

    return 0;
    }