Skip to content
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

Sorting of scanned wifi networks #661

Merged
merged 1 commit into from
Dec 21, 2024
Merged

Conversation

tyeth
Copy link
Contributor

@tyeth tyeth commented Nov 13, 2024

Addresses #659

@tyeth tyeth force-pushed the wireless-rssi-sorting branch from 7d2aebe to f234c27 Compare November 13, 2024 18:35
@tyeth
Copy link
Contributor Author

tyeth commented Nov 14, 2024

Works on Pico, which is what I was after as it was affecting my testing of other things.

No known network sorted response details

---- Reopened serial port COM40 ----
Found single wifi network in secrets.json
Adafruit.io WipperSnapper
-------Device Information-------
Firmware Version: 1.0.0-beta.92
Board ID: rpi-pico-w
Adafruit.io User: tyeth
WiFi Network: free4all_2G
MAC Address: 28:CD:C1:0E:17:E8
-------------------------------
Generating device's MQTT topics...
Running Network FSM...
Establishing network connection...
Performing a WiFi scan for SSID...ERROR: Your requested WiFi network was not found!
WipperSnapper found these WiFi networks: 
free4all -50dB
free4all -52dB
free4all -55dB
Tenda_60C06C -79dB
free4all -82dB
ERROR [WDT RESET]: ERROR: Unable to find WiFi network, rebooting soon...
ERROR [WDT RESET]: ERROR: Unable to find WiFi network, rebooting soon...

