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。The ESL will sync with another AP automatically Disappointed

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,
};
  • Hi Tan, 
    As you can see in your log: 


    Creating Periodic Advertising Sync is printed right after the first AP is captured. So you need to check what's wrong with the check if (!per_adv_found && second_cnt>5) . Is 5 seconds too short. Or if the second_cnt is counting correctly or not or the if condition was correct or not. Please try to print the log out. 

    I don't think this is something very hard to debug. Please show the log with all the output, for example the second_cnt print out in the timer handler and in the if (!per_adv_found && second_cnt>5) 

    I think what you implement is OK , about the timer. You can increase the timer to 10 sec just to test. 

Related