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

ipv4_address_ap not available immediately #9855

Open
stanelie opened this issue Dec 3, 2024 · 6 comments
Open

ipv4_address_ap not available immediately #9855

stanelie opened this issue Dec 3, 2024 · 6 comments
Labels
bug espressif applies to multiple Espressif chips network
Milestone

Comments

@stanelie
Copy link

stanelie commented Dec 3, 2024

CircuitPython version

Adafruit CircuitPython 9.2.0 on 2024-10-28; Waveshare ESP32-S3-Zero with ESP32S3

Code/REPL

import wifi
import ipaddress

ip_address_str = 0

ipv4 = ipaddress.IPv4Address("2.0.0.2")
netmask = ipaddress.IPv4Address("255.0.0.0")
gateway = ipaddress.IPv4Address("2.0.0.1")

def create_wifi_AP():
    wifi.radio.set_ipv4_address_ap(ipv4=ipv4, netmask=netmask, gateway=gateway)
    wifi.radio.start_ap("potato", "barbecue_chips", channel=1, max_connections=4)
    banana = str(wifi.radio.ipv4_address_ap)
    
create_wifi_AP()
ip_address_str = wifi.radio.ipv4_address_ap
print(f"my IP addr: {ip_address_str}" )

Behavior

If I run this code, it prints out the correct IP address in the console.
However, if I comment out the line 13 (the line that starts with banana), it prints out "my IP addr: None", the ipv4_address_ap is empty.

Description

Is this a bug? Or expected behavior? I was trying to get the ip address from the wifi radio and it took me a while to figure this out. Maybe there is something that I don't get...

Additional information

No response

@stanelie stanelie added the bug label Dec 3, 2024
@anecdata
Copy link
Member

anecdata commented Dec 3, 2024

I ran the code as-is and got None. Then I removed the banana line and replaced it with a time.sleep(1) and got the AP IP address. I suspect there is a slight delay in how long it takes for the AP IP address to become accessible.

@stanelie
Copy link
Author

stanelie commented Dec 3, 2024

That might be it, I will test. Thanks!

@stanelie
Copy link
Author

stanelie commented Dec 3, 2024

Correct, it works for me as well.
Can this be added to the documentation?

@stanelie
Copy link
Author

stanelie commented Dec 3, 2024

I tried time.sleep(0.01), it also works.

@anecdata
Copy link
Member

anecdata commented Dec 3, 2024

Let's leave this issue open, there may be a fix possible in the software, so that the call to set the address doesn't return until the address is valid. iirc, there was a similar issue for Station that was fixed like that.

@dhalbert dhalbert changed the title cannot get ipv4_address_ap unless I use it ? ipv4_address_ap not available immediately Dec 3, 2024
@dhalbert dhalbert added network espressif applies to multiple Espressif chips labels Dec 3, 2024
@dhalbert dhalbert added this to the 9.x.x milestone Dec 3, 2024
@anecdata
Copy link
Member

anecdata commented Dec 4, 2024

Maybe an explicit call to esp_netif_dhcps_get_status() before returning from wifi.radio.set_ipv4_address_ap()? But what to do if it's not yet started? Check in a loop for some max time and raise an exception if it's still not started?

iirc, wifi.radio.ap_info.rssi had the same issue. It wasn't valid right away after a wifi connection. It was up to user code to wait and check. But maybe that was fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug espressif applies to multiple Espressif chips network
Projects
None yet
Development

No branches or pull requests

3 participants