From 2126e7a60bfd7ce1327c07254ffe322fb96fdb12 Mon Sep 17 00:00:00 2001 From: MaxineMuster Date: Fri, 29 Nov 2024 21:48:22 +0100 Subject: [PATCH 1/3] try web gui setting of the new retain feature from XJIKKA --- src/httpserver/http_fns.c | 52 +++++++++++++++++++++---- src/new_pins.c | 8 +++- src/new_pins.h | 17 ++++++++ src/user_main.c | 81 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 144 insertions(+), 14 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 7285ebad6..8605ce59f 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1313,15 +1313,26 @@ int http_fn_cfg_wifi(http_request_t* request) { \ "); poststr_h2(request, "Use this to connect to your WiFi"); - add_label_text_field(request, "SSID", "ssid", CFG_GetWiFiSSID(), "
"); - add_label_password_field(request, "", "pass", CFG_GetWiFiPass(), "
Password enable clear text password (clears existing)"); - poststr_h2(request, "Alternate WiFi (used when first one is not responding)"); - poststr(request, "Note: It is possible to retain used SSID using command setStartupSSIDChannel in early.bat"); -#ifndef PLATFORM_BEKEN - poststr_h2(request, "SSID2 only on Beken Platform (BK7231T, BK7231N)"); + add_label_text_field(request, "SSID" +#if ALLOW_SSID2 + "1" #endif + , "ssid", CFG_GetWiFiSSID(), ""); + add_label_password_field(request, "", "pass", CFG_GetWiFiPass(), "
Password" +#if ALLOW_SSID2 + "1" +#endif + " enable clear text password (clears existing)"); +#if PLATFORM_BEKEN + int fval = HAL_FlashVars_GetChannelValue(SSIDRetainChannel); + poststr_h4(request, "Alternate WiFi (used when first one is not responding)"); +// poststr_h2(request, "SSID2 only on Beken Platform (BK7231T, BK7231N)"); add_label_text_field(request, "SSID2", "ssid2", CFG_GetWiFiSSID2(), ""); add_label_password_field(request, "", "pass2", CFG_GetWiFiPass2(), "
Password2 enable clear text password (clears existing)"); + hprintf255(request, "

Select SSID used first: ",(fval==9991) ? "selected":"",(fval==990 || fval==991) ? "selected":""); +#endif #if ALLOW_WEB_PASSWORD int web_password_enabled = strcmp(CFG_GetWebPassword(), "") == 0 ? 0 : 1; poststr_h2(request, "Web Authentication"); @@ -1379,7 +1390,6 @@ int http_fn_cfg_name(http_request_t* request) { int http_fn_cfg_wifi_set(http_request_t* request) { char tmpA[128]; int bChanged; - addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "HTTP_ProcessPacket: generating cfg_wifi_set \r\n"); bChanged = 0; @@ -1405,6 +1415,34 @@ int http_fn_cfg_wifi_set(http_request_t* request) { if (http_getArg(request->url, "pass2", tmpA, sizeof(tmpA))) { bChanged |= CFG_SetWiFiPass2(tmpA); } + if (http_getArg(request->url, "startSSID", tmpA, sizeof(tmpA))) { + int start_SSID = atoi(tmpA); + addLogAdv(LOG_DEBUG, LOG_FEATURE_GENERAL, "start_SSID with value %i", start_SSID); + // start values: + // 0 --> SSID1 + // 1 --> SSID2 + // 2 --> remember last SSID + // channel values for this cases: + // SSID2 --> 9991 + // retain, actual SSID1 --> 990 + // retain, actual SSID2 --> 991 + // SSID1 --> all other values (e.g. 9990) + + // during enabling the feature, we need to set the "actual" SSID + switch (start_SSID) + { + case 0: + UpdateSSIDretainedIfChanged_StoredValue(9990); // start SSID1 + break; + case 1: + UpdateSSIDretainedIfChanged_StoredValue(9991); // start SSID2 + break; + case 2: + UpdateSSIDretainedIfChanged_StoredValue(990); // store actual SSID + break; + } + } + #if ALLOW_WEB_PASSWORD if (http_getArg(request->url, "web_admin_password_enabled", tmpA, sizeof(tmpA))) { int web_password_enabled = atoi(tmpA); diff --git a/src/new_pins.c b/src/new_pins.c index 4c0411a90..c29097416 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -43,6 +43,7 @@ int g_initialPinStates = 0; // To enable this feature, the channel that will be used to store the last SSID // must be set using the setStartupSSIDChannel command in early.bat. // It has to be in early.bat.Autoexec.bat is processed after the wifi data is loaded. +/* int g_StartupSSIDRetainChannel = -1; // -1 disabled, 0..MAX_RETAIN_CHANNELS-1 channel to store last SSID int FV_GetStartupSSID_StoredValue(int adefault) { @@ -60,6 +61,7 @@ void FV_UpdateStartupSSIDIfChanged_StoredValue(int assidindex) { } HAL_FlashVars_SaveChannel(g_StartupSSIDRetainChannel,assidindex); } +*/ #endif void PIN_DeepSleep_MakeSureEdgesAreAlloced() { @@ -2197,11 +2199,11 @@ static commandResult_t CMD_SetChannelType(const void* context, const char* cmd, return CMD_RES_OK; } #if ALLOW_SSID2 +/* // setStartupSSIDChannel [-1 or RetainChannelIndex] static commandResult_t CMD_setStartupSSIDChannel(const void* context, const char* cmd, const char* args, int cmdFlags) { Tokenizer_TokenizeString(args, 0); - if (Tokenizer_GetArgsCount() >= 1) { int fval = Tokenizer_GetArgInteger(0); if ((fval < -1) || (fval >= MAX_RETAIN_CHANNELS - 1)) { @@ -2219,6 +2221,7 @@ static commandResult_t CMD_setStartupSSIDChannel(const void* context, const char // setStartupSSID [0/1] // Sets startup SSID - 0=SSID1 1=SSID2 - which SSID will be used after reboot. // for this to work, setStartupSSIDChannel and SSID2 must be set + static commandResult_t CMD_setStartupSSID(const void* context, const char* cmd, const char* args, int cmdFlags) { Tokenizer_TokenizeString(args, 0); @@ -2245,6 +2248,7 @@ static commandResult_t CMD_setStartupSSID(const void* context, const char* cmd, } return CMD_RES_OK; } +*/ #endif /// @brief Computes the Relay and PWM count. /// @param relayCount Number of relay and LED channels. @@ -2407,6 +2411,7 @@ void PIN_AddCommands(void) //cmddetail:"fn":"CMD_setButtonHoldRepeat","file":"new_pins.c","requires":"", //cmddetail:"examples":""} CMD_RegisterCommand("setButtonHoldRepeat", CMD_setButtonHoldRepeat, NULL); +/* #if ALLOW_SSID2 //cmddetail:{"name":"setStartupSSIDChannel","args":"[Value]", //cmddetail:"descr":"Sets retain channel number to store last used SSID, 0..MAX_RETAIN_CHANNELS-1, -1 to disable. Suggested channel number is 7 (MAXMAX_RETAIN_CHANNELS-5)", @@ -2419,4 +2424,5 @@ void PIN_AddCommands(void) //cmddetail:"examples":""} CMD_RegisterCommand("setStartupSSID", CMD_setStartupSSID, NULL); #endif +*/ } diff --git a/src/new_pins.h b/src/new_pins.h index 1bd8cbcb2..3285f0d16 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -1435,8 +1435,25 @@ int PIN_IOR_NofChan(int test); extern const char* g_channelTypeNames[]; #if ALLOW_SSID2 +/* int FV_GetStartupSSID_StoredValue(int adefault); void FV_UpdateStartupSSIDIfChanged_StoredValue(int assidindex); +*/ +#define SSIDRetainChannel 7 +// we will use this channel to store all information for the retain SSID feature: +// if retaining is set and +// which was the last used channel +// the fixed starting SSID +// +// we need two values: +// we use 999<0/1> as "magic numbers" for retain setting +// we use 9999<0/1> as "magic numbers" for "static" setting + +// retaining is set and SSID1 was last --> 990 +// retaining is set and SSID2 was last --> 991 +// retain is unset - start with SSID1 --> 9990 +// retain is unset - start with SSID2 --> 9991 +void UpdateSSIDretainedIfChanged_StoredValue(int val); // needs g_SSIDactual, so defined in user_main.c #endif #endif diff --git a/src/user_main.c b/src/user_main.c index 0c58ef100..4c2c9951e 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -289,9 +289,50 @@ void LN882H_ApplyPowerSave(int bOn); // SSID switcher by xjikka 20240525 #if ALLOW_SSID2 -#define SSID_USE_SSID1 0 -#define SSID_USE_SSID2 1 -static int g_SSIDactual = SSID_USE_SSID1; // -1 not initialized, 0=SSID1 1=SSID2 +//#define SSID_USE_SSID1 0 +//#define SSID_USE_SSID2 1 +// static int g_SSIDactual = SSID_USE_SSID1; // -1 not initialized, 0=SSID1 1=SSID2 + +// settings for retain SSID feature +// strictly speaking we only have to take into account one situation: +// "retaining" is set and SSID2 should be used first +// else it's SSID1 +// and doesn't matter if we start with SSID1 because it's default +// of if SSID1 was the last one used ... + +// retaining is set and SSID1 was last --> 990 +// retaining is set and SSID2 was last --> 991 +// everything else: retain is unset +// only if there is a value 991, we need to use SSID2 (g_SSIDactual = 1) +// in all other cases use SSID1 (g_SSIDactual = 0) +static int g_SSIDactual=0; + +// set the retained SSID +// +void UpdateSSIDretainedIfChanged_StoredValue(int val) { + int fval = HAL_FlashVars_GetChannelValue(SSIDRetainChannel); + addLogAdv(LOG_DEBUG, LOG_FEATURE_GENERAL, "UpdateSSIDretainedIfChanged_StoredValue value %i", val); + switch(val) + { + case 990: + val += g_SSIDactual; // 990 means "actual SSID" + break; + case 9990: // 990 means "use SSID1" + case 9991: // 990 means "use SSID2" + break; + default: + val = -9999; // unknown value + break; + } + if (val == -9999) return; + if (fval == val) { + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "first startup SSID unchanged (SSID%i), HAL_FlashVars_SaveChannel skipped", val); + return; //same value, no update + } + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "setting first startup SSID to SSID%i, HAL_FlashVars_SaveChannel skipped", val); + HAL_FlashVars_SaveChannel(SSIDRetainChannel, val); +} + static int g_SSIDSwitchAfterTry = 3;// switch to opposite SSID after static int g_SSIDSwitchCnt = 0; // switch counter #endif @@ -309,7 +350,7 @@ void CheckForSSID12_Switch() { ADDLOGF_INFO("WiFi SSID: switching to SSID%i\r\n", g_SSIDactual + 1); #endif } - +/* //20241125 XJIKKA Init last stored SSID from RetailChannel if set //Note that it must be set in early.bat using CMD_setStartupSSIDChannel void Init_WiFiSSIDactual_FromChannelIfSet(void) { @@ -317,6 +358,7 @@ void Init_WiFiSSIDactual_FromChannelIfSet(void) { g_SSIDactual = FV_GetStartupSSID_StoredValue(SSID_USE_SSID1); #endif } +*/ const char* CFG_GetWiFiSSIDX() { #if ALLOW_SSID2 if (g_SSIDactual) { @@ -379,8 +421,31 @@ void Main_OnWiFiStatusChange(int code) ADDLOGF_INFO("Main_OnWiFiStatusChange - WIFI_STA_AUTH_FAILED - %i\r\n", code); break; case WIFI_STA_CONNECTED: + { #if ALLOW_SSID2 - if (!g_bHasWiFiConnected) FV_UpdateStartupSSIDIfChanged_StoredValue(g_SSIDactual); //update ony on first connect + int actval = HAL_FlashVars_GetChannelValue(SSIDRetainChannel); + //update retain value + // only if + // on first connect and + // retain is set and + // value is different + + // remember: actval == 990 if SSID1 is used --> g_SSIDactual = 0 + // actval == 991 if SSID2 is used --> g_SSIDactual = 1 + + // we only need to store SSID value, if this is NOT the case, because g_SSIDactual doesn't match the retain value + // actval == 990 but g_SSIDactual == 1 --> we need to store 991 + // actval == 991 but g_SSIDactual == 0 --> we need to store 990 + // --> in both cases: actval + g_SSIDactual = 991 + // + // countercheck: in both other cases (if retained vale eaquals actual value): + // actval + g_SSIDactual is <> 991 ( it's 990 or 992) + // + // so testing for actval + g_SSIDactual == 991 is o.k. to test + // retain is set and value is different in one test !! + + if ( !g_bHasWiFiConnected && ( (actval + g_SSIDactual ) == 991 ) ) + HAL_FlashVars_SaveChannel(SSIDRetainChannel, 990 + g_SSIDactual); #endif g_bHasWiFiConnected = 1; #if ALLOW_SSID2 @@ -408,6 +473,7 @@ void Main_OnWiFiStatusChange(int code) g_ln882h_pendingPowerSaveCommand = -1; } #endif + } break; /* for softap mode */ case WIFI_AP_CONNECTED: @@ -1356,7 +1422,10 @@ void Main_Init_After_Delay() ADDLOGF_INFO("###### safe mode activated - boot failures %d", g_bootFailures); } #if ALLOW_SSID2 - Init_WiFiSSIDactual_FromChannelIfSet();//Channel must be set in early.bat using CMD_setStartupSSIDChannel +// Init_WiFiSSIDactual_FromChannelIfSet();//Channel must be set in early.bat using CMD_setStartupSSIDChannel + int ssidret=HAL_FlashVars_GetChannelValue(SSIDRetainChannel) ; + g_SSIDactual = ( (ssidret == 991) || (ssidret == 9991) ); // 0=SSID1 1=SSID2 + ADDLOGF_INFO("setting g_SSIDactual to %i (CH7 val=%i)", g_SSIDactual , HAL_FlashVars_GetChannelValue(SSIDRetainChannel) ); #endif wifi_ssid = CFG_GetWiFiSSIDX(); wifi_pass = CFG_GetWiFiPassX(); From 0c5cec9ea71771c056a94262e4132eec1275bc60 Mon Sep 17 00:00:00 2001 From: MaxineMuster Date: Fri, 29 Nov 2024 22:27:03 +0100 Subject: [PATCH 2/3] fix W600/W800 --- src/httpserver/http_fns.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 8605ce59f..eb31cb847 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1415,6 +1415,7 @@ int http_fn_cfg_wifi_set(http_request_t* request) { if (http_getArg(request->url, "pass2", tmpA, sizeof(tmpA))) { bChanged |= CFG_SetWiFiPass2(tmpA); } +#if ALLOW_SSID2 if (http_getArg(request->url, "startSSID", tmpA, sizeof(tmpA))) { int start_SSID = atoi(tmpA); addLogAdv(LOG_DEBUG, LOG_FEATURE_GENERAL, "start_SSID with value %i", start_SSID); @@ -1442,7 +1443,7 @@ int http_fn_cfg_wifi_set(http_request_t* request) { break; } } - +#endif #if ALLOW_WEB_PASSWORD if (http_getArg(request->url, "web_admin_password_enabled", tmpA, sizeof(tmpA))) { int web_password_enabled = atoi(tmpA); From 6b7f3c36a9cece8bd3466810bcc947a5e0cf48fc Mon Sep 17 00:00:00 2001 From: MaxineMuster Date: Sun, 1 Dec 2024 18:53:35 +0100 Subject: [PATCH 3/3] some changes to allow ony using one SSID --- src/httpserver/http_fns.c | 35 +++--------- src/new_pins.h | 25 ++++++--- src/user_main.c | 108 ++++++++++++++++++++++++++------------ 3 files changed, 99 insertions(+), 69 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index eb31cb847..f3c108c7e 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1324,14 +1324,17 @@ int http_fn_cfg_wifi(http_request_t* request) { #endif " enable clear text password (clears existing)"); #if PLATFORM_BEKEN - int fval = HAL_FlashVars_GetChannelValue(SSIDRetainChannel); + int fval = (HAL_FlashVars_GetChannelValue(SSIDRetainChannel)%1000)/100; poststr_h4(request, "Alternate WiFi (used when first one is not responding)"); // poststr_h2(request, "SSID2 only on Beken Platform (BK7231T, BK7231N)"); add_label_text_field(request, "SSID2", "ssid2", CFG_GetWiFiSSID2(), ""); add_label_password_field(request, "", "pass2", CFG_GetWiFiPass2(), "
Password2 enable clear text password (clears existing)"); - hprintf255(request, "

Select SSID used first: ",(fval==9991) ? "selected":"",(fval==990 || fval==991) ? "selected":""); + poststr(request, "

Select SSID used first: ",(fval==1) ? "selected":"",(fval==2 || fval==3) ? "selected":"",(fval==4) ? "selected":"",(fval==5) ? "selected":""); #endif #if ALLOW_WEB_PASSWORD int web_password_enabled = strcmp(CFG_GetWebPassword(), "") == 0 ? 0 : 1; @@ -1419,29 +1422,7 @@ int http_fn_cfg_wifi_set(http_request_t* request) { if (http_getArg(request->url, "startSSID", tmpA, sizeof(tmpA))) { int start_SSID = atoi(tmpA); addLogAdv(LOG_DEBUG, LOG_FEATURE_GENERAL, "start_SSID with value %i", start_SSID); - // start values: - // 0 --> SSID1 - // 1 --> SSID2 - // 2 --> remember last SSID - // channel values for this cases: - // SSID2 --> 9991 - // retain, actual SSID1 --> 990 - // retain, actual SSID2 --> 991 - // SSID1 --> all other values (e.g. 9990) - - // during enabling the feature, we need to set the "actual" SSID - switch (start_SSID) - { - case 0: - UpdateSSIDretainedIfChanged_StoredValue(9990); // start SSID1 - break; - case 1: - UpdateSSIDretainedIfChanged_StoredValue(9991); // start SSID2 - break; - case 2: - UpdateSSIDretainedIfChanged_StoredValue(990); // store actual SSID - break; - } + HandleSSIDretainedFromGUI(start_SSID); // handle in user_main.c - needs access to actual SSID used (g_SSIDactual) - defined "static" } #endif #if ALLOW_WEB_PASSWORD diff --git a/src/new_pins.h b/src/new_pins.h index 3285f0d16..659351132 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -1445,15 +1445,24 @@ void FV_UpdateStartupSSIDIfChanged_StoredValue(int assidindex); // which was the last used channel // the fixed starting SSID // -// we need two values: -// we use 999<0/1> as "magic numbers" for retain setting -// we use 9999<0/1> as "magic numbers" for "static" setting - -// retaining is set and SSID1 was last --> 990 -// retaining is set and SSID2 was last --> 991 -// retain is unset - start with SSID1 --> 9990 -// retain is unset - start with SSID2 --> 9991 +// possible values stored in retain channel (including possible future extension for counters/tries in values > 1000): +// +// 15 0 42 +// __ __ +// ^ ^ ^ +// | | | +// | | | +// | | ---- "magic number" 42 +// | | +// | ------- mode: 0/1 try both SSIDs, start with 0/1 +// | 2/3 try both SSIDs, start with 0/1, save last connected (SSID=val%2 2=0 3=1) +// | 4/5 only use SSID set, (SSID=val%4 4=0 5=1) +// | +// --------- possible extension, e.g # of tries before switching to next SSID (if both are used) +// +// SSID to use on startup is always mode-value%2 ! void UpdateSSIDretainedIfChanged_StoredValue(int val); // needs g_SSIDactual, so defined in user_main.c +void HandleSSIDretainedFromGUI(int val); // needs g_SSIDactual, so defined in user_main.c #endif #endif diff --git a/src/user_main.c b/src/user_main.c index 4c2c9951e..857296056 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -300,10 +300,10 @@ void LN882H_ApplyPowerSave(int bOn); // and doesn't matter if we start with SSID1 because it's default // of if SSID1 was the last one used ... -// retaining is set and SSID1 was last --> 990 -// retaining is set and SSID2 was last --> 991 +// retaining is set and SSID1 was last --> 242 +// retaining is set and SSID2 was last --> 342 // everything else: retain is unset -// only if there is a value 991, we need to use SSID2 (g_SSIDactual = 1) +// only if there is a value 342 or 142 or 542, we need to use SSID2 (g_SSIDactual = 1) // in all other cases use SSID1 (g_SSIDactual = 0) static int g_SSIDactual=0; @@ -312,27 +312,61 @@ static int g_SSIDactual=0; void UpdateSSIDretainedIfChanged_StoredValue(int val) { int fval = HAL_FlashVars_GetChannelValue(SSIDRetainChannel); addLogAdv(LOG_DEBUG, LOG_FEATURE_GENERAL, "UpdateSSIDretainedIfChanged_StoredValue value %i", val); - switch(val) - { - case 990: - val += g_SSIDactual; // 990 means "actual SSID" - break; - case 9990: // 990 means "use SSID1" - case 9991: // 990 means "use SSID2" - break; - default: - val = -9999; // unknown value - break; - } - if (val == -9999) return; + int valSSID=(val/100)%2; if (fval == val) { - addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "first startup SSID unchanged (SSID%i), HAL_FlashVars_SaveChannel skipped", val); + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "SSID unchanged (SSID%i), HAL_FlashVars_SaveChannel skipped", valSSID); return; //same value, no update } - addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "setting first startup SSID to SSID%i, HAL_FlashVars_SaveChannel skipped", val); + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "setting SSID to SSID%i", valSSID); HAL_FlashVars_SaveChannel(SSIDRetainChannel, val); } +void HandleSSIDretainedFromGUI(int val) { + // SSID retain results from GUI options + // 0 --> start with SSID1 + // 1 --> start with SSID2 + // 2 --> remember last SSID (will need to be combined wit actual SSID during setting) + // 4 --> only use SSID1 + // 5 --> only use SSID2 + int ret=val%10; // only 2 needs special treatment to store "actual" used SSID + if (val%10 == 2) ret += g_SSIDactual%2 ; // 2 means: start with "actual SSID" + if (ret >5) return; // unknown value + // in case we switched from "non-switching" to switching, change g_SSIDactual accordingly + if (ret < 4 && g_SSIDactual > 1 ) g_SSIDactual = g_SSIDactual%2 ; + // in case we switched from switching to "non-switching", change g_SSIDactual accordingly + if (ret >= 4 && g_SSIDactual < 4 ) g_SSIDactual = ret ; + + // maybe we later want to use values >10 for other purposes + // so we will readd them here later + // + // possible values stored in retain channel: + // + // 15 0 42 + // __ __ + // ^ ^ ^ + // | | | + // | | | + // | | ---- "magic number" 42 + // | | + // | ------- mode: 0/1 try both SSIDs, start with 0/1 + // | 2/3 try both SSIDs, start with 0/1, save last connected (SSID=val%2 2=0 3=1) + // | 4/5 only use SSID set, (SSID=val%4 4=0 5=1) + // | + // --------- possible extension, e.g # of tries before switching to next SSID (if both are used) + // + // SSID to use on startup is always mode-value%2 ! + + // handle higher values from above 1000 in channel = above 10 here (we will add magic value 42 in the last two decimal places) + int highval = 1000 * (val/10); // values e.g. for # of tries + if (! highval) highval = 1000*(HAL_FlashVars_GetChannelValue(SSIDRetainChannel)/1000); // no values? reuse actual values from flash + + ret *= 100; // push to third place + ret += 42; // add "magic" number + ret += highval; // restore or set higher values from above 1000 + + UpdateSSIDretainedIfChanged_StoredValue(ret); +} + static int g_SSIDSwitchAfterTry = 3;// switch to opposite SSID after static int g_SSIDSwitchCnt = 0; // switch counter #endif @@ -340,7 +374,7 @@ static int g_SSIDSwitchCnt = 0; // switch counter void CheckForSSID12_Switch() { #if ALLOW_SSID2 // nothing to do if SSID2 is unset - if (CFG_GetWiFiSSID2()[0] == 0) return; + if ( (CFG_GetWiFiSSID2()[0] == 0) || ( g_SSIDactual > 1) ) return; // g_SSIDactual > 1 : fix SSIDs, no switching 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; @@ -361,7 +395,7 @@ void Init_WiFiSSIDactual_FromChannelIfSet(void) { */ const char* CFG_GetWiFiSSIDX() { #if ALLOW_SSID2 - if (g_SSIDactual) { + if (g_SSIDactual%2) { return CFG_GetWiFiSSID2(); } else { @@ -374,7 +408,7 @@ const char* CFG_GetWiFiSSIDX() { const char* CFG_GetWiFiPassX() { #if ALLOW_SSID2 - if (g_SSIDactual) { + if (g_SSIDactual%2) { return CFG_GetWiFiPass2(); } else { @@ -430,22 +464,24 @@ void Main_OnWiFiStatusChange(int code) // retain is set and // value is different - // remember: actval == 990 if SSID1 is used --> g_SSIDactual = 0 - // actval == 991 if SSID2 is used --> g_SSIDactual = 1 + // remember: actval == X242 if SSID1 is used --> g_SSIDactual == 0 + // actval == X342 if SSID2 is used --> g_SSIDactual == 1 // we only need to store SSID value, if this is NOT the case, because g_SSIDactual doesn't match the retain value - // actval == 990 but g_SSIDactual == 1 --> we need to store 991 - // actval == 991 but g_SSIDactual == 0 --> we need to store 990 - // --> in both cases: actval + g_SSIDactual = 991 + // actval == X242 but g_SSIDactual == 1 --> we need to store X342 + // actval == X324 but g_SSIDactual == 0 --> we need to store X242 + // --> in both cases: actval + 100*g_SSIDactual = X342 // - // countercheck: in both other cases (if retained vale eaquals actual value): - // actval + g_SSIDactual is <> 991 ( it's 990 or 992) + // countercheck: in all other cases (if retained vale eaquals actual value or fixed values are given): + // actval + 100*g_SSIDactual is <> X342: + // values below 242: can be max 242 ( 142 + 100*1 ) <> 342 + // values above 342: can be min 442 ( 442 + 0 ) <> 342 // - // so testing for actval + g_SSIDactual == 991 is o.k. to test + // so testing for actval + 100*g_SSIDactual == X342 is o.k. to test // retain is set and value is different in one test !! - if ( !g_bHasWiFiConnected && ( (actval + g_SSIDactual ) == 991 ) ) - HAL_FlashVars_SaveChannel(SSIDRetainChannel, 990 + g_SSIDactual); + if ( !g_bHasWiFiConnected && ( (actval%1000 + 100*(g_SSIDactual%2) ) == 342 ) ) + HAL_FlashVars_SaveChannel(SSIDRetainChannel, 42 + 100*((g_SSIDactual%2)+2) + 1000*(actval/1000)); #endif g_bHasWiFiConnected = 1; #if ALLOW_SSID2 @@ -1423,9 +1459,13 @@ void Main_Init_After_Delay() } #if ALLOW_SSID2 // Init_WiFiSSIDactual_FromChannelIfSet();//Channel must be set in early.bat using CMD_setStartupSSIDChannel - int ssidret=HAL_FlashVars_GetChannelValue(SSIDRetainChannel) ; - g_SSIDactual = ( (ssidret == 991) || (ssidret == 9991) ); // 0=SSID1 1=SSID2 - ADDLOGF_INFO("setting g_SSIDactual to %i (CH7 val=%i)", g_SSIDactual , HAL_FlashVars_GetChannelValue(SSIDRetainChannel) ); + int ssidret= HAL_FlashVars_GetChannelValue(SSIDRetainChannel) ; + if (ssidret %100 == 42) + { + g_SSIDactual = ( (ssidret %1000) / 100) % 2 ; // check magic value and set SSID: 0=SSID1 1=SSID2 + if ( ((ssidret %1000) / 100) >= 4 ) g_SSIDactual += 4; // set to 4 for "fix" SSID1 and 5 for "fix" SSID2 (no switching) + ADDLOGF_INFO("setting g_SSIDactual to %i (CH7 val=%i)", g_SSIDactual , ssidret ); + } else ADDLOGF_INFO("g_SSIDactual (%i) unchanged - wrong magic number (CH7 val=%i)", g_SSIDactual , ssidret ); #endif wifi_ssid = CFG_GetWiFiSSIDX(); wifi_pass = CFG_GetWiFiPassX();