Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

picow_access_point example cannot be changed to other subnet #383

Open
eamars opened this issue May 17, 2023 · 10 comments
Open

picow_access_point example cannot be changed to other subnet #383

eamars opened this issue May 17, 2023 · 10 comments
Assignees
Milestone

Comments

@eamars
Copy link

eamars commented May 17, 2023

The example code from https://github.com/raspberrypi/pico-examples/blob/master/pico_w/wifi/access_point/picow_access_point.c#L293 shows the default IP address for the DHCP server is 192.168.4.1. When I changed the subnet to, for example, 192.168.3.1, my TCP client could not connect to the pico w anymore.

Wireshark shows the DHCP server is still offering 192.168.4.1 as the router.

Unfortuantely I'm not professional in lwip implementation therefore I could not figure out where the IP address is hard coded.

@eamars eamars changed the title cyw43 example access point with FreeRTOS picow_access_point example cannot be changed to other subnet May 17, 2023
@peterharperuk
Copy link
Contributor

I can't think what would need to change - probably a bug. Is there any reason why are you using the tcp_server example rather than the access point example?

@eamars
Copy link
Author

eamars commented May 17, 2023

Hi @peterharperuk
Thanks for your reply. I just updated the title and description for the issue. The cause was I changed the IP address for the host from 192.168.4.1 to 192.168.3.1. For some reason the DHCP server is still offering the 192.168.4.1 for the router address, according to the wireshark, therefore the host could not be resolved.

@peterharperuk
Copy link
Contributor

You changed the gateway address to 192.168.3.1 ad it still offers 192.168.4.1?

IP4_ADDR(ip_2_ip4(&state->gw), 192, 168, 4, 1);
IP4_ADDR(ip_2_ip4(&mask), 255, 255, 255, 0);

// Start the dhcp server
dhcp_server_t dhcp_server;
dhcp_server_init(&dhcp_server, &state->gw, &mask);

As far as I'm aware the dhcp server uses its own address and just changes the last number.

Do you have two netifs? If you have an AP and are also connected via STA mode - be aware of this bug #382

@eamars
Copy link
Author

eamars commented May 17, 2023

Screen Shot 2023-05-18 at 12 01 05 AM

The new DHCP starts from packet 481. The 192.168.4.1 was offering the IP address while the pi has 192.168.3.1 IP address. In the end the 192.168.3.16 was assigned to the client.

@eamars
Copy link
Author

eamars commented May 17, 2023

@peterharperuk
The only change I made was to change the subnet from 192.168.4.1 to 192.168.3.1.

Only the AP mode is activated at the time of running the TCP server. Also please find my screenshot above regarding the DHCP packet.

@peterharperuk
Copy link
Contributor

If you changed the gateway address I don't see how it's possible for it to offer the wrong address.

@eamars
Copy link
Author

eamars commented May 18, 2023

@peterharperuk I finally trace back to the source of the 192.168.4.1
https://github.com/georgerobotics/cyw43-driver/blob/9bfca61173a94432839cd39210f1d1afdf602c42/src/cyw43_lwip.c#L182

For which when DHCP sends the offer, it uses 192.168.4.1 as the source. Unfortuantely due to the lack of knowledge I'm not sure why the system could not behave as normal when the IP address is changed to 192.168.3.1.

Is this coincidence for pico-example to also choose the 192.168.4.1 as the default subnet for example in the AP mode?

@peterharperuk
Copy link
Contributor

Ah right. Well done - I'd completely forgotten about that!
The latest driver (which should make it into the next release, has a macro CYW43_DEFAULT_IP_AP_GATEWAY to set this. I guess the dhcp server should use that.

@peterharperuk peterharperuk self-assigned this May 18, 2023
@peterharperuk peterharperuk added this to the 1.5.1 milestone May 18, 2023
@peterharperuk
Copy link
Contributor

Is this coincidence for pico-example to also choose the 192.168.4.1 as the default subnet for example in the AP mode?

I think they have to match, right? The cyw43-driver comes originally from Micropython and I "borrowed" this DHCP server from Micropython, so I suspect that's why they match.

@eamars
Copy link
Author

eamars commented May 18, 2023

Thank you very much!

@peterharperuk peterharperuk modified the milestones: 1.5.1, 1.6.0 Jun 13, 2023
peterharperuk added a commit to peterharperuk/pico-examples that referenced this issue Jun 13, 2023
Use CYW43_DEFAULT_IP_AP_ADDRESS instead.

Fixes raspberrypi#383
peterharperuk added a commit to peterharperuk/pico-examples that referenced this issue Jun 13, 2023
Use CYW43_DEFAULT_IP_AP_ADDRESS instead.

Fixes raspberrypi#383
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants