BLE peripheral

目前在使用 BLE peripheral 的部分,在下完ATBp=1後可以看到打印出來的資訊,請問為什麼我在 pc 端上使用 bluez 的 tool 時,scan 不到此 mac 地址?


Screenshot from 2022-06-22 11-12-51

我用 ubuntu 18 的 bluez

sudo bluetoothctl
scan on

scan 到了

另想請問,我想使用 BLE peripheral 的一些範例
在下了 ATBp = 1後,在PC端上(central) 已可connect到 rtl8712dm
請問如果要讓 cenrral 與 peripheral間傳遞資料的話
我該從 SDK 的哪些 example 開始參考?
謝謝

BLE 的 example 文件在 \component\common\bluetooth\realtek\sdk\example
ATBp 启动的是 peripheral 的 example,用的是 BAS service 和 simple BLE service。
Service 的代码文件在 :

  • \component\common\bluetooth\realtek\sdk\src\ble\profile\server
  • \component\common\bluetooth\realtek\sdk\inc\bluetooth\profile\server

想要 central 和 peripheral 传数据,需要在 central 上读取 GATT attributes,找到 service 和 characteristic 相对应的 UUID,然后更改某一个 characteristic 数据值。

好的,謝謝~
我想將 Ameba 在 peripheral mode被 scan 到的名字(目前是 BLE_PERIPHERAL)
但在整個SDK裡搜尋後找不太到
請問我該從哪裡改?

\component\common\bluetooth\realtek\sdk\example\ble_peripheral\ble_app_main.c
BLE 有两个地方可以改名字

  1. Scan 到的名字,也就是 BLE ADV 蓝牙广告数据里的名字,需要改蓝牙广告数据
static const uint8_t adv_data[] =
{
    /* Flags */
    0x02,             /* length */
    GAP_ADTYPE_FLAGS, /* type="Flags" */
    GAP_ADTYPE_FLAGS_LIMITED | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
    /* Service */
    0x03,             /* length */
    GAP_ADTYPE_16BIT_COMPLETE,
    LO_WORD(GATT_UUID_SIMPLE_PROFILE),
    HI_WORD(GATT_UUID_SIMPLE_PROFILE),
    /* Local name */
    0x0F,             /* length */
    GAP_ADTYPE_LOCAL_NAME_COMPLETE,
    'B', 'L', 'E', '_', 'P', 'E', 'R', 'I', 'P', 'H', 'E', 'R', 'A', 'L',
};
  1. 链接后能看到的 device name,在这里改
