1

I have a pico w that I'm setting up as an access point:

ap = network.WLAN(network.AP_IF)
ap.config(essid=xxxx, password=xxxx)
ap.active(True)

and then I'm serving a "tell me how to connect to your router" web page:

s = socket. Socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("0.0.0.0", 80))
s.listen(1)

client, _ = s.accept()
...

And this works just fine. I connect eg a laptop to the access point and go to http://192.168.4.1 and the page appears. But I want to display a QR code with the http://... link to the web page on a 64x64 pixel matrix display that the pico is driving. So to enable me to use a 21x21 pixel QR code, I need the IP address range of pico access point to be 172.16..., rather than the 192.168... default. So to do that, I'm adding:

ap.ifconfig(('172.16.4.1', '255.255.255.0', '172.16.4.1', '0.0.0.0'))

to the access point setup code. Calling print(ap.ifconfig()) after it's configused shows it's setting up with that address range. But the website stops working. Accessing http://172.16.4.1 doesn't work and the web server doesn't accept the connection.

As suggested by goldilocks, I checked the laptop that is connected to the access point. It has an IP address in the 192.168... range. So it doesn't look like the pico w is either running a DHCP server, or if it is, it's assigning addresses in the wrong range.

So my questions:

  1. Does the soft access point in the network.WLAN code that the RP2 version of MicroPython uses support a DHCP server, or is the laptop handling this due to a lack of DHCP? The laptop is not connected to any other network, just the pico w access point.
  2. If the pico is supplying DHCP support, is there a way to configure the address range that it uses?
10
  • "Accessing 172.16.4.1 doesn't work and the web server doesn't accept the connection." -> That phrase smells like conjecture, is it? If what literally happens is that whatever web browser you are using says, "Connection refused", this is not the web server, because web servers (or application level servers generally) cannot do that. You need to clarify what actually happens alongside (or instead of) what you assume or think is happening.
    – goldilocks
    Jan 25, 2023 at 16:59
  • The client eventually times out and the client, _ = s.accept() line is never reached. Not sure I can clarify further as I’ve no further information as to what’s going wrong, which is why I’m asking. 😊
    – David Arno
    Jan 25, 2023 at 17:20
  • 1
    That implies the request is not reaching the Pico at all (beyond going through the wifi AP); check to see if exactly the same thing happens when you try to connect to a non-existent node on the same subnet (eg., 172.16.4.111). What IP is the client laptop using?
    – goldilocks
    Jan 25, 2023 at 17:26
  • @goldilocks, checking the laptop was the key to figuring out why it's not working. The laptop is still being assigned a 192.168 range IP address. It looks like I can change the ifconfig for the pico itself, but there's no way to configure the behaviour of the DHCP server that the access point provides. Looks like my plan needs a rethink. Thanks for your help.
    – David Arno
    Jan 25, 2023 at 22:12
  • Suggest you read this on usage of link-local addresses.
    – Seamus
    Jan 25, 2023 at 23:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.