hasCredentials() always returns false unless .connect() has been called

I’ve refactored the code, but not changed how it functions. Please feel free to open a github issue with your findings so we have a place to discuss the issues and potential fixes!

Hi again @akiesels!

I just pushed a fix for this issue to the feature/hal branch on the firmware repo. If you are building locally, please take it for a spin!

The state problems with WiFi I believe have been addressed, but to be sure, if you have any test code, please let me have it so I can plug that into our integration tests so that we know it’s fixed for sure!

For programmatically detecting wrong credentials, there’s an app issue for that! https://github.com/spark/firmware/issues/359

Cheers,
mat.

Hi @mdma,

I missed this post earlier somehow - sorry about that! So, I just pulled the latest source from the feature/hal branch, built it locally and flashed the core over USB. My test application code is very simple, same as the one in the original post above.

Unfortunately, I am still seeing incorrect behavior with the new firmware:

If the core has credentials stored, upon restart the red LED connected to D0 comes on and stay lit until wifi connection is made. At which point the blue LED connected to D1 lights up and the red one on D0 goes off.

So, it looks like .hasCredentials() is still returning false until wifi connection is made, regardless of whether credentials are actually stored or not.

Let me know if I can help troubleshoot this further.

Thanks,
Alexander

Hi @akiesels and @mdma

I am seeing the same issue here. I am trying to handle network association manually in my code just for experimentation. The following code loops forever even though the smart config app is running on my android transmitting settings. It seems WiFi.hasCredentials() always returns false in my code. This seems to be related to the issue in this post.

Here is the code snippet(module is in SYSTEM_MODE(SEMI_AUTOMATIC):

void setup()
{
	Serial.begin(9600);
	delay(1000);
	Serial.println("Start");
	WiFi.on();

	retry:

	if(!WiFi.hasCredentials()){
		Serial.println("No WiFi Credentials starting listen");
		WiFi.listen();
		while(!WiFi.hasCredentials());
		Serial.println("Got Credentials");
	}
	Serial.println("Connecting");
	WiFi.connect();
	Serial.println("Connecting WiFi");

	unsigned long startTime = millis();

	while(!WiFi.ready() || millis() < startTime + connectTimeout){
	}
	if(!WiFi.ready()){
		goto retry;
	}
	Serial.println("WiFi Connected");
}

The RGB LED turns on Blue at boot up and stays on solid indefinitely. Does not flash, just on solid.

Hi @mdma

Is this thread dead? I am back to this issue again with my application. Any fixes yet? I see this problem is not marked solved yet.

Thank you

Are you compiling locally with the feature/hal branch?

Hi @mdma,

Yes I am compiling locally through Eclipse. The problem is I get errors when opening the spark_wlan file right now. Is this where modifications are required? If so what modifications do I need to make?

Thanks,
Travis

@mdma, I can confirm that the light is still solid blue in both the develop and the feature/hal branches. I changed the line:

while(!WiFi.hasCredentials());
to
while(WiFi.listening());

but, to no avail. I am trying to find the relevant lines using the debugger right now…

I was having this problem recently, and wanted to pass on a workaround I found. You can call WiFi.connect with the WIFI_CONNECT_SKIP_LISTEN flag to tell it not to put it into listening mode, e.g.

WiFi.connect(WIFI_CONNECT_SKIP_LISTEN);

I call this right after I call WiFi.on, and then can test for credentials successfully using WiFi.hasCredentials(). Hopefully this helps anyone still fighting with this issue and looking for a workaround. (As this doesn’t contribute directly to the problem, if there’s a more appropriate place for this comment, let me know and I’ll move it).

2 Likes