Raspberry Pi Pico W Access Point - cannot change default IP

Has anyone set up a Pico W as an Access Point with a different IP address.
No matter what I do it always defaults to 192.168.4.1.

The Pico W is connected to a PC USB running Thonny.
Stop/Restart clicked.
Python script run.

It looks like when you set the IP, Subnet, Gateway, and DNS using ifconfig() and then activate it the default values are used not the ones set. To me this is an error in the Micro Python implementation for the Pico W.

Also the IP Access Point remains active until the Pico W is powered off. Even when the program is stopped. Connect and disconnect to the ssid ok; but of course no web page when program stopped, as you would expect.

btw the Access Point works perfectly using the default IP address.
I can connect using my phone to the ssid with the password.
Google Chrome then displays the program web page when accessing the default IP.

I have been through the documentation on how to set up WLAN.
All other set ups I have, tried work nicely, internet access ok, web page display ok, etc.
I am very impressed with the operation of the Pico W and how easy it is to use with Micro Python.

Its just the Access Point IP I am unable to change.
Regards
Jim

# python code to set up access point and IP address
ap = network.WLAN(network.AP_IF)
ap.config(ssid=ssid, password=pw)
print('01 ',ap.ifconfig())
ap.ifconfig(('192.168.12.1','255.255.255.0','192.168.12.1','0.0.0.0'))
print('02 ',ap.ifconfig())
ap.active(True)
print('03 ',ap.ifconfig())

while ap.active() == False:
  pass

print('Connection successful')
print('04 ',ap.ifconfig())


# Shell output
01  ('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
02  ('192.168.12.1', '255.255.255.0', '192.168.12.1', '0.0.0.0')
03  ('192.168.4.1', '255.255.255.0', '192.168.4.1', '0.0.0.0')
Connection successful
04  ('192.168.4.1', '255.255.255.0', '192.168.4.1', '0.0.0.0')

2 Likes

Original Deleted: Thought I had fixed it, only made it worse.

One thing I did find is the ssid and password must be declared before making the Access Point active.
Which makes sense, you set up the configuration then activate it.
Also explains the problems some have noted on other forums.

Note the ssid and password are loaded from a small separate file so they are not visible in the main program. Something I had seen in an example.
Regards
Jim

import network
from SSID_AP import SSID_AP

ssid = SSID_AP['ssid']
pw = SSID_AP['pw']

ap = network.WLAN(network.AP_IF)
ap.config(ssid=ssid, password=pw)          # must be before active(True)

ap.active(True)
while ap.active() == False:
  pass
2 Likes

It’s a little odd, but I found that it worked on the second attempt. Here’s the output of 2 consecutive runs:

>>> %Run -c $EDITOR_CONTENT
01  ('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
02  ('192.168.12.1', '255.255.255.0', '192.168.12.1', '0.0.0.0')
03  ('192.168.4.1', '255.255.255.0', '192.168.4.1', '0.0.0.0')
Connection successful
04  ('192.168.4.1', '255.255.255.0', '192.168.4.1', '0.0.0.0')
>>> %Run -c $EDITOR_CONTENT
01  ('192.168.4.1', '255.255.255.0', '192.168.4.1', '0.0.0.0')
02  ('192.168.12.1', '255.255.255.0', '192.168.12.1', '0.0.0.0')
03  ('192.168.12.1', '255.255.255.0', '192.168.12.1', '0.0.0.0')
Connection successful
04  ('192.168.12.1', '255.255.255.0', '192.168.12.1', '0.0.0.0')

If I hot “Stop” in thonny it remembered the IP, but if I unplug and replug it in I get the original behaviour. I’ll have a play around and see what I can find.

4 Likes

Hi Jim,

It looks like the ap.active(True) sets the ip to the default/previous value. Try swapping the ap.ifconfig(...) and ap.active(True) lines like this:

import network
ap = network.WLAN(network.AP_IF)
ap.config(ssid='picow', password='picow')
print('01 ',ap.ifconfig())
ap.active(True)
print(ap)
print('02 ',ap.ifconfig())
ap.ifconfig(('192.168.12.1','255.255.255.0','192.168.12.1','0.0.0.0'))
print('03 ',ap.ifconfig())

while ap.active() == False:
  pass

print('Connection successful')
print('04 ',ap.ifconfig())

this gave me:

%Run -c $EDITOR_CONTENT
01  ('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
<CYW43 AP up 192.168.4.1>
02  ('192.168.4.1', '255.255.255.0', '192.168.4.1', '0.0.0.0')
03  ('192.168.12.1', '255.255.255.0', '192.168.12.1', '0.0.0.0')
Connection successful
04  ('192.168.12.1', '255.255.255.0', '192.168.12.1', '0.0.0.0')
3 Likes

Thanks for your reply @Doug27394, I have been through all the options and nil success.
Original reply deleted.

Conclusions I have come to:
DHCP assignment of IP addresses is flawed, connecting devices need to use static addresses.
The interface always starts up with 192.168.4.1 but can be changed and works with the change.
Setting of the SSID & Password must be done before activating the interface.
A small delay is necessary in starting and stopping the interface.
The previous IP address is remembered between program starts but not after power off.

Program code and shell output.

import time
import network
from SSID_AP import SSID_AP

IP =      '192.168.12.1'
SUBNET =  '255.255.255.0'
GATEWAY = '192.168.12.1'
DNS =     '0.0.0.0'

ssid = SSID_AP['ssid']
pw = SSID_AP['pw']

ap = network.WLAN(network.AP_IF)
ap.config(ssid=ssid, password=pw)
ap.active(True)
time.sleep(0.1)
print('1',ap)
ap.ifconfig((IP,SUBNET,GATEWAY,DNS))
time.sleep(0.1)
print('3',ap)

while True:
    pass
>>> %Run -c $EDITOR_CONTENT
1 <CYW43 AP up 192.168.4.1>
3 <CYW43 AP up 192.168.12.1>

Pings successful between Pico W, Phone, and Pi4B. Now for the next part of this project.

Cheers
Jim

2 Likes