-
Hello, I'm just getting started with micropython on an ESP-WROOM-32 board; and I could not connect as a station to an AP when using 1.24.0 and 1.23.0. After creating an active wlan station, the AP I wanted to connect to would show up in scan() results, but attempts to connect(ssid, pass) never completed. the stations .status() was 211, and that didn't match any of the network STAT_* constants. On a whim, I flash older firmware (1.19.1), and the esp32 connects to the AP as expected. v1.20.0 also works. Either I'm missing some configuration, or this a bug that I should report. If you have an esp32 as a wifi station with 1.24.0, could you please share the steps you took? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
Using 1.23: # 06 Mar 2024 D. Festing
import network
import time
import config
import machine
sta_if = network.WLAN(network.STA_IF)
def connect():
count = 0
# seems to help to start like this on ESP32
sta_if.active(False)
time.sleep(0.5)
sta_if.active(True)
time.sleep(0.5)
if not sta_if.isconnected():
print('connecting to hotspot...')
time.sleep(0.1)
try:
# maybe should go after connect
# sta_if.ifconfig((config.WiFi_device, '255.255.255.0', config.gateway, '8.8.8.8'))
sta_if.connect(config.hotspot, config.password)
sta_if.ifconfig((config.WiFi_device, '255.255.255.0', config.gateway, '8.8.8.8'))
except OSError as error:
try:
with open('errors.txt', 'a') as outfile:
outfile.write(str(error) + '\n')
except OSError:
pass
while (count < 20):
count += 1
if (sta_if.isconnected()):
count = 0
print(f'network config: {sta_if.ifconfig()}')
break
print('. ')
time.sleep(1)
if (count == 20):
try:
with open('errors.txt', 'a') as outfile:
outfile.write('failed to connect after 20 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.
-
config.gateway, '8.8.8.8' seems not good-》 this is Google dns not an ip gateway. Please see ipconfig (windows) or ifconfig on your pc settings to have the rigth settings. |
Beta Was this translation helpful? Give feedback.
-
I believe I ran into this same issue and it seemed to be related to memory. Connecting to wifi would work fine immediately after a fresh reboot, when gc.mem_free() showed about 80KB. But after importing a lot of modules, gc.mem_free() was down around 30KB, then I started getting weird problems connecting to wifi. This was on an ESP32-PICO-D4. If mem_free was really low like 10KB, it would report memory alloc errors, that helped me diagnose it. But in this "middle ground" of just not quite enough memory, I don't know what is failing internally but it wasn't reporting mem_alloc, it would report other things like Wifi Error 15, or 202, or 0x0101, or "internal error". |
Beta Was this translation helpful? Give feedback.
Sorry for the long delay in my response; I was busy working on my project using 1.20.0 and didn't have the wherewithal to debug the issue I was having with newer releases.
Happily, I found the issue and it was all thanks to you posting the undocumented 211 error constant of STAT_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD. My router was configured to use WPA for auth, and recent versions of esp-idf seem to only allow WPA2 and WPA3 connections. That is the 'threshold', and WPA is not within that threshold.
I modified my router's config to use WPA2, and now I can use 1.24.1 without issue.