WiFi.hasCredentials / WiFi.ready not working on 0.7.0

Hi There,
It appears WiFi.hasCredentials() / WiFi.ready() never return true on 0.7.0 on my Photon device, whereas it did on 0.6.3. This is while I’m trying to pass it credentials while it is in softAP mode i.e. after WiFi.listen(true).

Observations :
• On 0.6.3, I start off with 36k of free memory, which drops to 16k of free memory when listening
• On 0.7.0, I start off with 24k of free memory, which drops to 4k of free memory when listening

• On 0.6.3, the memory jumps from 16k to 32k when I pass new credentials, and then stays at 32k
• On 0.7.0, the memory jumps from 4k to 24k briefly when I pass new credentials, but then falls back to 4k (this seems to indicate Photon does see some new credentials / some info being passed to it)

• On 0.6.3, WiFi.ready & WiFi.hasCredentials change to true upon passing credentials
• On 0.7.0, WiFi.ready & WiFi.hasCredentials is always false for some reason

Is softAP / WiFi.ready / WiFi.hasCredentials not working properly on 0.7.0 ?
Or is this a memory issue causing softAP / WiFi.ready / WiFi.hasCredentials to not work properly ?

Here’s the basic skeleton of the code (simplified) :

setup( ) {
        SYSTEM_MODE(SEMI_AUTOMATIC);
        SYSTEM_THREAD(ENABLED);

	WiFi.on( );
	WiFi.listen(false);
	WiFi.connect(WIFI_CONNECT_SKIP_LISTEN); // Trying to connect with previously saved credentials
        waitFor(WiFi.ready, 6000);

        debugPrint(System.freeMemory( ));

	if (!Particle.connected( )) { WiFi.listen(true); }
	
}

loop( ) {

	debugPrint(System.freeMemory( ));

	if ( WiFi.ready( ) ) { WiFi.listen(false);           						                 } // Never true
	else 	             { debugPrint(System.freeMemory( )); debugPrint(WiFi.hasCredentials( )); }
	
}

Any help would be appreciated,
Thanks,
Dhaval

Just a few notes

  • SYSTEM_MODE() and SYSTEM_THREAD() are macros that need to be placed outside of setup().
  • Your first WiFi.listen(false) call is superfluous. After WiFi.on() the device will never be in LM.
  • WiFi.connect(WIFI_CONNECT_SKIP_LISTEN) should only be used when WiFi.hasCredentials() is true.
  • 6 seconds for a WiFi connection to get established may be too short.
  • You are checking for Particle.connected() but that’ll always be false due to the lack of a Particle.connect() call.

BTW, readability of this kind of code format is not great.

1 Like

Thanks ScruffR. I made some copy-paste errors in an attempt to simplify the code snippet put here
• Yes, those macros are outside of setup()
• Good to know
• There’s some code I’ve omitted here - in some cases we hard code the credentials in.
I’m showing the case here where it isn’t hardcoded in. But I suppose that should be within the conditional
• How many seconds would you suggest ? In my testing 4s seemed sufficient, so I set it to 6s.
Either way, seems irrelevant to the problem statement on hand ?
• Again, present in the code snippet that I omitted. Updated code below.

I must’ve missed the answer to my question though - why the inability to pass credentials on 0.7.0 but it was fine on 0.6.3 ?

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

setup( ) {

	WiFi.on( );
	WiFi.listen(false); // Not needed per earlier comments
    // Conditional where sometimes Credentials are hardcoded in and sometimes not
	WiFi.connect(WIFI_CONNECT_SKIP_LISTEN); // Trying to connect with previously saved credentials
    waitFor(WiFi.ready, 6000);

    debugPrint(System.freeMemory( ));

	if (!Particle.connected( )) { Particle.connect(); WiFi.listen(true); }
	
}

loop( ) {

	debugPrint(System.freeMemory( ));

	if ( WiFi.ready( ) ) { WiFi.listen(false);           						                 } // Never true
	else 	             { debugPrint(System.freeMemory( )); debugPrint(WiFi.hasCredentials( )); }
	
}

I guess my point is - WiFi.hasCredentials() and WiFi.ready() on 0.7.0 are never true, which seems to be the underlying problem. How do I fix that to begin with ?

I can assure you WiFi.ready() does work for me on a Photon running 0.7.0
Try this
https://go.particle.io/shared_apps/5c102f8a63a1cafcea000025

