Hi all.
My specific question is, are there limitations or restrictions in Micropython and/or Pico in regard to using static IP addresses?
I ask because I’ve recently had to two very different applications where the code would fail using static, but work fine using DHCP.
The first was getting a json file from currentuvindex.com. The code works fine when connected using DHCP but fails when connected with a static IP. At first I thought the issue was DNS related and so I tried different DNS servers, no luck. Maybe it was my router settings so I bypassed that by using my mobile as a wi-fi hotspot, same issue.
The second was testing some code for uMail as an SMTP client for sending emails using MicroPython. The email will not send when on a static IP.
def do_connect(ssid=secrets['ssid'],psk=secrets['password']): # Gets the info from the secrets.py
print("do_connect.py says do_connect is called")
wlan = network.WLAN(network.STA_IF) # Initialize the Wi-Fi interface.
wlan.active(True) # Activate the interface.
# Set a static IP configuration
static_ip = '192.168.0.61' # Desired IP address
subnet = '255.255.255.0' # Subnet mask
gateway = '192.168.0.1' # Gateway IP
dns = '8.8.8.8' # 8.8.8.8 is Google. 202.142.142.142 is Aussie Broadband's DNS.
wlan.ifconfig((static_ip, subnet, gateway, dns))
# Connect
wlan.connect(ssid, psk)
# print(wlan.isconnected()) # Check the connection status.
# Wait for connect or fail
wait = 10
while wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
wait -= 1
print('do_connect.py says waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
raise RuntimeError('do_connect.py says wifi connection failed')