WiFi.SSID() not available after WiFi.ready()

I’ve found an issue getting ssid after verify WiFi.ready()
This is my code:

    Serial.println("Connecting WiFi");
    while ( !WiFi.ready() ) delay(200);
    Serial.print("Wifi Connected: ");

Sometimes WiFi.SSID() is empty !
I’ve posted because i’ve no found a similar issue on community

Hmm thats strange, according to the docs the function becomes true when the core has obtained an IP address. Having an IP address is rather hard without an SSID so I’m not sure what is going on here.

Are you connecting to the cloud or only WLAN? If you are connecting to the cloud you could also slip in

while (!Spark.connected()) delay(100);

and see if that works

yes with a delay i can read ssid but i think this a bug of WiFi.ready() function…

I think the problem is in the time to write the ssid to the registers. The WiFi might be ready but the data is still being written into the memory. Perhaps @bko can help

yes, but i think WiFi.ready() need a fix :smile:

If this issue reproduces then yes, it definitely needs a fix :wink:

@blondie63 & @TheHawk1337 I agree it is a bug or at least poor documentation I find it takes at least 800 milliseconds to get a valid response from WIFI.SSID() once WiFi.ready() is true.

Hi guys,

WiFi.ready only checks to see if the TI part has reported that it got a DHCP address.

There is a call in SPARK_WLAN_Loop() after the DHCP address is set that fills out SSID and local IP, gateway IP, subnet mask, and MAC address from information provided by the TI WiFi part.

If you are not calling SPARK_WLAN_Loop() in your own while loop, this will not happen until you go around loop().

If you are calling SPARK_WLAN_Loop() either directly or by going around loop(), it asks the TI part for this info after a delay of 100ms, so in the 800ms case, it looks to me like it takes 8 call attempts to get the data from the TI part.

I don’t think the Spark guys wanted to block waiting for this data but you certainly can.

The first part of the doc for WiFi.ready() is correct–just when the DHCP address is set, but the second part is not right: you should wait for local IP and friends to get filled in before starting a connection.

1 Like

Hi @bko I would say that I do not think the calls to SPARK_WLAN_Loop() are necessary for the ssid to eventually get populated. I am using manual mode.

The code block I did the test with was pretty much as follows:

if (WiFi.ready())
   i = 0;
   while( i < 20)
      if (strcmp(ssid,"") != 0)
         i = 20;

Hi @HardWater

SPARK_WLAN_Loop() is an internal function that gets called lots of places to keep the cloud alive.

It gets called when you go around the loop() and it gets called during delay() when either the delay value is large enough to mask the call time or when enough small delays have accumulated.

So yes, it is called and it does fill out the SSID etc.