mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-04 18:25:45 +00:00
Ssid2modv2 (#1274)
* SSID2 autoswitch BEKEN only * SSID2 autoswitch BEKEN only v2 --------- Co-authored-by: Tester23 <openshwprojects@gmail.com>
This commit is contained in:
@ -1276,6 +1276,9 @@ int http_fn_cfg_wifi(http_request_t* request) {
|
||||
add_label_text_field(request, "SSID", "ssid", CFG_GetWiFiSSID(), "<form action=\"/cfg_wifi_set\">");
|
||||
add_label_password_field(request, "", "pass", CFG_GetWiFiPass(), "<br>Password <span style=\"float:right;\"><input type=\"checkbox\" onclick=\"e=getElement('pass');if(this.checked){e.value='';e.type='text'}else e.type='password'\" > enable clear text password (clears password)</span>");
|
||||
poststr_h2(request, "Alternate WiFi (used when first one is not responding)");
|
||||
#ifndef PLATFORM_BEKEN
|
||||
poststr_h2(request, "SSID2 only on Beken Platform (BK7231T,BK7231N)");
|
||||
#endif
|
||||
add_label_text_field(request, "SSID2", "ssid2", CFG_GetWiFiSSID2(), "");
|
||||
add_label_password_field(request, "", "pass2", CFG_GetWiFiPass2(), "<br>Password2 <span style=\"float:right;\"><input type=\"checkbox\" onclick=\"e=getElement('pass2');if(this.checked){e.value='';e.type='text'}else e.type='password'\" > enable clear text password (clears password)</span>");
|
||||
#if ALLOW_WEB_PASSWORD
|
||||
|
||||
@ -288,6 +288,53 @@ extern int g_ln882h_pendingPowerSaveCommand;
|
||||
void LN882H_ApplyPowerSave(int bOn);
|
||||
#endif
|
||||
|
||||
// SSID switcher by xjikka 20240525
|
||||
#if ALLOW_SSID2
|
||||
static int g_SSIDactual = 0; // 0=SSID1 1=SSID2
|
||||
static int g_SSIDSwitchAfterTry = 3;// switch to opposite SSID after
|
||||
static int g_SSIDSwitchCnt = 0; // switch counter
|
||||
#endif
|
||||
|
||||
void CheckForSSID12_Switch() {
|
||||
#if ALLOW_SSID2
|
||||
// nothing to do if SSID2 is unset
|
||||
if (CFG_GetWiFiSSID2()[0] == 0) return;
|
||||
if (g_SSIDSwitchCnt++ < g_SSIDSwitchAfterTry) {
|
||||
ADDLOGF_INFO("WiFi SSID: waiting for SSID switch %d/%d (using SSID%d)\r\n", g_SSIDSwitchCnt, g_SSIDSwitchAfterTry, g_SSIDactual+1);
|
||||
return;
|
||||
}
|
||||
g_SSIDSwitchCnt = 0;
|
||||
g_SSIDactual ^= 1; // toggle SSID
|
||||
ADDLOGF_INFO("WiFi SSID: switching to SSID%i\r\n", g_SSIDactual + 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* CFG_GetWiFiSSIDX() {
|
||||
#if ALLOW_SSID2
|
||||
if (g_SSIDactual) {
|
||||
return CFG_GetWiFiSSID2();
|
||||
}
|
||||
else {
|
||||
return CFG_GetWiFiSSID();
|
||||
}
|
||||
#else
|
||||
return CFG_GetWiFiSSID();
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* CFG_GetWiFiPassX() {
|
||||
#if ALLOW_SSID2
|
||||
if (g_SSIDactual) {
|
||||
return CFG_GetWiFiPass2();
|
||||
}
|
||||
else {
|
||||
return CFG_GetWiFiPass();
|
||||
}
|
||||
#else
|
||||
return CFG_GetWiFiPass();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Main_OnWiFiStatusChange(int code)
|
||||
{
|
||||
// careful what you do in here.
|
||||
@ -325,6 +372,9 @@ void Main_OnWiFiStatusChange(int code)
|
||||
break;
|
||||
case WIFI_STA_CONNECTED:
|
||||
g_bHasWiFiConnected = 1;
|
||||
#if ALLOW_SSID2
|
||||
g_SSIDSwitchCnt = 0;
|
||||
#endif
|
||||
ADDLOGF_INFO("Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - %i\r\n", code);
|
||||
|
||||
if (bSafeMode == 0) {
|
||||
@ -448,13 +498,19 @@ void Main_ConnectToWiFiNow() {
|
||||
const char* wifi_ssid, * wifi_pass;
|
||||
|
||||
g_bOpenAccessPointMode = 0;
|
||||
wifi_ssid = CFG_GetWiFiSSID();
|
||||
wifi_pass = CFG_GetWiFiPass();
|
||||
HAL_ConnectToWiFi(wifi_ssid, wifi_pass,&g_cfg.staticIP);
|
||||
// register function to get callbacks about wifi changes.
|
||||
CheckForSSID12_Switch();
|
||||
wifi_ssid = CFG_GetWiFiSSIDX();
|
||||
wifi_pass = CFG_GetWiFiPassX();
|
||||
// register function to get callbacks about wifi changes ..
|
||||
// ... but do it, before calling HAL_ConnectToWiFi(),
|
||||
// otherwise callbacks are not possible (e.g. WIFI_STA_CONNECTING can never be called )!!
|
||||
HAL_WiFi_SetupStatusCallback(Main_OnWiFiStatusChange);
|
||||
ADDLOGF_DEBUG("Registered for wifi changes\r\n");
|
||||
g_connectToWiFi = 0;
|
||||
ADDLOGF_INFO("Registered for wifi changes\r\n");
|
||||
ADDLOGF_INFO("Connecting to SSID [%s]\r\n", wifi_ssid);
|
||||
HAL_ConnectToWiFi(wifi_ssid, wifi_pass, &g_cfg.staticIP);
|
||||
// don't set g_connectToWiFi = 0; here!
|
||||
// this would overwrite any changes, e.g. from Main_OnWiFiStatusChange !
|
||||
// so don't do this here, but e.g. set in Main_OnWiFiStatusChange if connected!!!
|
||||
}
|
||||
bool Main_HasFastConnect() {
|
||||
if (g_bootFailures > 2)
|
||||
|
||||
Reference in New Issue
Block a user