Replies: 2 comments 10 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.
8 replies
-
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.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.
All reactions