openshwprojects / OpenBK7231T_App

Open source firmware (Tasmota/Esphome replacement) for BK7231T, BK7231N, BL2028N, T34, XR809, W800/W801, W600/W601 and BL602
https://openbekeniot.github.io/webapp/devicesList.html
1.33k stars 226 forks source link

SSID2 autoswitch mod #1254

Closed xjikka closed 1 week ago

xjikka commented 4 weeks ago

How does it work: It tries g_SSIDSwitchAfterTry times to connect to the SSID and if it fails it switches to SSID2 (if set) and so on after 3 more failed attempts back to SSID and so on.

Discussed here: https://github.com/openshwprojects/OpenBK7231T_App/issues/1246

openshwprojects commented 4 weeks ago

I think this should be enabled by default. Is ALLOW_SSID2 enabled in this PR?

@divadiow , would you be able to test that? I have just a single router...

xjikka commented 4 weeks ago

ALLOW_SSID2 id disabled for W800 and W600 in the new_pins.h for the other platforms is enabled.

new_pins.h: ...

if PLATFORM_W600 || PLATFORM_W800

define ALLOW_SSID2 0

define ALLOW_WEB_PASSWORD 0

char initCommandLine[512];

else

define ALLOW_SSID2 1

define ALLOW_WEB_PASSWORD 1

...

xjikka commented 4 weeks ago

The change regarding SSID2 is only functional if SSID2 is set. However, MaxineMuster's WiFi initialization change https://github.com/openshwprojects/OpenBK7231T_App/issues/1246#issuecomment-2133126343 and here https://github.com/openshwprojects/OpenBK7231T_App/issues/1246#issuecomment-2133430372 (part of ssid2mod for LN882H) would be good to try on other platforms as well. There is no feedback yet. I've checked it (intensively) only on the BK7231N platform.

divadiow commented 3 weeks ago

Hi. I'm away but will be back tomorrow evening and will test then or Monday

divadiow commented 3 weeks ago

OK. With 1254_merge_689545a11ddf

Two SSIDs setup on same router, OBK1 and OBK2. Same security profile so identical pw and encryption types. Password was super simple with no special characters.

From downing of SSID1 (no power cycle): BK-T took ~ 5 mins to connect to OBK2 BK-N, BL, LN didn't connect to OBK2 (waited 20 mins)

From power-on with SSID1 down: BK-N & T took ~3mins 45s to connect to OBK2 LN882H took ~6 minutes to connect to OBK2 BL602 did not connect (waited 20 minutes). (BL602 did reconnect quickly to OBK1 when that was re-broadcasting)

From downing of SSID2 (with N, T &LN connected) and reinstatement of SSID1 (no power cycle): BK-N & T connected to OBK1 after a few minutes (lost track - 3-6 mins?) LN882H did not connect to OBK1 (waited 20 mins)

MaxineMuster commented 3 weeks ago

To speed up the times I would suggest to lower the seconds to wait inside Main_OnWiFiStatusChange() (g_connectToWiFi is used as a timer here). Especially 120 seconds for WIFI_STA_CONNECTING is very long. For testing setting all to 10 or 15 seconds would help I think.

In the end it will only work, if the function is called on every change...

divadiow commented 3 weeks ago

From downing of SSID1 (no power cycle): BK-T took ~ 5 mins to connect to OBK2 BK-N, BL, LN didn't connect to OBK2 (waited 20 mins)

I'm going to rerun this now

divadiow commented 3 weeks ago

From downing of SSID1 with all connected (no power cycle):

BK-T - 4 min 48s to connect to OBK2 BK-N - no connection after 20 mins LN882H - " BL602 - "

xjikka commented 3 weeks ago

BK7231N - I'm using it and it switches to SSID2 in both cases on my router (both SSIDs are simple SSID + simple password) bk7231n-no-SSID1-on-poweron.log - SSID1 not available at power on bk7231n-SSID1-on-poweron-disabled-after-connect.log - SSID1 available at power on, in short time later disabled bk7231n-no-SSID1-on-poweron.log bk7231n-SSID1-on-poweron-disabled-after-connect.log

