In the previous post-Raspberry Pi Pico W Web Server, we saw how to enable the network and allow access to our Raspberry pi pico W board, the problem is we don’t know the IP address and will need to wait for the router to assign a dynamic address. Using a static address that is set during board initialisation removes the wait and will allow us complete control
Enabling network credentials to the Pico W is a truly helpful thing. This has authorised us to access our machines from an individual computer. But when we did it, we depended on understanding what the IP address of the Pico W was in order to join that into our browser.
The portion of the address is dynamic and will be dependent on the configuration of our wireless network that is set up by our router. However, we can set up that address so that we know what it is going to be beforehand. This is what is called a static IP address.
The allocation of the address is dynamic meaning that it changes. It is dependent on which network we are attached to and is controlled by our router.
Get a static IP-address
We can find out what our default gateway is from Windows by proceeding to the command prompt and typing; To get a static IP address that works, it will require to be within the range delivered by the router.
1 |
ipconfig |
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix. :
Link-local IPv6 Address . . . . . : fe80::7e4:6897:cc02:4037%12
IPv4 Address. . . . . . . . . . . : 192.168.0.112
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
The default router gateway is, therefore ‘192.168.0.1’.
With all that information we are now ready to configure our static IP address.
Configuring Raspberry Pi Pico W With A Static IP Address
A static IP address is a computer’s unique address that is specific to that computer. It is used to identify that computer in a network and allow other devices on the network to find it.
Our network
module and our WLAN
category include a ifconfig
the process that uses all our collected information. We will require to declare it in the format wlan.ifconfig([(ip, subnet, gateway, dns)])
.
1 |
wlan.ifconfig(('192.168.0.112', '255.255.255.0', '192.168.0.1', '8.8.8.8')) |
Where 8.8.8.8
is a suitable DNS server?
To possess it in the example of the server our web server, we would put it into the section where we are configuring the wlan
settings;
1 2 3 4 |
wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect(ssid, password) wlan.ifconfig(('192.168.0.112', '255.255.255.0', '192.168.0.1', '8.8.8.8')) |