OSError: Wifi Internal Error on a tiny ESP32 C3 5x5 Neopixel board. #13414
-
Hi everyone, I can't get wifi working on this tiny ESP32 C3 board. And any help is much appreciated.
It always returns this in thonny:
The board reports this with esptool flash_id:
I've tried the ESP32 C3 release and preview (yes baud is low, but it is fast and works anyway): Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 47 replies
-
I've realised the first time you try and run the code (after reflashing) it sits waiting to connect, but never connects. Still doesn't connect though. |
Beta Was this translation helpful? Give feedback.
-
I always start with: sta_if.active(True)
# seems more reliable to start with a fresh connect()
if sta_if.isconnected():
sta_if.disconnect()
print ('started in the connected state, but now disconnected')
else:
print ('started in the disconnected state') |
Beta Was this translation helpful? Give feedback.
-
Hmmm. Nothing is returned by wlan.scan() but on my other boards I see a list of SSID and technical details. I've tried your hints and toggling active incase that did something.
it just said:
Line 29 is "sta_if.connect("SSID", "my real actual password")" |
Beta Was this translation helpful? Give feedback.
-
Overall this board's wifi seems super flakey. It works intermittently and can run the rest of my script querying solar power etc when it connects. It seems like it is affected by sources of RF noise, like poor quality USB power sources. A 2m USB cable strung up away from the computer works best for using thonny. Calling @andypiper, sorry to ping out of the blue, I see you posted about this ESP C3 neopixel 5x5 board previously. Did you have wifi problems? There is also a similar board with a RP2040 instead of ESP32 C3, so I'll order one of them and try it out. |
Beta Was this translation helpful? Give feedback.
-
Hi There, Still having trouble and getting this OSError issue. I am using a Lolin S2 Mini (fake I presume). Adding a try/except in my while loop connecting the wifi helps connecting:
This loop before connecting doesn't help:
This try/except in the while testing connecting does:
If someone has a better solution, please feel free to comment. Thx Eric. |
Beta Was this translation helpful? Give feedback.
-
In you script I see, that you re-issue |
Beta Was this translation helpful? Give feedback.
-
@Tico06 starting with a import network
import time
import config
import machine
sta_if = network.WLAN(network.STA_IF)
def connect():
count = 0
sta_if.active(True)
# seems more reliable to start with a fresh connect()
if sta_if.isconnected():
sta_if.disconnect()
print ('started in the connected state, but now disconnected')
else:
print ('started in the disconnected state')
time.sleep(0.1)
if not sta_if.isconnected():
print ('connecting to hotspot...')
time.sleep(0.1)
try:
sta_if.ifconfig((config.WiFi_device, '255.255.255.0', config.gateway, '8.8.8.8'))
sta_if.connect(config.hotspot, config.password)
except OSError as error:
try:
with open('errors.txt', 'a') as outfile:
outfile.write(str(error) + '\n')
except OSError:
pass
while (count < 5):
count += 1
if (sta_if.isconnected()):
count = 0
print (f'network config: {sta_if.ifconfig()}')
break
print ('. ')
time.sleep(1)
if (count == 5):
try:
with open('errors.txt', 'a') as outfile:
outfile.write('failed to connect after 5 tries' + '\n')
except Exception as e:
pass
disconnect() # or you could get errors
print ('machine reset')
time.sleep(0.1)
machine.reset() # start from scratch
rssi = sta_if.status('rssi')
print (f'RSSI = {rssi} dBm')
time.sleep(0.1)
if ((rssi < -95) or (rssi == 0)):
print ('signal level is below -95dBm')
time.sleep(0.1)
disconnect() # or you could get errors
print ('machine reset')
time.sleep(0.1)
machine.reset() # start from scratch
def disconnect():
sta_if.disconnect()
sta_if.active(False) |
Beta Was this translation helpful? Give feedback.
-
That seems overly complicated. I use the simple script below since ESP8266 times at all wifi capable boards, and it works fine.
|
Beta Was this translation helpful? Give feedback.
-
Here is a simple script I tested: from time import sleep_ms
import network
wlan = network.WLAN(network.STA_IF) # create station interface
wlan.active(True) # activate the interface
if wlan.isconnected():
wlan.disconnect()
print (f'Started in the connected state, but now disconnected.')
else:
print (f'Started in the disconnected state.')
wlan.config(reconnects=10)
while wlan.status() != network.STAT_IDLE:
print("Awaiting IDLE...")
sleep_ms(500)
print (f'Connecting...')
try:
wlan.connect(apSSID, apPWD) # connect to an AP
except OSError as e:
print("OSError, sleeping...")
while (wlan.status() == network.STAT_CONNECTING):
pass
if (wlan.status() == network.STAT_IDLE):
print (f'STAT_IDLE:', wlan.status())
elif (wlan.status() == network.STAT_CONNECTING):
print (f'STAT_CONNECTING:', wlan.status())
elif (wlan.status() == network.STAT_WRONG_PASSWORD):
print (f'STAT_WRONG_PASSWORD:', wlan.status())
elif (wlan.status() == network.STAT_NO_AP_FOUND):
print (f'STAT_NO_AP_FOUND:', wlan.status())
#elif (wlan.status() == network.STAT_CONNECT_FAIL):
# print (f'STAT_CONNECT_FAIL', wlan.status())
elif (wlan.status() == network.STAT_GOT_IP):
print (f'STAT_GOT_IP:', wlan.status())
else:
print(f'Unknown status:', wlan.status())
print (f'MAC:', wlan.config('mac')) # get the interface's MAC address
print (f'ifconfig:', wlan.ifconfig()) # get the interface's IP/netmask/gw/DNS addresses
print (f'Hostname:', wlan.config('hostname')) The first time I launch the script I have the following result:
Then re-launched immediatly, the state is unknown. It says STAT_IDLE, but has no IP....
The only way from there to get a connection to the WIFI is to reset the chip.... The node will be isolated and WIFI is not stable (small GSM box), thus I want to be sure it will connect and attempts as much as possible until connected. |
Beta Was this translation helpful? Give feedback.
-
Thx @davefes for your suggestion. I think you are right it will work after a machine.reset(). I am not in favour of kill & restart because it has an impact on the data management. I'll check if my use case, the ap could disappear and reappear, has any concerns with this issue and let you know. |
Beta Was this translation helpful? Give feedback.
-
So I made some tests to better understand how wifi works. My conclusion is the wifi stack works globally, I met once or twice general failure, but not able to find a way to reproduce. Anyway, the following issues are quite disturbing:
from time import sleep_ms
import network
wlan = network.WLAN(network.STA_IF) # create station interface
wlan.active(False) # de-activate the interface to re-init the stack
sleep_ms(500)
wlan.active(True) # activate the interface
sleep_ms(500)
wlan.config(reconnects=-1)
print('Connecting to an existing AP')
wlan.connect(apSSID, apPWD)
while wlan.status() in (network.STAT_CONNECTING, network.STAT_IDLE):
sleep_ms(500)
print ('Status should be STAT_GOT_IP({}): {}'.format(network.STAT_GOT_IP, wlan.status()))
wlan.active(False) # de-activate the interface to re-init the stack
sleep_ms(500)
wlan.active(True) # activate the interface
sleep_ms(500)
print ('\nStatus should be STAT_IDLE({}): {}\n\n'.format(network.STAT_IDLE, wlan.status()))
print('Connecting to a non-existing AP')
wlan.connect('Zorglub', apPWD) # connect to an AP which doesn't exist
while wlan.status() in (network.STAT_CONNECTING, network.STAT_IDLE):
sleep_ms(500)
print ('Status should be STAT_CONNECTING({}): {}'.format(network.STAT_CONNECTING, wlan.status()))
wlan.active(False) # de-activate the interface to re-init the stack
sleep_ms(500)
wlan.active(True) # activate the interface
sleep_ms(500)
print ('\nStatus should be STAT_IDLE({}): {}'.format(network.STAT_IDLE, wlan.status()))
from time import sleep_ms
import network
wlan = network.WLAN(network.STA_IF) # create station interface
wlan.active(False) # de-activate the interface to re-init the stack
sleep_ms(500)
wlan.active(True) # activate the interface
sleep_ms(500)
wlan.config(reconnects=-1)
print('Connecting to a non-existing AP')
wlan.connect('Zorglub!', apPWD)
# After wlan.connect, it could still been in STAT_IDLE before changing
# to STAT_CONNECTING
while wlan.status() in (network.STAT_CONNECTING, network.STAT_IDLE):
sleep_ms(500)
print ('Status should be STAT_CONNECTING({}): {}'.format(network.STAT_CONNECTING, wlan.status()))
Fortunately, it actually connects if the AP appears on the network.
>>> import network
>>> network.STAT_IDLE
1000
>>> network.STAT_CONNECT_FAIL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'STAT_CONNECT_FAIL' |
Beta Was this translation helpful? Give feedback.
Maybe:
https://docs.micropython.org/en/latest/library/network.WLAN.html
txpower and WLAN.PM_NONE