How can ESL establish periodic sync with the special AP?

Hi,my board is nRF52840,and the demo is periodic_sync_conn within ncs2.7.0, 

I want to establish periodic sync with the  AP whose rssi is better,but i am failed。Thanks.

struct _AP_info
{
    int8_t sid;
    int8_t rssi;
    bt_addr_le_t addr;
} __packed;
static struct _AP_info AP_info={.rssi=-80};

static void scan_AP(const struct bt_le_scan_recv_info *info)
{
    if (info->rssi > AP_info.rssi)
    {
        AP_info.sid = info->sid;
        AP_info.rssi = info->rssi;
        bt_addr_le_copy(&(AP_info.addr), info->addr);
        printk("Get better rssi AP:sid=%d,rssi=%i,addr=0x%X\n", AP_info.sid, AP_info.rssi, AP_info.addr.a.val[0]);
    }
}
static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_simple *buf)
{
    char name[NAME_LEN] = {0};
    char le_addr[BT_ADDR_LE_STR_LEN];
    struct _AP_info *p_AP_info = NULL;

    (void)memset(name, 0, sizeof(name));
    bt_data_parse(buf, data_cb, name);
    bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr));

    if (0 == strstr(name, "PAwR conn sample") || 0 == info->interval){
        return;
    }

    //printk("scan_recv:%s,sid:%d,rssi:%i,type:%d,addr:%s\n", name, info->sid, info->rssi, info->addr->type, le_addr);
    scan_AP(info);

    if (!per_adv_found){
        // per_sid = info->sid;
        // bt_addr_le_copy(&per_addr, info->addr);
        per_sid = AP_info.sid;
        bt_addr_le_copy(&per_addr, &(AP_info.addr));

        per_adv_found = true;
        k_sem_give(&sem_per_adv);
    }
}
static struct bt_le_scan_cb scan_callbacks = {
    .recv = scan_recv,
};
Related