Skip to content

add retry to AP connect for simpletest #20

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

Merged
merged 2 commits into from
Mar 1, 2019
Merged

add retry to AP connect for simpletest #20

merged 2 commits into from
Mar 1, 2019

Conversation

jerryneedell
Copy link
Contributor

I find that the first attempt to connect to my SSID often fails. It usually connects on the secontd try.
adding this retry loop avoids a lot of problems.
This just occurred when I tried following the guide for a new pyportal.
With this change, it connects reliably.

@jerryneedell jerryneedell requested review from ladyada, a team and makermelissa March 1, 2019 12:27
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.

Looks like esp.connect in WiFiManager attempts a reset and retry, and excepts a ValueError too. (https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/blob/master/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py#L87

You may want to implement a hard-reset for the ESP before retrying: (https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/blob/master/adafruit_esp32spi/adafruit_esp32spi.py#L146)

Are you having these issues with the WiFiManager examples?

@jerryneedell
Copy link
Contributor Author

jerryneedell commented Mar 1, 2019

I have always had this issue with esp32spi , but the wifmanager handles it just fine with its retry. I dd not add the hard reset here, because it had just been reset as part of the init. I'm not sure what causes this or if others have had this issue. I has always worked for me on the second try.

I only accepted RuntimeError since I did not want to mask other issues.
In my experience it has always reported a RuntimeError "no such ssid".

I can add the ValueError and reset if you want -- I was just trying to keep it as simple as possible -- being a "simpletest"

@jerryneedell
Copy link
Contributor Author

FYI -- here is an example of the typical error and recovery with this PR


Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 2c9fbb5 on 2019-02-24; Adafruit PyPortal with samd51j20
>>> import esp32spi_simpletest
ESP32 SPI webclient test
ESP32 found and in idle mode
Firmware vers. bytearray(b'1.2.2\x00')
MAC addr: ['0xd1', '0x5b', '0xd', '0x33', '0x4f', '0xc4']
        Needell Airport         RSSI: -45
        Needell Airport         RSSI: -68
        Needell Airport         RSSI: -84
        Needell Airport         RSSI: -86
        xfinitywifi             RSSI: -88
         A31A           RSSI: -90
        central2.4              RSSI: -94
Connecting to AP...
could not connect to AP, retrying:  ('No such ssid', b'Needell Airport')
Connected to Needell Airport    RSSI: -44
My IP address is 10.0.0.173
IP lookup adafruit.com: 104.20.38.240
Ping google.com: 30 ms
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
----------------------------------------
This is a test of the CC3000 module!
If you can read this, its working :)
----------------------------------------

Fetching json from http://api.coindesk.com/v1/bpi/currentprice/USD.json
----------------------------------------
{'time': {'updated': 'Mar 1, 2019 13:52:00 UTC', 'updatedISO': '2019-03-01T13:52:00+00:00', 'updateduk': 'Mar 1, 2019 at 13:52 GMT'}, 'disclaimer': 'This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org', 'bpi': {'USD': {'code': 'USD', 'description': 'United States Dollar', 'rate_float': 3849.26, 'rate': '3,849.2567'}}}
----------------------------------------
Done!

@brentru
Copy link
Member

brentru commented Mar 1, 2019

@jerryneedell Thanks for providing the error log, you wouldn't need to handle ValueError in the case that it's only returning a RuntimeError.

@ladyada ladyada merged commit 370e56e into adafruit:master Mar 1, 2019
@jerryneedell jerryneedell deleted the jerryn_simpletest branch March 1, 2019 18:11
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 6, 2019
Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 1.3.2 from 1.3.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#21 from makermelissa/master
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#20 from jerryneedell/jerryn_simpletest

Updating https://github.com/adafruit/Adafruit_CircuitPython_PyPortal to 1.0.5 from 1.0.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#10 from ladyada/master
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.

3 participants