void app_le_gap_init(void)
{
    /* Device name and device appearance */
    uint8_t  device_name[GAP_DEVICE_NAME_LEN] = "BLE_PERIPHERAL";
    uint16_t appearance = GAP_GATT_APPEARANCE_UNKNOWN;
    uint8_t  slave_init_mtu_req = false;


    /* Advertising parameters */
    uint8_t  adv_evt_type = GAP_ADTYPE_ADV_IND;
    uint8_t  adv_direct_type = GAP_REMOTE_ADDR_LE_PUBLIC;
    uint8_t  adv_direct_addr[GAP_BD_ADDR_LEN] = {0};
    uint8_t  adv_chann_map = GAP_ADVCHAN_ALL;
    uint8_t  adv_filter_policy = GAP_ADV_FILTER_ANY;
    uint16_t adv_int_min = DEFAULT_ADVERTISING_INTERVAL_MIN;
    uint16_t adv_int_max = DEFAULT_ADVERTISING_INTERVAL_MAX;

    /* GAP Bond Manager parameters */
    uint8_t  auth_pair_mode = GAP_PAIRING_MODE_PAIRABLE;
    uint16_t auth_flags = GAP_AUTHEN_BIT_BONDING_FLAG;
    uint8_t  auth_io_cap = GAP_IO_CAP_NO_INPUT_NO_OUTPUT;
#if F_BT_LE_SMP_OOB_SUPPORT
    uint8_t  auth_oob = false;
#endif
    uint8_t  auth_use_fix_passkey = false;
    uint32_t auth_fix_passkey = 0;
    uint8_t  auth_sec_req_enable = false;
    uint16_t auth_sec_req_flags = GAP_AUTHEN_BIT_BONDING_FLAG;

    /* Set device name and device appearance */
    le_set_gap_param(GAP_PARAM_DEVICE_NAME, GAP_DEVICE_NAME_LEN, device_name);
    le_set_gap_param(GAP_PARAM_APPEARANCE, sizeof(appearance), &appearance);
    le_set_gap_param(GAP_PARAM_SLAVE_INIT_GATT_MTU_REQ, sizeof(slave_init_mtu_req),
                     &slave_init_mtu_req);

    /* Set advertising parameters */
    le_adv_set_param(GAP_PARAM_ADV_EVENT_TYPE, sizeof(adv_evt_type), &adv_evt_type);
    le_adv_set_param(GAP_PARAM_ADV_DIRECT_ADDR_TYPE, sizeof(adv_direct_type), &adv_direct_type);
    le_adv_set_param(GAP_PARAM_ADV_DIRECT_ADDR, sizeof(adv_direct_addr), adv_direct_addr);
    le_adv_set_param(GAP_PARAM_ADV_CHANNEL_MAP, sizeof(adv_chann_map), &adv_chann_map);
    le_adv_set_param(GAP_PARAM_ADV_FILTER_POLICY, sizeof(adv_filter_policy), &adv_filter_policy);
    le_adv_set_param(GAP_PARAM_ADV_INTERVAL_MIN, sizeof(adv_int_min), &adv_int_min);
    le_adv_set_param(GAP_PARAM_ADV_INTERVAL_MAX, sizeof(adv_int_max), &adv_int_max);
    le_adv_set_param(GAP_PARAM_ADV_DATA, sizeof(adv_data), (void *)adv_data);
    le_adv_set_param(GAP_PARAM_SCAN_RSP_DATA, sizeof(scan_rsp_data), (void *)scan_rsp_data);

    /* Setup the GAP Bond Manager */
    gap_set_param(GAP_PARAM_BOND_PAIRING_MODE, sizeof(auth_pair_mode), &auth_pair_mode);
    gap_set_param(GAP_PARAM_BOND_AUTHEN_REQUIREMENTS_FLAGS, sizeof(auth_flags), &auth_flags);
    gap_set_param(GAP_PARAM_BOND_IO_CAPABILITIES, sizeof(auth_io_cap), &auth_io_cap);
#if F_BT_LE_SMP_OOB_SUPPORT
    gap_set_param(GAP_PARAM_BOND_OOB_ENABLED, sizeof(auth_oob), &auth_oob);
#endif
    le_bond_set_param(GAP_PARAM_BOND_FIXED_PASSKEY, sizeof(auth_fix_passkey), &auth_fix_passkey);
    le_bond_set_param(GAP_PARAM_BOND_FIXED_PASSKEY_ENABLE, sizeof(auth_use_fix_passkey),
                      &auth_use_fix_passkey);
    le_bond_set_param(GAP_PARAM_BOND_SEC_REQ_ENABLE, sizeof(auth_sec_req_enable), &auth_sec_req_enable);
    le_bond_set_param(GAP_PARAM_BOND_SEC_REQ_REQUIREMENT, sizeof(auth_sec_req_flags),
                      &auth_sec_req_flags);

    /* register gap message callback */
    le_register_app_cb(app_gap_callback);
}

Hi,
目前在使用 BLE peripheral 的部分遇到點問題
在 \component\common\bluetooth\realtek\sdk\src\ble\profile\server\simple_ble_service.c


請問上圖紅底線的參數是從哪裡提供的?
我知道在下圖的 server_add_service裡有導入
simple_ble_service_tbl 的 function pointer struct
simp_ble_service_add_service
但卻找不到圖一紅底線的參數是從哪裡導入的

另外想請問
我想不透過AT Command來啟動 BLE peripheral
因此我把ATBp = 1 裡有關的function都拉到 main
為什麼開機後卻只會有下列的畫面
image

是底层 BLE driver stack 提供的,BLE driver 收到 read request 时,attrib_index 就是想要读的 attribute

开启 BLE 前必须先开启 wifi,因为 BLE 和 wifi 共用 RF,wifi 还有 RF 的主控权

你也可以参考一下 Arduino 里面的 BLE