如何实时更改广播地址和MAC地址?



  • 请教下在ble_simple_peripheral这个工程里面广播的名字和MAC地址怎么样实现实时更改?

    static void sp_start_adv(void)
    {
    mac_addr_t addr2;
    addr2.addr[0]=0x11;
    addr2.addr[1]=0x22;
    addr2.addr[2]=0x33;
    addr2.addr[3]=0x44;
    addr2.addr[4]=0x55;
    addr2.addr[5]=0x66;
    gap_mac_addr_t addr;
    addr.addr_type=0;
    // addr1.addr addr2;
    addr.addr=addr2;

    // Set advertising parameters
    gap_adv_param_t adv_param;
      adv_param.peer_mac_addr = addr;
    

    // adv_param.adv_mode = GAP_ADV_MODE_UNDIRECT;
    adv_param.adv_mode = GAP_ADV_MODE_NON_CONN_SCAN;
    // adv_param.adv_addr_type = GAP_ADDR_TYPE_PUBLIC;
    adv_param.adv_addr_type = GAP_ADDR_TYPE_PRIVATE;
    adv_param.adv_chnl_map = GAP_ADV_CHAN_ALL;
    adv_param.adv_filt_policy = GAP_ADV_ALLOW_SCAN_ANY_CON_ANY;
    adv_param.adv_intv_min = 300;
    adv_param.adv_intv_max = 300;

    gap_set_advertising_param(&adv_param);//设置BLE参数
    // Set advertising data & scan response data 设置广播数据和扫描响应数据
    gap_set_advertising_data(adv_data, sizeof(adv_data));  
    gap_set_advertising_rsp_data(scan_rsp_data, sizeof(scan_rsp_data));
    // Start advertising
    co_printf("Start advertising...\r\n");
    gap_start_advertising(0);
    

    }



  • 停止广播, 再广播一次, 地址就修改了



  • 此回复已被删除!