Other Parts Discussed in Thread:CC3235S
首先,用SDK中的network_terminal的demo程序,扫描出来的AP结果每次都是一样的,比如说,我先打开路由器A,输入scan -n 30扫描30个AP结果,其中有A路由器,然后断开路由器A,再扫描一次,结果没有变化,还是有路由器A,而且等待几分钟后再尝试依旧如此。比如重启后再扫描,结果才能更新,是不是CC3235S缓存了扫描结果,如果是,那么怎样才能手动删除缓存结果。
自己开发过程中也是遇到了这种问题,偶尔需要扫码一下AP,结果每次扫出来的结果都是一样的,代码如下
int get_ap_list(SlWlanNetworkEntry_t *pAp_entry,int entry_number)
{
int ret_val;
int ret = 0;
int i;
UART_PRINT( "start scan \n\r");
ret_val = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY_EN(1), NULL,0);
if(ret_val < 0)
{
UART_PRINT("enable scan policy failed, ret = %d\n\r",ret_val);
}
/*延时一定时间,等待扫描完成*/
mdelay(500);
for(i=0;i<10;i++)
{
ret = sl_WlanGetNetworkList(0, entry_number, pAp_entry);
if(ret >0)
break;
else if(i == 9)
{
UART_PRINT("sl_WlanGetNetworkList Failed, ret = %d\n\r",ret);
soft_reset();
}
msleep(1000);
}
UART_PRINT( "end scan \n\r");
ret_val = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY_EN(0), NULL,0);
if(ret_val < 0)
{
UART_PRINT("enable scan policy failed, ret = %d\n\r",ret_val);
}
return ret;
}
Viki Shi:
disable扫描再打开试试
,
Viki Shi:
参考如下代码:static int GetScanResult(SlWlanNetworkEntry_t* netEntries) {unsigned char policyOpt;unsigned long IntervalVal = 60;int lRetVal;policyOpt = SL_WLAN_CONNECTION_POLICY(0, 0, 0, 0);lRetVal = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, policyOpt, NULL, 0);ASSERT_ON_ERROR(lRetVal);// enable scanpolicyOpt = SL_WLAN_SCAN_POLICY(1, 0);// set scan policy - this starts the scanlRetVal = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, policyOpt,(unsigned char *) (IntervalVal),sizeof(IntervalVal));ASSERT_ON_ERROR(lRetVal);// delay 1 second to verify scan is startedsleep(1);// lRetVal indicates the valid number of entries// The scan results are occupied in netEntries[]lRetVal = sl_WlanGetNetworkList(0, SCAN_TABLE_SIZE, netEntries);ASSERT_ON_ERROR(lRetVal);// Disable scanpolicyOpt = SL_WLAN_SCAN_POLICY(0, 0);// set scan policy - this stops the scansl_WlanPolicySet(SL_WLAN_POLICY_SCAN, policyOpt,(unsigned char *) (IntervalVal), sizeof(IntervalVal));ASSERT_ON_ERROR(lRetVal);return lRetVal;}
,
Zhiyuan HE:
不好意思,我按照您说的改了一下,先disable掉自动连接AP,然后再打开扫描,延时1s,获取扫描结果,再关闭扫描,最终结果还是一样的问题,代码如下:
int get_ap_list(SlWlanNetworkEntry_t *pAp_entry,int entry_number) {int ret_val;int ret = 0;int i;unsigned long IntervalVal = 60;/*延时一定时间,等待扫描完成*/ret_val = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(0, 0, 0, 0), NULL, 0);if(ret_val < 0){UART_PRINT("sl_WlanPolicySet disconnect error, ret_val = %d\n\r", ret_val);}UART_PRINT( "start scan \n\r");ret_val = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY(1, 0), (unsigned char *) (IntervalVal), sizeof(IntervalVal));if(ret_val < 0){UART_PRINT("enable scan policy failed, ret = %d\n\r",ret_val);}mdelay(1000);for(i=0;i<10;i++){ret = sl_WlanGetNetworkList(0, entry_number, pAp_entry);if(ret >0)break;else if(i == 9){UART_PRINT("sl_WlanGetNetworkList Failed, ret = %d\n\r",ret);soft_reset();}msleep(1000);}UART_PRINT( "end scan \n\r");ret_val = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY(0, 0), (unsigned char *) (IntervalVal), sizeof(IntervalVal));if(ret_val < 0){UART_PRINT("enable scan policy failed, ret = %d\n\r",ret_val);}return ret; }
,
Viki Shi:
你后面扫描了多少次,有可能是scan cache还没改过来:
After setting policy, calling Scan command would retrieve results from NWP cache, according to set settings.
Please note that the NWP cache has ageing time, so older retrieved results could violate the new policy.
,
Zhiyuan HE:
interval设置20s,每次扫描后等待两三秒接着扫,扫了两分多钟,结果还是一样的。我也觉得是缓存了。
关于这个interval,我觉得很奇怪,文档里介绍是
sl_WlanGetNetworkList triggers a one-shot scan if there are no scan results in the system, or if the scan results which exist are old (aging is defined as 20 seconds if the scan policy is disabled, or twice the scan interval if the policy is enabled).
所以意思就是我enable扫描后,cache的aging是interval的两倍,也就是我配置了interval为20s,每40s就会刷新一遍scan cache,但是实际情况下即使过了好几分钟都没有刷新,重启设备之后扫描出来的AP才会更新。
所以想问问有没有什么办法能够清掉scan cache,我在文档里没有看到相关的API
,
Viki Shi:
尝试一下下面的语句:
/* Clear the results buffer */memset(&app_CB.gDataBuffer, 0x0, sizeof(app_CB.gDataBuffer));
,
Zhiyuan HE:
这个应该没用把,这个是SDK里的,network_terminal这个demo程序里读取扫描结果前确实已经调用这条指令来清空app_CB这个全局变量了
而且我自己的代码中从NWP中拿到的扫描结果是放在局部变量里的,函数执行完变量就销毁了,所以请不请空都没有影响。
,
Viki Shi:
请看一下这边的类似问题:e2e.ti.com/…/652321
,
Zhiyuan HE:
感谢,我看了这个帖子,确实每次调用sl_WlanGetNetworkList只会添加AP,没有办法把已经不存在的AP删掉,只不过这个帖子依旧没有解答为什么不存在的AP依旧会出现在扫描结果里,我怀疑是不是SDK有问题,毕竟文档里写了sl_WlanGetNetworkList扫描的结果也是会定时清缓存的,但是实际上没有。
另一种后台扫描的方式在demo中是可行的,我在network_terminal这个demo程序中尝试了设置scan policy的方式,也即先输入setpolicy -i 10, 再输入scan -n 30,扫描间隔拉长后确实刷新了结果,但是我不太清楚为什么我在我们开发的项目中设置scan policy后依旧不会刷新扫描结果,而且我也尝试清空所指内存的数据,结果还是一样,麻烦帮我看看是不是我哪里写的有问题
int get_ap_list(SlWlanNetworkEntry_t *pAp_entry,int entry_number) {int ret_val;int ret = 0;int i;unsigned long IntervalVal = 5;/*延时一定时间,等待扫描完成*/ret_val = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(0, 0, 0, 0), NULL, 0);if (ret_val < 0){UART_PRINT("wifi disconnect Failed, ret_val = %d\n\r", ret_val);}UART_PRINT( "start scan \n\r");ret_val = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY(1, 0), (unsigned char *) (IntervalVal), sizeof(IntervalVal));if(ret_val < 0){UART_PRINT("enable scan policy failed, ret = %d\n\r",ret_val);}mdelay(1000);for(i=0;i<10;i++){ret = sl_WlanGetNetworkList(0, entry_number, pAp_entry);if(ret >0)break;else if(i == 9){UART_PRINT("sl_WlanGetNetworkList Failed, ret = %d\n\r",ret);soft_reset();}msleep(1000);}UART_PRINT( "end scan \n\r");ret_val = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY(0, 0), (unsigned char *) (IntervalVal), sizeof(IntervalVal));if(ret_val < 0){UART_PRINT("enable scan policy failed, ret_val = %d\n\r",ret_val);}ret_val = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(1, 0, 0, 0), NULL, 0);if (ret_val < 0){UART_PRINT("wifi disconnect Failed, ret_val = %d\n\r",ret_val);}return ret; }我是先关掉auto connect,再打开scan,调用sl_WlanGetNetworkList,最后关掉scan,设置auto connect。似乎auto connect与后台扫描冲突,所以我是这样先关掉,扫描结束后再开启auto connect