In both cases is SSID2 Connected on BK7231N

From power-on with SSID1 down: Info:MAIN:Time 216, idle 155200/s, free 74600, MQTT 0(0), bWifi 1,

From downing of SSID1 (no power cycle): Info:MAIN:Time 271, idle 149022/s, free 74632, MQTT 0(2), bWifi 1,

xjikka commented 3 weeks ago

I'll try to recompile it and I'll check again on the BK7231N

divadiow commented 3 weeks ago

I'll redo N flash, factory reset and test again in the morning. I was expecting N to behave like T and your experience with N so hopefully just a crappy test from me.

divadiow commented 3 weeks ago

OK. BK-N test started again. 3x N devices factory reset and flashed with 1254_merge_689545a11ddf. no powersave, no startup commands, no autoexec.

all 3 connected to SSID2 after ~4 minutes after SSID1 was downed. then all 3 connected back to SSID1 after SSID2 downed and SSID1 reinstated, again after 4-4 min 30s

xjikka commented 3 weeks ago

Thanks for the info. I also re-compiled the App again, tested it again on the BK7231N with the same result (switching SSID 1 and 2 in both scenarios). As a bonus, I tested it using hidden SSIDs and it works as expected.

divadiow commented 3 weeks ago

cool, so I think in summary it feels like BK-N/T is good but the rest need more work/testing?

xjikka commented 3 weeks ago

I have no other devices available, only BK-T and BK-N. So I suggest to modify the definition so that SSID2 is offered (in the webconfig) only for Beken so:

#ifdef PLATFORM_BEKEN
#define ALLOW_SSID2 1
#else
#define ALLOW_SSID2 0
#endif
#if PLATFORM_W600 || PLATFORM_W800
#define ALLOW_WEB_PASSWORD 0
char initCommandLine[512];
#else
#define ALLOW_WEB_PASSWORD 1
...
MaxineMuster commented 3 weeks ago

I'm not at home at the moment, so I can't check the logs, what e.g. LN882H will do when WiFi is down. It works if connection isn't possible due to SSID or password mismatch. I didn't test a "vanishing" SSID yet.

As I said, it only works, when Main_OnWiFiStatusChange() is called in these cases (or we would need another mechanism to set g_connectToWiFi to a value > 0).

[edit]But I think it would be o.k. to start with Beken devices and try to fix this for others later[/edit]

divadiow commented 3 weeks ago

lmk if/when you want me to redo LN test on multiple reset devices to confirm current state on LN

xjikka commented 3 weeks ago

I have added/changed src/new_pins.h

#ifdef PLATFORM_BEKEN
#define ALLOW_SSID2 1
#else
#define ALLOW_SSID2 0
#endif
openshwprojects commented 3 weeks ago

@xjikka please double check if you are not changing config layout on non-Beken platform, if you hide SSID data from config, you will break configs on those platforms. So take care, do not change #ifdef in the config struct

xjikka commented 3 weeks ago

@xjikka please double check if you are not changing config layout on non-Beken platform, if you hide SSID data from config, you will break configs on those platforms. So take care, do not change #ifdef in the config struct

As I was going through the source code I know that CFG_SetWiFiSSID2() and CFG_GetWiFiPass2() haven't been used anywhere so far. But you're right that someone could theoretically have passwords/SSIDs stored there in thede fields SSID2 as a backup even when not in use. Storing via wifi_pass2 and wifi_ssid2 will be preserved, however it won't be editable. This has to be decided by someone else. The other option is to edit the text for SSID2 in WebInterface to make it clear that it only works on BEKEN

openshwprojects commented 1 week ago

I think you can easily add #ifdef conditional for PLATFORM_BEKEN to add some extra HTML text on the page. Please try, will it be then ready to merge?