Skip to content

Added fix for long wait between connections on Adafruit feather m0#266

Merged
nitin710 merged 3 commits intomasterfrom
hotfix-wifiConnectionAttemptDelay
Apr 6, 2023
Merged

Added fix for long wait between connections on Adafruit feather m0#266
nitin710 merged 3 commits intomasterfrom
hotfix-wifiConnectionAttemptDelay

Conversation

@nitin710
Copy link
Collaborator

@nitin710 nitin710 commented Apr 5, 2023

Description

Fixes a bug where network switching on feather M0 would take attemptDelay (set in code) seconds. This artifact was introduced when changes were made to support enterprise wifi on ESP32.

This bug caused the Feather M0 to wait for 20 secs before switching networks (even if the network it was trying to connect to was not available).
This patch fixes that issue and now, if a network is not available (Feather M0 fails to connect to it), it moves on to the next network.

Requirements

  • None

Issues Referenced

  • None

Documentation update

  • None

Testing

The following shows the setup log indicating time taken between trying separate networks.

  • Testing on ESP32 (SSID not available)
    • Notice that even though the timeout is set to 20secs, it switches to the next network after 4 secs (time taken for ESP to detect absence of network)
    • WiFi.status() = 1 is WL_NO_SSID_AVAIL
ttempting to connect to SSID: brainwaves2.4
WiFi.begin() duration = 116
WiFi.status() = 1, total duration = 4116
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: emotinet
WiFi.begin() duration = 116
WiFi.status() = 1, total duration = 4116
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: brainwaves2.4
WiFi.begin() duration = 116
WiFi.status() = 1, total duration = 4117
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: emotinet
WiFi.begin() duration = 116
WiFi.status() = 1, total duration = 4116
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: brainwaves2.4
WiFi.begin() duration = 117
WiFi.status() = 1, total duration = 4117
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: emotinet
WiFi.begin() duration = 117
WiFi.status() = 1, total duration = 4117
  • Testing on ESP32 (SSID available)
Attempting to connect to SSID: emotinet
WiFi.begin() duration = 72
WiFi.status() = 1, total duration = 4073
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: FiOS-RUV
WiFi.begin() duration = 125
WiFi.status() = 3, total duration = 6124
WiFi.begin() attempts = 2
Connected to WiFi
SSID: FiOS-RUV
  • Testing on Feather M0 (SSID not available)
    • Notice that the Feather switches network as soon as it fails to connect to the network it is trying.
    • The bug caused the Feather to wait here for 20 secs. Now it moves to the next network within 1 second.
    • WiFi.status() = 6 is WL_DISCONNECTED
Attempting to connect to SSID: brainwaves2.4
WiFi.begin() duration = 952
WiFi.status() = 6, total duration = 952
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: emotinet
WiFi.begin() duration = 920
WiFi.status() = 6, total duration = 921
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: brainwaves2.4
WiFi.begin() duration = 921
WiFi.status() = 6, total duration = 921
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: emotinet
WiFi.begin() duration = 921
WiFi.status() = 6, total duration = 921
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: brainwaves2.4
WiFi.begin() duration = 920
WiFi.status() = 6, total duration = 921
  • Testing on Feather M0 (SSID available)
Attempting to connect to SSID: emotinet
WiFi.begin() duration = 952
WiFi.status() = 6, total duration = 952
<<<<<<< Switching WiFi Networks >>>>>>>
Attempting to connect to SSID: FiOS-RU
WiFi.begin() duration = 1033
WiFi.status() = 3, total duration = 1034
WiFi.begin() attempts = 2
Connected to WiFi
SSID: FiOS-RUV
IP Address: 192.168.1.84

Steps to test

  • Flash the EmotiBit with the bin files. 1.7.0.hotfix-wifiConnectionAttemptDelay.zip
  • Add credentials to an SSID that does not exist/ is not currently available.
  • Notice the switching speed in the serial log.
  • It should switch networks faster than 20 secs (which is the current programmed delay)

Checklist to allow merge

  • All dependent repositories used were on branch master
  • Firmware
    • Set testingMode to TestingMode::NONE
    • Set const bool DIGITAL_WRITE_DEBUG = false (if set true while testing)
    • Update version in EmotiBit.h
    • Update library.properties to the correct version (should match EmotiBit.h)
  • Update software bundle version in ofxEmotiBitVersion.h
  • doxygen style comments included for new code snippets
  • Required documentation updated

Screenshots:

#endif
// only check for WL_DISCONNECTED if board is ESP. It is because of how WiFi library on ESP handles a connection failure.
// ToDo: reconsider this logic if support for new board (apart from M0 or ESP32) is added
while((wifiStatus == WL_IDLE_STATUS || (checkForDisconnected && wifiStatus == WL_DISCONNECTED)) && (millis() - beginDuration < attemptDelay)) // This is necessary for ESP32 unless callback is utilized
Copy link
Collaborator Author

@nitin710 nitin710 Apr 5, 2023

Choose a reason for hiding this comment

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

For reviewer:
Logic:

  • For Feather M0: checkForDisconnected = false

while((wifiStatus == WL_IDLE_STATUS || (false && wifiStatus == WL_DISCONNECTED))
which equals
while((wifiStatus == WL_IDLE_STATUS))

  • For ESP32: checkForDisconnected = true

while((wifiStatus == WL_IDLE_STATUS || (true && wifiStatus == WL_DISCONNECTED))
which equals
while((wifiStatus == WL_IDLE_STATUS || (wifiStatus == WL_DISCONNECTED))

Copy link
Collaborator

@produceconsumerobot produceconsumerobot left a comment

Choose a reason for hiding this comment

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

Review 01

Code looks good.
Are there test results affirming that when the network is available it will still connect on both MCUs?
Did you intend to include bin files?

@nitin710
Copy link
Collaborator Author

nitin710 commented Apr 5, 2023

Review 01

Are there test results affirming that when the network is available it will still connect on both MCUs?

Yes, that has been tested. I will add it to the results above and ping you.

Did you intend to include bin files?

Ah, missed the upload. Will fix that.

@nitin710
Copy link
Collaborator Author

nitin710 commented Apr 5, 2023

@produceconsumerobot
updated PR with test results for "successful connect".
also linked bin files.

@produceconsumerobot
Copy link
Collaborator

@nitin710 great!
Test results look good to me.
Let's add these tests to our FW testing protocol/records. Perhaps we can even add a new column for the "modules" (or files) these tests touch so that we can be sure to run these tests at appropriate times in the future.
I will try to test this out tomorrow on univ networks, but I'd say go ahead and merge if you're ready.

@nitin710
Copy link
Collaborator Author

nitin710 commented Apr 6, 2023

Added the tests to our protocols.
Merging to master.

@nitin710 nitin710 merged commit 6edc2be into master Apr 6, 2023
@nitin710 nitin710 deleted the hotfix-wifiConnectionAttemptDelay branch April 6, 2023 15:47
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