From 3610831582301695793e52efd448ab5593d3468a Mon Sep 17 00:00:00 2001 From: xjikka Date: Mon, 25 Nov 2024 11:23:41 +0100 Subject: [PATCH 1/9] SSID2 add retain SSID on reboot using setLastSSIDChannel command in early.bat --- src/httpserver/http_fns.c | 3 ++- src/new_pins.c | 41 +++++++++++++++++++++++++++++++++++++++ src/new_pins.h | 5 +++++ src/user_main.c | 22 +++++++++++++++++---- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 8bb48e1b6..43694f315 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1317,7 +1317,8 @@ int http_fn_cfg_wifi(http_request_t* request) { 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)"); #ifndef PLATFORM_BEKEN - poststr_h2(request, "SSID2 only on Beken Platform (BK7231T, BK7231N)"); + poststr_h2(request, "SSID2 only on Beken Platform (BK7231T, BK7231N)."); + poststr(request, "Note: It is possible to retain last connected SSID in channel using command setLastSSIDChannel in early.bat"); #endif add_label_text_field(request, "SSID2", "ssid2", CFG_GetWiFiSSID2(), ""); add_label_password_field(request, "", "pass2", CFG_GetWiFiPass2(), "
Password2 enable clear text password (clears existing)"); diff --git a/src/new_pins.c b/src/new_pins.c index e9b246ed6..db8a2587c 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -38,6 +38,23 @@ int BTN_HOLD_REPEAT_MS; byte *g_defaultWakeEdge = 0; int g_initialPinStates = 0; +#if ALLOW_SSID2 +int g_LastSSIDRetainChannel = -1; // -1 disabled, 0..MAX_RETAIN_CHANNELS-1 channel to store last SSID + +int FV_GetLastSSID_StoredValue(int adefault) { + if ((g_LastSSIDRetainChannel < 0) || (g_LastSSIDRetainChannel >= MAX_RETAIN_CHANNELS)) return adefault; + int fval = HAL_FlashVars_GetChannelValue(g_LastSSIDRetainChannel); + return (fval & 1); ////only SSID1 (0) and SSID2 (1) allowed +} +void FV_UpdateLastSSIDIfChanged_StoredValue(int assidindex) { + if ((g_LastSSIDRetainChannel < 0) || (g_LastSSIDRetainChannel >= MAX_RETAIN_CHANNELS)) return; + if ((assidindex < 0) && (assidindex > 1)) return; //only SSID1 (0) and SSID2 (1) allowed + int fval = HAL_FlashVars_GetChannelValue(g_LastSSIDRetainChannel); + if (fval == g_LastSSIDRetainChannel) return; //same value, no update + HAL_FlashVars_SaveChannel(g_LastSSIDRetainChannel,assidindex); +} +#endif + void PIN_DeepSleep_MakeSureEdgesAreAlloced() { int i; if (g_defaultWakeEdge == 0) { @@ -2172,7 +2189,26 @@ static commandResult_t CMD_SetChannelType(const void* context, const char* cmd, addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "Channel %i type changed to %s", channel, type); return CMD_RES_OK; } +// setLastSSIDChannel [-1 or RetainChannelIndex] +static commandResult_t CMD_setLastSSIDChannel(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)) { + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "LastSSIDChannel value error: %i Allowed values (-1, 0..%i)", fval, MAX_RETAIN_CHANNELS - 1); + return CMD_RES_BAD_ARGUMENT; + } + g_LastSSIDRetainChannel = fval; + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "LastSSIDChannel changed to %i", g_LastSSIDRetainChannel); + } + else { + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "LastSSIDChannel is %i", g_LastSSIDRetainChannel); + } + return CMD_RES_OK; +} /// @brief Computes the Relay and PWM count. /// @param relayCount Number of relay and LED channels. /// @param pwmCount Number of PWM channels. @@ -2334,5 +2370,10 @@ void PIN_AddCommands(void) //cmddetail:"fn":"CMD_setButtonHoldRepeat","file":"new_pins.c","requires":"", //cmddetail:"examples":""} CMD_RegisterCommand("setButtonHoldRepeat", CMD_setButtonHoldRepeat, NULL); + //cmddetail:{"name":"setLastSSIDChannel","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). Last four a", + //cmddetail:"fn":"CMD_setButtonHoldRepeat","file":"new_pins.c","requires":"", + //cmddetail:"examples":""} + CMD_RegisterCommand("setLastSSIDChannel", CMD_setLastSSIDChannel, NULL); } diff --git a/src/new_pins.h b/src/new_pins.h index 574c85e57..87083df03 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -1434,4 +1434,9 @@ int PIN_IOR_NofChan(int test); extern const char* g_channelTypeNames[]; +#if ALLOW_SSID2 +int FV_GetLastSSID_StoredValue(int adefault); +void FV_UpdateLastSSIDIfChanged_StoredValue(int assidindex); +#endif + #endif diff --git a/src/user_main.c b/src/user_main.c index 5ff2987ad..666d6b078 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -289,7 +289,9 @@ void LN882H_ApplyPowerSave(int bOn); // SSID switcher by xjikka 20240525 #if ALLOW_SSID2 -static int g_SSIDactual = 0; // 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 static int g_SSIDSwitchAfterTry = 3;// switch to opposite SSID after static int g_SSIDSwitchCnt = 0; // switch counter #endif @@ -308,6 +310,13 @@ void CheckForSSID12_Switch() { #endif } +//20241125 XJIKKA Init last stored SSID from RetailChannel if set +//Note that it must be set in early.bat using CMD_setLastSSIDChannel +void Init_WiFiSSIDactual_FromChannelIfSet(void) { +#if ALLOW_SSID2 + g_SSIDactual = FV_TryGetLastSSID_StoredValue(SSID_USE_SSID1); +#endif +} const char* CFG_GetWiFiSSIDX() { #if ALLOW_SSID2 if (g_SSIDactual) { @@ -370,6 +379,9 @@ 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_UpdateLastSSIDIfChanged_StoredValue(g_SSIDactual); //update ony on first connect +#endif g_bHasWiFiConnected = 1; #if ALLOW_SSID2 g_SSIDSwitchCnt = 0; @@ -1343,9 +1355,11 @@ void Main_Init_After_Delay() if (bSafeMode) { ADDLOGF_INFO("###### safe mode activated - boot failures %d", g_bootFailures); } - - wifi_ssid = CFG_GetWiFiSSID(); - wifi_pass = CFG_GetWiFiPass(); +#if ALLOW_SSID2 + Init_WiFiSSIDactual_FromChannelIfSet();//Channel must be set in early.bat using CMD_setLastSSIDChannel +#endif + wifi_ssid = CFG_GetWiFiSSIDX(); + wifi_pass = CFG_GetWiFiPassX(); #if 0 // you can use this if you bricked your module by setting wrong access point data From 1d84fe2eec5e290cd565a72fa7da4ea402bdb54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kostiha?= Date: Mon, 25 Nov 2024 18:32:42 +0100 Subject: [PATCH 2/9] func name --- src/user_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user_main.c b/src/user_main.c index 666d6b078..217d15006 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -314,7 +314,7 @@ void CheckForSSID12_Switch() { //Note that it must be set in early.bat using CMD_setLastSSIDChannel void Init_WiFiSSIDactual_FromChannelIfSet(void) { #if ALLOW_SSID2 - g_SSIDactual = FV_TryGetLastSSID_StoredValue(SSID_USE_SSID1); + g_SSIDactual = FV_GetLastSSID_StoredValue(SSID_USE_SSID1); #endif } const char* CFG_GetWiFiSSIDX() { From d9ae84d4945d6a52c462204bb00b236b3370335e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kostiha?= Date: Mon, 25 Nov 2024 19:10:19 +0100 Subject: [PATCH 3/9] save repair --- src/new_pins.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/new_pins.c b/src/new_pins.c index db8a2587c..8821ecbe8 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -50,7 +50,10 @@ void FV_UpdateLastSSIDIfChanged_StoredValue(int assidindex) { if ((g_LastSSIDRetainChannel < 0) || (g_LastSSIDRetainChannel >= MAX_RETAIN_CHANNELS)) return; if ((assidindex < 0) && (assidindex > 1)) return; //only SSID1 (0) and SSID2 (1) allowed int fval = HAL_FlashVars_GetChannelValue(g_LastSSIDRetainChannel); - if (fval == g_LastSSIDRetainChannel) return; //same value, no update + if (fval == assidindex) { + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "WiFi unchanged (SSID%i), HAL_FlashVars_SaveChannel skipped", assidindex+1); + return; //same value, no update + } HAL_FlashVars_SaveChannel(g_LastSSIDRetainChannel,assidindex); } #endif From b0e2a877b5af59fc3a3d71f9aa755b29c5193f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kostiha?= Date: Mon, 25 Nov 2024 19:41:01 +0100 Subject: [PATCH 4/9] Cmd StartupSSID --- src/httpserver/http_fns.c | 2 +- src/new_pins.c | 65 +++++++++++++++++++++++++++------------ src/new_pins.h | 4 +-- src/user_main.c | 8 ++--- 4 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 43694f315..4088cf3ad 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1316,9 +1316,9 @@ int http_fn_cfg_wifi(http_request_t* request) { 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 connected SSID in channel using command setStartupSSIDChannel in early.bat"); #ifndef PLATFORM_BEKEN poststr_h2(request, "SSID2 only on Beken Platform (BK7231T, BK7231N)."); - poststr(request, "Note: It is possible to retain last connected SSID in channel using command setLastSSIDChannel in early.bat"); #endif add_label_text_field(request, "SSID2", "ssid2", CFG_GetWiFiSSID2(), ""); add_label_password_field(request, "", "pass2", CFG_GetWiFiPass2(), "
Password2 enable clear text password (clears existing)"); diff --git a/src/new_pins.c b/src/new_pins.c index 8821ecbe8..2cd6af521 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -39,22 +39,22 @@ byte *g_defaultWakeEdge = 0; int g_initialPinStates = 0; #if ALLOW_SSID2 -int g_LastSSIDRetainChannel = -1; // -1 disabled, 0..MAX_RETAIN_CHANNELS-1 channel to store last SSID +int g_StartupSSIDRetainChannel = -1; // -1 disabled, 0..MAX_RETAIN_CHANNELS-1 channel to store last SSID -int FV_GetLastSSID_StoredValue(int adefault) { - if ((g_LastSSIDRetainChannel < 0) || (g_LastSSIDRetainChannel >= MAX_RETAIN_CHANNELS)) return adefault; - int fval = HAL_FlashVars_GetChannelValue(g_LastSSIDRetainChannel); +int FV_GetStartupSSID_StoredValue(int adefault) { + if ((g_StartupSSIDRetainChannel < 0) || (g_StartupSSIDRetainChannel >= MAX_RETAIN_CHANNELS)) return adefault; + int fval = HAL_FlashVars_GetChannelValue(g_StartupSSIDRetainChannel); return (fval & 1); ////only SSID1 (0) and SSID2 (1) allowed } -void FV_UpdateLastSSIDIfChanged_StoredValue(int assidindex) { - if ((g_LastSSIDRetainChannel < 0) || (g_LastSSIDRetainChannel >= MAX_RETAIN_CHANNELS)) return; +void FV_UpdateStartupSSIDIfChanged_StoredValue(int assidindex) { + if ((g_StartupSSIDRetainChannel < 0) || (g_StartupSSIDRetainChannel >= MAX_RETAIN_CHANNELS)) return; if ((assidindex < 0) && (assidindex > 1)) return; //only SSID1 (0) and SSID2 (1) allowed - int fval = HAL_FlashVars_GetChannelValue(g_LastSSIDRetainChannel); + int fval = HAL_FlashVars_GetChannelValue(g_StartupSSIDRetainChannel); if (fval == assidindex) { addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "WiFi unchanged (SSID%i), HAL_FlashVars_SaveChannel skipped", assidindex+1); return; //same value, no update } - HAL_FlashVars_SaveChannel(g_LastSSIDRetainChannel,assidindex); + HAL_FlashVars_SaveChannel(g_StartupSSIDRetainChannel,assidindex); } #endif @@ -2192,24 +2192,47 @@ static commandResult_t CMD_SetChannelType(const void* context, const char* cmd, addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "Channel %i type changed to %s", channel, type); return CMD_RES_OK; } -// setLastSSIDChannel [-1 or RetainChannelIndex] -static commandResult_t CMD_setLastSSIDChannel(const void* context, const char* cmd, const char* args, int cmdFlags) { +// 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)) { - addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "LastSSIDChannel value error: %i Allowed values (-1, 0..%i)", fval, MAX_RETAIN_CHANNELS - 1); + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSIDChannel value error: %i Allowed values (-1, 0..%i)", fval, MAX_RETAIN_CHANNELS - 1); return CMD_RES_BAD_ARGUMENT; } - g_LastSSIDRetainChannel = fval; - addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "LastSSIDChannel changed to %i", g_LastSSIDRetainChannel); + g_StartupSSIDRetainChannel = fval; + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSIDChannel changed to %i", g_StartupSSIDRetainChannel); } else { - addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "LastSSIDChannel is %i", g_LastSSIDRetainChannel); + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSIDChannel is %i", g_StartupSSIDRetainChannel); } + return CMD_RES_OK; +} +// setStartupSSID [0/1] +// Sets startup SSID - 0=SSID1 1=SSID2 - which SSID will be used after reboot, 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); + int fold = FV_GetStartupSSID_StoredValue(0); + if (Tokenizer_GetArgsCount() >= 1) { + int fval = Tokenizer_GetArgInteger(0); + if ((fval < 0) || (fval >1)) { + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSID value error: %i Allowed values (0, 1)", fval); + return CMD_RES_BAD_ARGUMENT; + } + if (g_StartupSSIDRetainChannel<0) { + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "Cannot set setStartupSSID, StartupSSIDChannel not set. Use setStartupSSIDChannel first"); + return CMD_RES_BAD_ARGUMENT; + } + if (!(fval==fold)) FV_UpdateStartupSSIDIfChanged_StoredValue(fval); //update ony on change + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSID changed to %i", fval); + } else { + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSID is %i", fold); + } return CMD_RES_OK; } /// @brief Computes the Relay and PWM count. @@ -2373,10 +2396,14 @@ void PIN_AddCommands(void) //cmddetail:"fn":"CMD_setButtonHoldRepeat","file":"new_pins.c","requires":"", //cmddetail:"examples":""} CMD_RegisterCommand("setButtonHoldRepeat", CMD_setButtonHoldRepeat, NULL); - //cmddetail:{"name":"setLastSSIDChannel","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). Last four a", - //cmddetail:"fn":"CMD_setButtonHoldRepeat","file":"new_pins.c","requires":"", + //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)", + //cmddetail:"fn":"CMD_setStartupSSIDChannel","file":"new_pins.c","requires":"", //cmddetail:"examples":""} - CMD_RegisterCommand("setLastSSIDChannel", CMD_setLastSSIDChannel, NULL); - + CMD_RegisterCommand("setStartupSSIDChannel", CMD_setStartupSSIDChannel, NULL); + //cmddetail:{"name":"setStartupSSID","args":"[Value]", + //cmddetail:"descr":"Sets startup SSID, 0 (SSID0) 1 (SSID1)", + //cmddetail:"fn":"CMD_setStartupSSID","file":"new_pins.c","requires":"", + //cmddetail:"examples":""} + CMD_RegisterCommand("setStartupSSID", CMD_setStartupSSID, NULL); } diff --git a/src/new_pins.h b/src/new_pins.h index 87083df03..1bd8cbcb2 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -1435,8 +1435,8 @@ int PIN_IOR_NofChan(int test); extern const char* g_channelTypeNames[]; #if ALLOW_SSID2 -int FV_GetLastSSID_StoredValue(int adefault); -void FV_UpdateLastSSIDIfChanged_StoredValue(int assidindex); +int FV_GetStartupSSID_StoredValue(int adefault); +void FV_UpdateStartupSSIDIfChanged_StoredValue(int assidindex); #endif #endif diff --git a/src/user_main.c b/src/user_main.c index 217d15006..0c58ef100 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -311,10 +311,10 @@ void CheckForSSID12_Switch() { } //20241125 XJIKKA Init last stored SSID from RetailChannel if set -//Note that it must be set in early.bat using CMD_setLastSSIDChannel +//Note that it must be set in early.bat using CMD_setStartupSSIDChannel void Init_WiFiSSIDactual_FromChannelIfSet(void) { #if ALLOW_SSID2 - g_SSIDactual = FV_GetLastSSID_StoredValue(SSID_USE_SSID1); + g_SSIDactual = FV_GetStartupSSID_StoredValue(SSID_USE_SSID1); #endif } const char* CFG_GetWiFiSSIDX() { @@ -380,7 +380,7 @@ void Main_OnWiFiStatusChange(int code) break; case WIFI_STA_CONNECTED: #if ALLOW_SSID2 - if (!g_bHasWiFiConnected) FV_UpdateLastSSIDIfChanged_StoredValue(g_SSIDactual); //update ony on first connect + if (!g_bHasWiFiConnected) FV_UpdateStartupSSIDIfChanged_StoredValue(g_SSIDactual); //update ony on first connect #endif g_bHasWiFiConnected = 1; #if ALLOW_SSID2 @@ -1356,7 +1356,7 @@ 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_setLastSSIDChannel + Init_WiFiSSIDactual_FromChannelIfSet();//Channel must be set in early.bat using CMD_setStartupSSIDChannel #endif wifi_ssid = CFG_GetWiFiSSIDX(); wifi_pass = CFG_GetWiFiPassX(); From 65503127b55af25103d27728558ae948e8f05c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kostiha?= Date: Mon, 25 Nov 2024 19:42:19 +0100 Subject: [PATCH 5/9] save repair 2 --- src/httpserver/http_fns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 4088cf3ad..381035f46 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1318,7 +1318,7 @@ int http_fn_cfg_wifi(http_request_t* request) { poststr_h2(request, "Alternate WiFi (used when first one is not responding)"); poststr(request, "Note: It is possible to retain connected SSID in channel using command setStartupSSIDChannel in early.bat"); #ifndef PLATFORM_BEKEN - poststr_h2(request, "SSID2 only on Beken Platform (BK7231T, BK7231N)."); + 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(), "
Password2 enable clear text password (clears existing)"); From 0af441ee215ef46d0ddad57628a3b5defc5ad5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kostiha?= Date: Mon, 25 Nov 2024 19:56:02 +0100 Subject: [PATCH 6/9] cmd text --- src/new_pins.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/new_pins.c b/src/new_pins.c index 2cd6af521..fc975b11e 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -2228,8 +2228,12 @@ static commandResult_t CMD_setStartupSSID(const void* context, const char* cmd, addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "Cannot set setStartupSSID, StartupSSIDChannel not set. Use setStartupSSIDChannel first"); return CMD_RES_BAD_ARGUMENT; } - if (!(fval==fold)) FV_UpdateStartupSSIDIfChanged_StoredValue(fval); //update ony on change - addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSID changed to %i", fval); + if (!(fval==fold)) { + FV_UpdateStartupSSIDIfChanged_StoredValue(fval); //update ony on change + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSID changed to %i", fval); + } else { + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSID unchanged %i", fval); + } } else { addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSID is %i", fold); } From e11cc672c457642aa807efb3e657aa0334a1a286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kostiha?= Date: Mon, 25 Nov 2024 20:02:59 +0100 Subject: [PATCH 7/9] . --- src/httpserver/http_fns.c | 2 +- src/new_pins.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 381035f46..7285ebad6 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1316,7 +1316,7 @@ int http_fn_cfg_wifi(http_request_t* request) { 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 connected SSID in channel using command setStartupSSIDChannel in early.bat"); + 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)"); #endif diff --git a/src/new_pins.c b/src/new_pins.c index fc975b11e..63c70591b 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -2212,7 +2212,8 @@ static commandResult_t CMD_setStartupSSIDChannel(const void* context, const char return CMD_RES_OK; } // setStartupSSID [0/1] -// Sets startup SSID - 0=SSID1 1=SSID2 - which SSID will be used after reboot, setStartupSSIDChannel and SSID2 must be set +// 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); @@ -2225,11 +2226,11 @@ static commandResult_t CMD_setStartupSSID(const void* context, const char* cmd, return CMD_RES_BAD_ARGUMENT; } if (g_StartupSSIDRetainChannel<0) { - addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "Cannot set setStartupSSID, StartupSSIDChannel not set. Use setStartupSSIDChannel first"); + addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "Cannot set StartupSSID, StartupSSIDChannel is not set."); return CMD_RES_BAD_ARGUMENT; } if (!(fval==fold)) { - FV_UpdateStartupSSIDIfChanged_StoredValue(fval); //update ony on change + FV_UpdateStartupSSIDIfChanged_StoredValue(fval);//update flash only when changed addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSID changed to %i", fval); } else { addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "StartupSSID unchanged %i", fval); From 8cc456c5f03eebad7caff7aad5c77861ddefbc30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kostiha?= Date: Mon, 25 Nov 2024 20:47:17 +0100 Subject: [PATCH 8/9] . --- src/new_pins.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/new_pins.c b/src/new_pins.c index 63c70591b..9881a2d65 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -39,6 +39,10 @@ byte *g_defaultWakeEdge = 0; int g_initialPinStates = 0; #if ALLOW_SSID2 +//20241125 XJIKKA SSID retain - last used SSID will be preserved +// 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) { From 233c40885326b9453d4511f844884789d0a3b35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kostiha?= Date: Mon, 25 Nov 2024 22:01:35 +0100 Subject: [PATCH 9/9] Cmd disable on platforms without SSID2 --- src/new_pins.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/new_pins.c b/src/new_pins.c index 9881a2d65..4c0411a90 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -2196,6 +2196,7 @@ static commandResult_t CMD_SetChannelType(const void* context, const char* cmd, addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "Channel %i type changed to %s", channel, type); 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) { @@ -2244,6 +2245,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. /// @param pwmCount Number of PWM channels. @@ -2405,6 +2407,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)", //cmddetail:"fn":"CMD_setStartupSSIDChannel","file":"new_pins.c","requires":"", @@ -2415,4 +2418,5 @@ void PIN_AddCommands(void) //cmddetail:"fn":"CMD_setStartupSSID","file":"new_pins.c","requires":"", //cmddetail:"examples":""} CMD_RegisterCommand("setStartupSSID", CMD_setStartupSSID, NULL); +#endif }