-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[test] WiFi periodic scanning #2088
Conversation
@xoseperez Unless you had some other ideas about scanning approach... JustWifi is also refactored quite a bit, but mostly in regards to internal flow. |
Are there any plans to get this merged or does it require more testing? I had a situation the other day after a power cut. The devices connected to the first AP they found with the same SSID but not the strongest. I had to do a manual re-connect per device so it then connected to the strongest SSID. |
Not in a way it is written here. I'll need to update the logic a bit. As mentioned in the original topic, I did add RPN ops as sort-of workaround:
i.e. every 30 seconds check current RSSI and disconnect when it's less than -60. But, it does not take into an account the surrounding networks (or if there are any at all) |
I'll add RPN to some builds at some point and see if the problem devices are more stable. I know I can send a reboot command via MQTT, but is there a reconnect command? I know the device has to have a working WiFi connection to receive it, but I can monitor the RSSI level in openHab and maybe then send a reconnect command if too low. |
There is one via
I'll need to update the basic edit: however, it will leak memory when doing the wifi reset. hm... |
:oops: I misread the MQTT part as HTTP. There is |
I have tried a device using the above rule but the wifi disconnects every 30 seconds regardless of RSSI level. The device currently has a value of around -56. Does the rule need some additional code or an 'IF' statement? |
Yes, missing piece is There is no real |
With rssi around -56, the following still disconnects which I think is wrong. The following stops the disconnect. I believe this should equate to if Am I understanding the RPN implementation correctly? |
Restarting the wifi near that device I believe triggers the rule, but the device seemed to do a restart with the following exception:
|
Yes, where stack No exception here. Can you check how it decodes the crash dump? |
Could you point me towards what I need to do :)
|
|
Yep
|
Decoding script should tell what those addresses mean. Given that you saved the build directory, there should still be .elf file alongside the .bin, addresses are not constant and depend on the build config |
firmware.zip Can this be viewed in a standard text editor or does it require specific software? I can open it in Notepad++ but can't find any of the addresses in the file listed above. |
See bug-report.md link, it is explaining the decoder.
Can you also try adding |
I can see the details now for the decoder when looking on a normal screen, I could only see the left hand side of the page on my phone.
|
Can you also share the rules list? I'd guess there's mqtt_send somewhere that get's caught by surprise |
There aren't any other rules defined on this device. |
FYI, the WiFi AP was offline for at least 30 minutes this morning. The device running the rule had gone into ESPURNA AP mode. A power cycle made the device reconnect back to the previously known AP. If I'd left it longer, would the device try and reconnect to the known AP or, would it stay in the ESPURNA AP mode until rebooted? |
It should scan ~3 minutes espurna/code/espurna/config/general.h Line 544 in 47538b9
|
edit: closing as out-of-date So I've been looking at wifi stuff yet again, and I think I want to get rid of justwifi part altogether (or at least until I can figure out what would be a nicer library API). Obviously, it should also be better than the RPN script, since it would have access to the BSSID info as well and won't reconnect to the same poor AP Question remains though, what exactly is the reconnect policy should be:
And RSSI should probably be an average and not just plain comparison |
Or, some parameter for connection where it won't allow RSSI less than a certain value |
A quick test of two of my devices. They are both connected without any issues for over 30 days. Ones RSSI was -80 and the other -81. Clicking the Obviously, depending on the location of a device WRT the known/configured APs, an arbitrary figure to force reconnect may not be the best option. I'd have thought that if the device could scan periodically (10 or 30 mins say), get RSSI values for configured APs and compare. If there is a stronger signal, run the reconnect code. I'm not sure what happens if the stronger AP doesn't have access to the router? Say if the WiFi of the AP is working but can't communicate for some reason? |
re. just above, I meant why solve the reconnection problem when we can just ignore bad APs and wait for a good one 🤔 comms are a whole other question here. we do check if there's an IP, but none of the network services are actually required to work for the connection to be considered ok |
Like you talked about above, I'm not sure at what RSSI value should be considered poor. My device that was on -80 to -70 is communicating fine although the webUI can become unresponsive at times. Maybe a trigger of <-60 it should try and reconnect. Could there be a problem if the device, due to distance, is always around -70? Wouldn't it constantly try reconnecting even though it's never going to get a stronger signal? Re: comms. For ease of management I run my 30ish devices using static IPs. That way I know which IP to use to get to a specific device. My router doesn't have enough static IP associations capacity for too many. |
I don't know what thresholds a mobile phone would use to auto scan for stronger configured WiFi networks? |
There's a very lengthy description of what android does - https://source.android.com/devices/tech/connect/wifi-network-selection?hl=en It would do the loop, true... Maybe it could give up in a cycle or two, and then run the scan check while connected (i.e. do what justwifi thing here did). |
I scrapped the threshold idea for the initial connection itself, which seems like an overkill for a semi-stable connection. It will be dropped if the device will drop too much traffic, so another scan will happen that way at some point. Also about static IPs and comms. In theory, there could be a check for 'essential' services like MQTT or something else and it could drop the connection when those are not available. But, it feels like it would add a lot of saved state and idk if it is really that useful |
See dev espurna/code/espurna/config/general.h Lines 604 to 619 in cb23c94
is the gist of it. It will connect to first available network. It will poll RSSI value every ~1minute, after 3rd time it is bad - it will switch into scanning mode and try to find something better, ignoring the current network ofc. Have not really tested this though besides a dev board. My main concerns are possibility to soft-lock the device in some weird state and newish approach to do the connection really early on boot. If this works, ok :) If it does not, pls open an issue |
Initial testing with two devices and it seems to work well. Device was connected to one channel around -56. WiFi AP turned off near that device and it connected to a different AP on another channel at -76. WIFI AP turned back on and after approx. 3 mins, the device had connected back to the original AP. Can the |
Threshold is exposed as a setting, but not (yet) displayed in the UI: espurna/code/espurna/wifi_config.h Lines 70 to 72 in 976176c
Lines 368 to 370 in 976176c
(will try to squeeze it into another patch related to settings, right now the idea is to show when calling wifi to see all of things under the wifi 'namespace')Amount of retries is not, though, it is a build-time setting at least for now. Does it behave normally when neither APs are working and it needs to wait to reconnect longer? Does fallback still work? |
What length of time should each check take? I isolated the WiFi and after approx 4 minutes I'd lost connection. Re-instated the WiFi but the device didn't connect for at least 2 mins and the espurna AP didn't come up. A power cycle re-boot reconnected back to the known WiFi as normal. |
When disconnected from the AP, retries start in about 10-15seconds. It attempts to connect 3 times (around ~4seconds inbetween), then attempts again in 2 minutes. For a single network config, fallback AP should be there in around 20 seconds There's a small bug in disconnection detection though - when attempting the connection, timeout happens too early and it schedules another connection while already connected... device will needlessly disconnect->connect another 2 times, but will work ok after that happens. Not being able to connect brings up the fallback AP , not yet sure about that one. |
fix #2064
based on xoseperez/justwifi@master...mcspr:better-networks
sort of works. low interval of 10sec and two APs seems to work, jumping from one to the other.
one strange issue is when AP disappears by plugging it off, connection logs the old network but actually connects to the other one, not sure if that is some feature of SDK or I have a typo somewhere.