diff --git a/cores/beken-72xx/arduino/libraries/WiFi/WiFi.cpp b/cores/beken-72xx/arduino/libraries/WiFi/WiFi.cpp index b5e354594..32f7d2e15 100644 --- a/cores/beken-72xx/arduino/libraries/WiFi/WiFi.cpp +++ b/cores/beken-72xx/arduino/libraries/WiFi/WiFi.cpp @@ -5,8 +5,9 @@ WiFiClass::WiFiClass() { data = (WiFiData *)calloc(1, sizeof(WiFiData)); - DATA->scanSem = xSemaphoreCreateBinary(); - STA_CFG.dhcp_mode = DHCP_CLIENT; + DATA->scanSem = xSemaphoreCreateBinary(); + STA_CFG.dhcp_mode = DHCP_CLIENT; + STA_ADV_CFG.dhcp_mode = DHCP_CLIENT; } WiFiClass::~WiFiClass() { diff --git a/cores/beken-72xx/arduino/libraries/WiFi/WiFiPrivate.h b/cores/beken-72xx/arduino/libraries/WiFi/WiFiPrivate.h index 276aeaa38..38ec80c00 100644 --- a/cores/beken-72xx/arduino/libraries/WiFi/WiFiPrivate.h +++ b/cores/beken-72xx/arduino/libraries/WiFi/WiFiPrivate.h @@ -57,6 +57,7 @@ extern void wifiEventHandler(rw_evt_type event); typedef struct { network_InitTypeDef_st configSta; + network_InitTypeDef_adv_st configStaAdv; network_InitTypeDef_ap_st configAp; unsigned long scannedAt; SemaphoreHandle_t scanSem; @@ -73,6 +74,7 @@ typedef struct { #define cDATA ((WiFiData *)cls->data) #define STA_CFG (DATA->configSta) +#define STA_ADV_CFG (DATA->configStaAdv) #define AP_CFG (DATA->configAp) #define IP_STATUS (DATA->statusIp) #define LINK_STATUS (DATA->statusLink) diff --git a/cores/beken-72xx/arduino/libraries/WiFi/WiFiSTA.cpp b/cores/beken-72xx/arduino/libraries/WiFi/WiFiSTA.cpp index 2ac77c6a8..a5558d101 100644 --- a/cores/beken-72xx/arduino/libraries/WiFi/WiFiSTA.cpp +++ b/cores/beken-72xx/arduino/libraries/WiFi/WiFiSTA.cpp @@ -13,11 +13,26 @@ WiFiClass::begin(const char *ssid, const char *passphrase, int32_t channel, cons disconnect(false); - strcpy(STA_CFG.wifi_ssid, ssid); - if (passphrase) { - strcpy(STA_CFG.wifi_key, passphrase); + if (bssid) { + strcpy(STA_ADV_CFG.ap_info.ssid, ssid); + if (passphrase) { + strcpy(STA_ADV_CFG.key, passphrase); + STA_ADV_CFG.key_len = strlen(passphrase); + } else { + STA_ADV_CFG.key[0] = '\0'; + STA_ADV_CFG.key_len = 0; + } + STA_ADV_CFG.ap_info.channel = channel; + STA_ADV_CFG.wifi_retry_interval = 100; } else { - STA_CFG.wifi_bssid[0] = '\0'; + strcpy(STA_CFG.wifi_ssid, ssid); + if (passphrase) { + strcpy(STA_CFG.wifi_key, passphrase); + } else { + STA_CFG.wifi_key[0] = '\0'; + } + STA_CFG.wifi_retry_interval = 100; + STA_CFG.wifi_mode = BK_STATION; } if (reconnect(bssid)) @@ -27,21 +42,31 @@ WiFiClass::begin(const char *ssid, const char *passphrase, int32_t channel, cons } bool WiFiClass::config(IPAddress localIP, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) { - STA_CFG.dhcp_mode = localIP ? DHCP_DISABLE : DHCP_CLIENT; + STA_CFG.dhcp_mode = localIP ? DHCP_DISABLE : DHCP_CLIENT; + STA_ADV_CFG.dhcp_mode = localIP ? DHCP_DISABLE : DHCP_CLIENT; if (localIP) { sprintf(STA_CFG.local_ip_addr, IP_FMT, localIP[0], localIP[1], localIP[2], localIP[3]); sprintf(STA_CFG.net_mask, IP_FMT, subnet[0], subnet[1], subnet[2], subnet[3]); sprintf(STA_CFG.gateway_ip_addr, IP_FMT, gateway[0], gateway[1], gateway[2], gateway[3]); + sprintf(STA_ADV_CFG.local_ip_addr, IP_FMT, localIP[0], localIP[1], localIP[2], localIP[3]); + sprintf(STA_ADV_CFG.net_mask, IP_FMT, subnet[0], subnet[1], subnet[2], subnet[3]); + sprintf(STA_ADV_CFG.gateway_ip_addr, IP_FMT, gateway[0], gateway[1], gateway[2], gateway[3]); if (dns1) { sprintf(STA_CFG.dns_server_ip_addr, IP_FMT, dns1[0], dns1[1], dns1[2], dns1[3]); + sprintf(STA_ADV_CFG.dns_server_ip_addr, IP_FMT, dns1[0], dns1[1], dns1[2], dns1[3]); } else { - STA_CFG.dns_server_ip_addr[0] = '\0'; + STA_CFG.dns_server_ip_addr[0] = '\0'; + STA_ADV_CFG.dns_server_ip_addr[0] = '\0'; } } else { - STA_CFG.local_ip_addr[0] = '\0'; - STA_CFG.net_mask[0] = '\0'; - STA_CFG.gateway_ip_addr[0] = '\0'; - STA_CFG.dns_server_ip_addr[0] = '\0'; + STA_CFG.local_ip_addr[0] = '\0'; + STA_CFG.net_mask[0] = '\0'; + STA_CFG.gateway_ip_addr[0] = '\0'; + STA_CFG.dns_server_ip_addr[0] = '\0'; + STA_ADV_CFG.local_ip_addr[0] = '\0'; + STA_ADV_CFG.net_mask[0] = '\0'; + STA_ADV_CFG.gateway_ip_addr[0] = '\0'; + STA_ADV_CFG.dns_server_ip_addr[0] = '\0'; } // from wlan_ui.c:1370 @@ -74,10 +99,8 @@ bool WiFiClass::reconnect(const uint8_t *bssid) { LT_DM(WIFI, "Data = %p", DATA->configSta); - STA_CFG.wifi_mode = BK_STATION; - STA_CFG.wifi_retry_interval = 100; if (bssid) - memcpy(STA_CFG.wifi_bssid, bssid, 6); + memcpy(STA_ADV_CFG.ap_info.bssid, bssid, 6); else memset(STA_CFG.wifi_bssid, 0x00, 6); @@ -91,7 +114,11 @@ bool WiFiClass::reconnect(const uint8_t *bssid) { LT_DM(WIFI, "Starting WiFi..."); __wrap_bk_printf_disable(); - bk_wlan_start_sta(&STA_CFG); + if (bssid) { + bk_wlan_start_sta_adv(&STA_ADV_CFG); + } else { + bk_wlan_start_sta(&STA_CFG); + } __wrap_bk_printf_enable(); LT_DM(WIFI, "Start OK");