With this test sketch you can see the state of WiFi.ready() via the D7 LED.
When you hit the SETUP button you can connect and disconnect and see how that affects the LED.
Also, when you look at the serial output you’ll see that WiFi.hasCredentials() actually returns true.

But maybe your device is not actually running 0.7.0 correctly.
when running particle serial inspect on a properly upated device this is what you should see

>particle serial inspect
Platform: 6 - Photon
Modules
  Bootloader module #0 - version 101, main location, 16384 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
  System module #1 - version 207, main location, 262144 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
  System module #2 - version 207, main location, 262144 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
      System module #1 - version 207
      Bootloader module #0 - version 7
  User module #1 - version 5, main location, 131072 bytes max size
    UUID: DEE6819EFDB0167F0B4F437501CCE2934A02C01D0FE01971D39BA61B8A58591E
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
      System module #2 - version 207
  empty - factory location, 131072 bytes max size
1 Like

I get the same - plus another section in the factory location :

Platform: 6 - Photon
Modules
Bootloader module #0 - version 101, main location, 16384 bytes max size
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #1 - version 207, main location, 262144 bytes max size
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #2 - version 207, main location, 262144 bytes max size
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #1 - version 207
Bootloader module #0 - version 7
User module #1 - version 5, main location, 131072 bytes max size
UUID: 5A5BB8268633E37EB18765729D0AFCE0974CBA60101787E136DDA6EA3F88AACA
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #2 - version 207
User module #1 - version 4, factory location, 131072 bytes max size
UUID: C82B31D0324902A80DF0BFF802A809F0C4FF02A80DF072F8384609F0D0FF2C49
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #2 - version 21

Is there convincing evidence that this cannot be a memory issue ? 4592 seems really low … Also - notice how the memory comes back up to ~24k at the moment I enter the Credentials - it stops listening (but hasCredentials is never true)

statePairing memory: 4592
Pairing 1 memory: 4592
check_ConnectedtoRouter false
Not connected to Router. Free memory: 4592
WiFi Ready: 0
WiFi SSID:
WiFi IP Add: 0.0.0.0
WiFi RSSI: 0
Paired ? 0
Particle ? 0
Listening ?1
WiFi Credentials: 0

statePairing memory: 4592
Pairing 1 memory: 4592
check_ConnectedtoRouter false
Not connected to Router. Free memory: 25152
WiFi Ready: 0
WiFi SSID:
WiFi IP Add: 0.0.0.0
WiFi RSSI: 0
Paired ? 0
Particle ? 0
Listening ?0
WiFi Credentials: 0

statePairing memory: 25152
Pairing 1 memory: 25152
check_ConnectedtoRouter false
Not connected to Router. Free memory: 25152
WiFi Ready: 0
WiFi SSID:
WiFi IP Add: 0.0.0.0
WiFi RSSI: 0
Paired ? 0
Particle ? 0
Listening ?0
WiFi Credentials: 0

AFAIK there is no room for a factory image on the Photons, hence there shouldn’t be anything there.

Note - the exact same code (no changes whatsover) - compiled for 0.6.3 and flashed onto the Photon device, does work.

Note how the memory in listening mode is a lot higher now, around ~16k.

statePairing memory: 16244
Pairing 1 memory: 16244
check_ConnectedtoRouter false
Not connected to Router. Free memory: 16244
WiFi Ready: 0
WiFi SSID:
WiFi IP Add: 0.0.0.0
WiFi RSSI: 0
Paired ? 0
Particle ? 0
Listening ?1
WiFi Credentials: 0

statePairing memory: 16244
Pairing 1 memory: 16244
GOT NEW CREDENTIALS. Max 6s wait.
Live SSID
Max 10s wait for Particle…

And just to be sure it wasn’t related to the factory image, I re-did particle serial inspect - with the same results.

So I don’t think this is the root-cause (even though unusual per your feedback).

Platform: 6 - Photon
Modules
Bootloader module #0 - version 11, main location, 16384 bytes max size
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #1 - version 109, main location, 262144 bytes max size
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #2 - version 109, main location, 262144 bytes max size
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #1 - version 109
User module #1 - version 4, main location, 131072 bytes max size
UUID: 4FC6A03D24075E82A63B10D2FA6DF33B63F2F58AE34C4F4BAA93CFB23D599370
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #2 - version 109
User module #1 - version 4, factory location, 131072 bytes max size
UUID: 0B085856002023230B08E73F0B08E40400204C230B085C050020080300201C56
Integrity: PASS
Address Range: PASS
Platform: PASS
Dependencies: PASS
System module #2 - version 21