And success (failing on connect attempt #0, but succeeding on # 1 aka 2nd attempt):

Details

---- Opened the serial port COM40 ----
Connecting to WiFi (attempt #1)
Connected to WiFi!
Connecting to AIO MQTT (attempt #0)
WiFi Status: 20
Registering hardware with WipperSnapper...
Registering hardware with IO...
Encoding registration request...Encoding registration msg...Published!
Polling for registration message response...2
GOT Registration Response Message:
Hardware Response Msg:
        GPIO Pins: 31
        Analog Pins: 4
        Reference voltage: 3.30v
Completed registration process, configuration next!
Polling for message containing hardware configuration...
Polling for message containing hardware configuration...
Polling for message containing hardware configuration...
cbSignalTopic: New Msg on Signal Topic
2 bytes.
decodeSignalMsg
cbSignalMsg
Sub-messages found: 1
Signal Msg Tag: Pin Configuration
Initial Pin Configuration Complete!
Publishing to pin config complete...
Hardware configured successfully!
Registration and configuration complete!
Running application...
Sending MQTT PING: SUCCESS!
WiFi RSSI: -36
Sending MQTT PING: SUCCESS!
WiFi RSSI: -44
Sending MQTT PING: SUCCESS!
WiFi RSSI: -53
Sending MQTT PING: SUCCESS!
WiFi RSSI: -43
Sending MQTT PING: SUCCESS!

@tyeth tyeth marked this pull request as ready for review November 14, 2024 20:51
@tyeth tyeth changed the title DRAFT CI Assets - Initial sorting of scanned wifi networks Sorting of scanned wifi networks Nov 14, 2024
@tyeth tyeth requested a review from brentru November 15, 2024 15:16
@tyeth
Copy link
Contributor Author

tyeth commented Nov 15, 2024

@brentru this is ready for review. I should retest on the other platforms, especially samd.

Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyeth I have a few review notes below and also some questions:

  1. Do we take the network with the highest RSSI?
  2. If we fail to connect to the defined network, do we try again with the next network in our list of networks?
  3. What is the purpose of sorting by RSSI if we are not going to take the network with the largest RSSI or if its not defined?

src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
@tyeth tyeth force-pushed the wireless-rssi-sorting branch from 806690f to a6b68cd Compare November 21, 2024 18:39
@tyeth
Copy link
Contributor Author

tyeth commented Nov 21, 2024

@tyeth I have a few review notes below and also some questions:

  1. Do we take the network with the highest RSSI?
  2. If we fail to connect to the defined network, do we try again with the next network in our list of networks?
  3. What is the purpose of sorting by RSSI if we are not going to take the network with the largest RSSI or if its not defined?
  1. Yep, the least negative, or closest to 0, being the strongest / highest RSSI. (Unless you mean more negative highest)
    -Edit- It appears on wikipedia that different hardware may return positive RSSI values, so we may need to switch the sort in those rare cases.
  2. I believe we only make an attempt to the strongest known network then do a reboot on third connect failure.
    It would be a nice extension to continue connecting to the other known networks if present. Don't think we'd need to keep a list of BSSIDs matching the SSIDs, to know which network we've failed on, instead we just accept if the default network fails and move on to the first alternative network entry, repeating until no remaining networks to try, then reboot. I guess we keep a position in the list, and the initial connect and reconnect logic goes through one by one.
  3. I believe the RSSI cannot be undefined, and we do take the first (closest to zero) network with the smallest/largest/strongest RSSI. I tested that we do and it correctly picks between 3 meshes when running the new code (it prints the RSSI on ping which is helpful).

@tyeth tyeth force-pushed the wireless-rssi-sorting branch 2 times, most recently from ee9b0ba to a1ea262 Compare November 21, 2024 19:58
@tyeth
Copy link
Contributor Author

tyeth commented Nov 27, 2024

Log of wifi multi connection attempt on ESP8266 with Wifi debug logging on (can't generate for WS firmware due to dbg size)
-Edit- Appears the code works fine, but my router refuses the dhcp request (as far as I can tell from the logs), but is fine on attempt two (which is to the second closest mesh instead of the closer router).
I've modified the multi library to print which entry from the list it's connecting to:

02:22:48.213 ->       0: [CH 01] [48:D3:43:A2:44:81] -93dBm * Shaun
02:22:48.213 ->       1: [CH 06] [48:D3:43:AC:16:A9] -90dBm * Ginger Moggie
02:22:48.213 ->       2: [CH 01] [AC:84:C6:EF:6D:22] -94dBm * Noonan WiFi
02:22:48.213 ->  ---> 3: [CH 08] [82:7F:54:A1:5B:41] -67dBm * free4all
02:22:48.213 ->  ---> 4: [CH 08] [C8:7F:54:D8:39:BC] -35dBm * free4all
02:22:48.213 ->  ---> 5: [CH 08] [62:7C:61:82:50:F1] -92dBm * free4all
02:22:48.213 ->  ---> 6: [CH 08] [B2:7C:61:82:2F:A1] -76dBm * free4all
02:22:48.213 ->       7: [CH 11] [18:35:D1:3A:09:09] -75dBm * VM7662787
02:22:48.213 ->       8: [CH 11] [10:D7:B0:B8:C4:F6] -89dBm * TALKTALKB8C4F9
02:22:48.213 -> [WIFIM] Sorted indices: 4 3 6 5 
02:22:48.213 -> [WIFIM] Connecting to #4 (free4all)
02:22:48.246 -> wifi evt: 2
02:22:48.279 -> scandone
02:22:49.150 -> state: 0 -> 2 (b0)
02:22:49.186 -> state: 2 -> 3 (0)
02:22:49.186 -> state: 3 -> 5 (10)
02:22:49.186 -> add 0
02:22:49.186 -> aid 17
02:22:49.186 -> cnt 
02:22:49.186 -> 
02:22:49.186 -> connected with free4all, channel 8
02:22:49.186 -> dhcp client start...
02:22:49.186 -> wifi evt: 0
02:22:59.190 -> pm open,type:2 0
02:23:18.212 -> [WIFIM] Connect timeout
02:23:18.212 -> [WIFIM] Connecting to #3 (free4all)
Original log

``` 02:03:30.974 -> rll��|�l�|� � l� b|������r�b� b��nn�lnn��� b�p��lrlrlp�n��� � l �� b n�|�� ��� b��nn�l��l`����nn l`���nr���n bl��lp�n��� r�������� b n�|� � b��nn� l`����nn l`���nr���n b��`��r��n b��`��� �� �l`���n��l������n�r��n|� l � l`��b��� �|�r��l�n� �n� l`���r�l�l�� � 02:03:31.083 -> SDK:2.2.2-dev(38a443e)/Core:3.1.2=30102000/lwIP:STABLE-2_1_3_RELEASE/glue:1.2-65-g06164fb/BearSSL:b024386 02:03:31.083 -> 02:03:31.083 -> ESP8266 Multi WiFi example 02:03:31.083 -> fpm close 1 02:03:31.083 -> mode : sta(c8:c9:a3:90:31:eb) 02:03:31.083 -> add if0 02:03:31.083 -> wifi evt: 8 02:03:31.209 -> [WIFIM][APlistAdd] Add SSID: free4all 02:03:31.209 -> [WIFIM] Start scan 02:03:33.353 -> scandone 02:03:33.426 -> [WIFIM] 7 networks found: 02:03:33.426 -> 0: [CH 01] [48:D3:43:A2:44:81] -87dBm * Shaun 02:03:33.426 -> 1: [CH 06] [40:0D:10:5C:DD:39] -91dBm * VM7307174 02:03:33.426 -> ---> 2: [CH 08] [B2:7C:61:82:2F:A1] -75dBm * free4all 02:03:33.426 -> ---> 3: [CH 08] [C8:7F:54:D8:39:BC] -30dBm * free4all 02:03:33.426 -> ---> 4: [CH 08] [62:7C:61:82:50:F1] -83dBm * free4all 02:03:33.426 -> ---> 5: [CH 08] [82:7F:54:A1:5B:41] -63dBm * free4all 02:03:33.426 -> 6: [CH 11] [18:35:D1:3A:09:09] -75dBm * VM7662787 02:03:33.426 -> [WIFIM] Sorted indices: 3 5 2 4 02:03:33.426 -> [WIFIM] Connecting free4all 02:03:33.426 -> wifi evt: 2 02:03:33.509 -> scandone 02:03:34.354 -> state: 0 -> 2 (b0) 02:03:34.355 -> state: 2 -> 3 (0) 02:03:34.392 -> state: 3 -> 5 (10) 02:03:34.392 -> add 0 02:03:34.392 -> aid 15 02:03:34.392 -> cnt 02:03:34.392 -> 02:03:34.392 -> connected with free4all, channel 8 02:03:34.392 -> dhcp client start... 02:03:34.392 -> wifi evt: 0 02:03:38.419 -> [WIFIM] Connect timeout 02:03:38.419 -> [WIFIM] Connecting free4all 02:03:38.462 -> ap_loss 02:03:38.462 -> scandone 02:03:38.462 -> state: 5 -> 0 (0) 02:03:38.462 -> rm 0 02:03:38.462 -> reconnect 02:03:38.462 -> wifi evt: 1 02:03:38.462 -> STA disconnect: 8 02:03:39.126 -> scandone 02:03:40.009 -> state: 0 -> 2 (b0) 02:03:40.042 -> state: 2 -> 3 (0) 02:03:40.042 -> state: 3 -> 5 (10) 02:03:40.042 -> add 0 02:03:40.042 -> aid 8 02:03:40.042 -> cnt 02:03:40.042 -> 02:03:40.042 -> connected with free4all, channel 8 02:03:40.042 -> dhcp client start... 02:03:40.042 -> wifi evt: 0 02:03:42.073 -> ip:192.168.50.226,mask:255.255.255.0,gw:192.168.50.1 02:03:42.073 -> wifi evt: 3 02:03:42.141 -> [WIFIM] Connected: 02:03:42.141 -> [WIFIM] SSID: free4all 02:03:42.141 -> [WIFIM] IP: 192.168.50.226 02:03:42.141 -> [WIFIM] MAC: 82:7F:54:A1:5B:41 02:03:42.141 -> [WIFIM] CH: 8 02:03:42.141 -> [WIFIM] RSSI: -71 02:03:42.141 -> WiFi connected: free4all 192.168.50.226 02:03:43.119 -> WiFi connected: free4all 192.168.50.226 02:03:44.136 -> WiFi connected: free4all 192.168.50.226 ```

@tyeth tyeth requested a review from brentru November 29, 2024 14:37
src/Wippersnapper.h Outdated Show resolved Hide resolved
src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
src/network_interfaces/Wippersnapper_AIRLIFT.h Outdated Show resolved Hide resolved
@tyeth tyeth force-pushed the wireless-rssi-sorting branch from 1c9ca3b to 21f893a Compare December 11, 2024 22:30
@tyeth tyeth force-pushed the wireless-rssi-sorting branch 3 times, most recently from 5d54832 to 1f0468b Compare December 20, 2024 18:42
@tyeth tyeth requested a review from brentru December 20, 2024 18:47
@brentru
Copy link
Member

brentru commented Dec 20, 2024

@tyeth LGTM, merge when tests are passing

@tyeth tyeth force-pushed the wireless-rssi-sorting branch from 1f0468b to 0de83b9 Compare December 20, 2024 18:53
@tyeth tyeth merged commit e78470e into adafruit:main Dec 21, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants