我建置Standard SDK於BW16上,
並使用wlan_repeater的範例測試AP+STA mode同時使用的情況,
在範例中我關閉了WLAN_FAST_CONNECT,
並於開啟STA模式前啟用autoreconnect的功能,
剛開始BW16可以正常開啟AP並同時使用STA進行連線;
當我斷開STA所連線的網路時,
BW16開始進行重新連線的動作,但此時BW16上的AP便無法使用了,
需等到BW16的STA連接上,AP才會再重新啟動,
想請問這部分該如何修正呢?
或者除了wlan_repeater外還有其他AP+STA mode的使用範例可以參考嗎?
代碼如下:
static void example_wlan_repeater_thread(void *param)
{
/* To avoid gcc warnings */
( void ) param;
// Wait for other task stable.
vTaskDelay(4000);
/*********************************************************************************
* 1. Enable Wi-Fi with concurrent (STA + AP) mode
*********************************************************************************/
printf("\n\r[WLAN_REPEATER_EXAMPLE] Enable Wi-Fi with concurrent (STA + AP) mode\n");
/*********************************************************************************
* 1-1. Disable Wi-Fi
*********************************************************************************/
printf("\n\r[WLAN_REPEATER_EXAMPLE] Disable Wi-Fi\n");
wifi_off();
vTaskDelay(20);
/*********************************************************************************
* 1-2. Enable Wi-Fi with STA + AP mode
*********************************************************************************/
printf("\n\r[WLAN_REPEATER_EXAMPLE] Enable Wi-Fi with STA + AP mode\n");
if(wifi_on(RTW_MODE_STA_AP) < 0){
printf("\n\r[WLAN_REPEATER_EXAMPLE] ERROR: wifi_on failed\n");
return;
}
uint8_t *mac = LwIP_GetMAC(&xnetif[0]);
bridgeif_set_mac_init(mac);
bridgeif_add_port_sta_netif();
bridgeif_add_port_ap_netif();
/*********************************************************************************
* 1-3. Start AP
*********************************************************************************/
printf("\n\r[WLAN_REPEATER_EXAMPLE] Start AP\n");
char *ssid = "AmebaRPT";
char *password = "12345678"; // NULL for RTW_SECURITY_OPEN
int channel = 6;
if(wifi_start_ap(ssid, (password)?RTW_SECURITY_WPA2_AES_PSK:RTW_SECURITY_OPEN, password, strlen(ssid), (password)?strlen(password):0, channel) < 0) {
printf("\n\r[WLAN_REPEATER_EXAMPLE] ERROR: wifi_start_ap failed\n");
return;
}
/*********************************************************************************
* 1-4. Check AP running
*********************************************************************************/
printf("\n\r[WLAN_REPEATER_EXAMPLE] Check AP running\n");
int timeout = 20;
while(1) {
char essid[33];
if(wext_get_ssid(WLAN1_NAME, (unsigned char *) essid) > 0) {
if(strcmp((const char *) essid, (const char *)ssid) == 0) {
printf("\n\r[WLAN_REPEATER_EXAMPLE] %s started\n", ssid);
break;
}
}
if(timeout == 0) {
printf("\n\r[WLAN_REPEATER_EXAMPLE] ERROR: Start AP timeout\n");
return;
}
vTaskDelay(1 * configTICK_RATE_HZ);
timeout --;
}
/*********************************************************************************
* 1-5. Start DHCP server
*********************************************************************************/
printf("\n\r[WLAN_REPEATER_EXAMPLE] Start DHCP server\n");
#if CONFIG_LWIP_LAYER
dhcps_init(&xnetif[1]);
vTaskDelay(1000);
#endif
/*********************************************************************************
* 1-6. Connect to AP using STA mode and start DHCP client
*********************************************************************************/
printf("\n\r[WLAN_REPEATER_EXAMPLE] Connect to AP\n");
char *sta_ssid = "iPhone";
char *sta_password = "77777777";
wifi_set_autoreconnect(1);
if(wifi_connect(sta_ssid, RTW_SECURITY_WPA2_AES_PSK, sta_password, strlen(sta_ssid), strlen(sta_password), -1, NULL) == RTW_SUCCESS)
LwIP_DHCP(0, DHCP_START);
printf("\n\r[WLAN_REPEATER_EXAMPLE] Task delete.\n");
vTaskDelete(NULL);
}