Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8621

General • Re: Static IP on Raspberry Pico

$
0
0
My summary of the situation as I observe things to be ...

Connect with a DHCP obtained address - Most use cases

Code:

wlan = network.WLAN(network.STA_IF)wlan.active(True)wlan.connect(ssid, password)while not wlan.isconnected():  passprint(wlan.ifconfig())
Connect with a Fixed IP - Without provoking a DHCP request

Code:

wlan = network.WLAN(network.STA_IF)wlan.active(True)wlan.ifconfig((ip, netmask, gateway, dns))wlan.connect(ssid, password)while not wlan.isconnected():  passprint(wlan.ifconfig())
Incorrect way of connecting with a Fixed IP as it also provokes a DHCP request

Code:

wlan = network.WLAN(network.STA_IF)wlan.active(True)wlan.connect(ssid, password)while not wlan.isconnected():  passwlan.ifconfig((ip, netmask, gateway, dns))print(wlan.ifconfig())
If just wanting to change the last octet to become a Fixed IP after DHCP

Code:

octet = ".199"wlan = network.WLAN(network.STA_IF)wlan.active(True)wlan.connect(ssid, password)while not wlan.isconnected():  passip, netmask, gateway, dns = wlan.ifconfig()ip = ip[:ip.rfind(".")] + octetwlan.ifconfig((ip, netmask, gateway, dns))print(wlan.ifconfig())

Statistics: Posted by hippy — Mon Jan 29, 2024 12:02 pm



Viewing all articles
Browse latest Browse all 8621

Trending Articles