您好,我嘗試創建 Function 來測試
STA 連線的同時,AP 的顯示也出現了
但是點選 AP 名稱連線時,則顯示無法連線
附件為我模仿原有 Code 創建的 Function
WiFi.cpp
//----------------------New----------------------//
int WiFiClass::repeaterBegin(char* ap_ssid, char* ap_password, char* ap_channel, uint8_t ap_hidden_ssid, char* sta_ssid, const char* sta_passphrase)
{
uint8_t status = WL_IDLE_STATUS;
WiFiDrv::repeaterInit();
status = WiFiDrv::apRepeaterSetting(ap_ssid, strlen(ap_ssid), ap_password, strlen(ap_password), ap_channel);
printf("AP : %d\n", status);
status = WiFiDrv::staRepeaterSetting(sta_ssid, strlen(sta_ssid), sta_passphrase, strlen(sta_passphrase));
printf("STA : %d\n", status);
WiFiDrv::repeaterDriverRun(ap_hidden_ssid);
return status;
}
//----------------------New----------------------//
wifi_drv.cpp
//----------------------New----------------------//
int8_t WiFiDrv::apRepeaterSetting(char* ssid, uint8_t ssid_len, const char *passphrase, uint8_t len, const char *channel)
{
int ret = WL_SUCCESS;
//SSID Cheak
ap.ssid.len = ssid_len;
if (ap.ssid.len > 32) {
printf("Error: SSID length can't exceed 32\n\r");
ret = WL_FAILURE;
}
strcpy((char *)ap.ssid.val, (char*)ssid);
if (ap.ssid.val[0] == 0) {
printf("Error: SSID can't be empty\n\r");
ret = WL_FAILURE;
}
//Password Cheak
strcpy((char *)password, (char*)passphrase);
ap.password = password;
ap.password_len = len;
if (ap.password_len <= 0) {
printf("Error: Password can't be empty\n\r");
ret = WL_FAILURE;
}
ap.security_type = RTW_SECURITY_WPA2_AES_PSK;
//Channel
ap.channel = (unsigned char) atoi((const char *)channel);
return ret;
}
int8_t WiFiDrv::staRepeaterSetting(char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len)
{
int ret = WL_SUCCESS;
memset(wifi.bssid.octet, 0, ETH_ALEN);
memcpy(wifi.ssid.val, ssid, ssid_len);
wifi.ssid.len = ssid_len;
if(wifi.ssid.len <= 0){
printf("Error: SSID can't be empty\n\r");
ret = WL_FAILURE;
}
memset(password, 0, sizeof(password));
memcpy(password, passphrase, len);
wifi.password = password;
wifi.password_len = len;
if(wifi.password_len <= 0){
printf("Error: Password can't be empty\n\r");
ret = WL_FAILURE;
}
wifi.security_type = RTW_SECURITY_WPA2_AES_PSK;
wifi.key_id = 0;
return ret;
//
uint8_t dhcp_result;
ret = wifi_connect((char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password, wifi.ssid.len, wifi.password_len, wifi.key_id, NULL);
if (ret == RTW_SUCCESS) {
dhcp_result = LwIP_DHCP(0, DHCP_START);
if (dhcp_result == DHCP_ADDRESS_ASSIGNED) {
return WL_SUCCESS;
} else {
wifi_disconnect();
return WL_FAILURE;
}
}
return ret;
}
int8_t apRepeaterActivate(uint8_t hidden_ssid)
{
int timeout = 20;
int ret = WL_SUCCESS;
printf("\n\rStarting AP ...");
if (hidden_ssid == 1) {
ret = wifi_start_ap_with_hidden_ssid((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel);
} else {
ret = wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel);
}
if(ret < 0) {
printf("\n\rERROR: Operation failed!");
ret = WL_FAILURE;
}
while (1) {
char essid[33];
if (wext_get_ssid(WLAN1_NAME, ((unsigned char *)essid)) > 0) {
if (strcmp(((const char *)essid), ((const char *)ap.ssid.val)) == 0) {
printf("\n\r%s started\n", ap.ssid.val);
ret = WL_SUCCESS;
break;
}
}
if (timeout == 0) {
printf("\n\rERROR: Start AP timeout!");
ret = WL_FAILURE;
break;
}
vTaskDelay(1 * configTICK_RATE_HZ);
timeout --;
}
return ret;
}
int8_t staRepeaterActivate()
{
int ret;
uint8_t dhcp_result;
ret = wifi_connect((char*)wifi.ssid.val, wifi.security_type, (char*)wifi.password, wifi.ssid.len, wifi.password_len, wifi.key_id, NULL);
if (ret == RTW_SUCCESS) {
dhcp_result = LwIP_DHCP(0, DHCP_START);
if (dhcp_result == DHCP_ADDRESS_ASSIGNED) {
return WL_SUCCESS;
} else {
wifi_disconnect();
return WL_FAILURE;
}
}
return ret;
}
void WiFiDrv::repeaterDriverRun(uint8_t hidden_ssid)
{
struct netif *pnetif = &xnetif[0];
wifi_mode = RTW_MODE_STA_AP;
if (init_wlan == false) {
printf("init_wlan : false\n\r");
init_wlan = true;
LwIP_Init();
wifi_on(RTW_MODE_STA_AP);
staRepeaterActivate();
apRepeaterActivate(hidden_ssid);
dhcps_init(pnetif);
} else if(init_wlan == true){
printf("init_wlan : true\n\r");
dhcps_deinit();
wifi_off();
vTaskDelay(20);
wifi_on(RTW_MODE_STA_AP);
staRepeaterActivate();
apRepeaterActivate(hidden_ssid);
dhcps_init(pnetif);
}
}
void WiFiDrv::repeaterInit()
{
init_wifi_struct();
}
//----------------------New----------------------//
再麻煩您協助解惑了