WLAN.isconnected() is not really connected to wanted router when using static IP #9560
-
I know it was a silly mistake, but I have am use to setting up static IPs for my ESP32 devices. So when I tried Mike Teachman's publishThingspeak.py I put some extra lines in to put my ThingSpeak device on a static IP. Like this: # connect the device to the WiFi network
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
utime.sleep(0.5)
wifi.ifconfig(('192.168.10.80', '255.255.255.0', '192.168.10.1', '8.8.8.8'))
wifi.connect(WIFI_SSID, WIFI_PASSWORD)
# wait until the device is connected to the WiFi network
MAX_ATTEMPTS = 20
attempt_count = 0
while not wifi.isconnected() and attempt_count < MAX_ATTEMPTS:
attempt_count += 1
utime.sleep(1)
if attempt_count == MAX_ATTEMPTS:
print('could not connect to the WiFi network')
sys.exit()
print ('connected to WiFi')
print (' network config:', wifi.ifconfig()) When I changed to a different router on a different network isconnected() said is was connected but Reading the docs:
It might be difficult for isconnected() to recognise the user mistake. Or is there a better way to setup static IPs? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
for client static ip address you have 2 options:
for option 2,you should not use this line: |
Beta Was this translation helpful? Give feedback.
wifi.ifconfig(('192.168.10.80', '255.255.255.0', '192.168.10.1', '8.8.8.8'))
192.168.10.80 -> client ip address(esp32)
255.255.255.0 -> netmask
192.168.10.1 -> gateway(should be router)
8.8.8.8 -> dns
for client static ip address you have 2 options:
for option 2,you should not use this line:
wifi.ifconfig(('192.168.10.80', '255.255.255.0', '192.168.10.1', '8.8.8.8'))