OSError: scan failed

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
jamesb
Posts: 13
Joined: Tue Nov 29, 2016 3:31 am

OSError: scan failed

Post by jamesb » Sun Dec 18, 2016 3:00 am

wifi.scan() gives:

Code: Select all

>>> interface.scan()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: scan failed
I think it's when it can't see any wifi networks. I guess I'll enclose it in a try-except block, unless someone know a smart way around this?

eradicatore
Posts: 52
Joined: Thu Apr 20, 2017 9:19 pm

Re: OSError: scan failed

Post by eradicatore » Tue Oct 03, 2017 7:59 pm

Hi,
Were you able to confirm this happens if the scan results in no networks found? I was hitting OS error on scans in one location last night very repeatedly, so I would assume you're right. But I just expected the documentation to also mention this pretty interesting way of reporting nothing found (rather than just an empty tuple).

eradicatore
Posts: 52
Joined: Thu Apr 20, 2017 9:19 pm

Re: OSError: scan failed

Post by eradicatore » Thu Nov 16, 2017 8:21 pm

I still can't get the try/except to work around this failure when there are no wifi scan results. Does anyone else see this failure if there are zero ap's visible when you try to scan? Why would code like this not work?

Code: Select all

    try:
        scan_results = wifi.scan()
    except:
        ## for some odd reason OSERROR here means no wifi APs found
        scan_results = None
  

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: OSError: scan failed

Post by pythoncoder » Fri Nov 17, 2017 11:17 am

Hmm. That's a hard one to test unless you live in Greenland ;) My Faraday cage (AKA microwave oven) is too small for my laptop. Ideas anyone?
Peter Hinch
Index to my micropython libraries.

stundenblume
Posts: 2
Joined: Thu Jan 10, 2019 7:52 pm

Re: OSError: scan failed

Post by stundenblume » Thu Jan 10, 2019 7:55 pm

Hello,
eradicatore wrote:
Thu Nov 16, 2017 8:21 pm
I still can't get the try/except to work around this failure when there are no wifi scan results. Does anyone else see this failure if there are zero ap's visible when you try to scan? Why would code like this not work?
I know, this is very old but yes, I have the same Problem.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: OSError: scan failed

Post by Roberthh » Thu Jan 10, 2019 8:31 pm

For me it works. I made a little test script:

Code: Select all

from network import WLAN
wlan=WLAN()

while True:
    try:
        print(wlan.scan())
    except OSError:
        print("Silence")
Firmware: MicroPython v1.9.4-773-gafecc124-dirty on 2019-01-04; ESP module with ESP8266

I placed the ESP8266 in the microwave (thanks Peter), with the thinnest cable I could find, and got both scan results and 'Silence' printed. I must say that WiFi reception in our kitchen is poor, and the rssi, when received, was below -90 dB.

B.t.w.: Poor WiFi in the kitchen is not that bad for personal communication at the table.

stundenblume
Posts: 2
Joined: Thu Jan 10, 2019 7:52 pm

Re: OSError: scan failed

Post by stundenblume » Tue Jan 15, 2019 7:20 am

Hello Robert,
thanks for testing. I will try it again, as I was testing I was in a train, right now I can't find a place without wifi signals.
Sebastian

Post Reply