Problems in handling WiFI credentials

Hi guys,
I think I’m having an issue with the function “WiFi.clearCredentials()” or/and when the Photon works as Acces Point with “WiFi.listen()”.
Through serial communication I send a command which sets a flag and then, in the loop() function, “WiFi.clearCredentials()” and “Wifi.listen()”.

loop()
{

//OTHER CODE

if(clearCredFlag) {
WiFi.clearCredentials();// I want only one wifi stored
delay(100);
WiFi.listen();
delay(100);
}

}

In this way the Photon goes correctly in AP (blinking blue) and waits the new WiFi credentials but when I connect to it doesn’t respond. A message from your app appears and says:

Error
Please try running setup again after resetting your Photon and putting it back in blinking blue listen mode if needed.

If I press the reset the Photon goes correctly on listen mode as soon as is called WiFi.connect() (I’m in semi-automatic mode) but I receive the red SOS blinking when I try to connect and set the credentials (with the app).
If I press the setup button untill blink fast blue (manually clean credentials) then the app can connect to the Photon and I can set a WiFi credential.

I’m using software timers but they do nothing until I got new WiFi credentials.

I think something goes wrong when I clear the WiFi credentials. Probably they get corrupted somehow.

Some questions:

1)Have you some advise? Are there differences between WiFi.clearCredentials() + WiFi.listen() and pressing the setup button for more than 10s?

2)Instead of using the device setup library in my app is it possible to use directly UDP and/or TCP communications with the app (the classes UDP and TCPclient) to set WiFi credentials?

  1. I tried to use the Soft HTTP Pages sample (here) to set Wi-Fi credentials through a web browser interface, but it works correctly only with a simple firmware. When I merge my FW with that sample, the web browser gives me some errors while loading the page, namely it seems that it can not load some css or js files ("/rsa-utils/jsbn_2.js" , etc.)
    Do you have any hint about why this behavior occurs and what I could do to make it work with my FW?

Thank you very much
Claudio

Befor clearing the creds, try WiFi.disconnect()

Yes, you could.

That mainly depends on your particular project. I’ve got multiple other projects that also support SoftAP pages and they work fine.

Thank you ScruffR for your very fast response!
I just tried the WiFi.disconnect() before clearing credentials but it’s the same (Error message from the app and SOS when I try to set creds after resetting the Photon and blink blue after WiFi.connect()).

About using UDP and TCP classes in listen mode (Photon IP is 192.168.0.1 and mine is 192.168.0.2), I implemented a simple UDP and TCPclient communications (send and receive). They echo the message on the port where they receive it, but seems they don’t work. I use protocols in the FW already so I reused parts of the code which work.

Probably only specific ports are availeble for communication?

Not in Listening Mode but in normal application mode.

Can you post a gist or a link to a project file that exhibits the problem?

I’m sorry, I was thinking about using UDP / TCP in listen mode instead of the device setup library.

Which problem? the first one or the UDP/TCP in listen mode?

Your original one.
I’d think if you can get over that you won’t need UDP/TCP in Listening Mode, right?

Yes, if I can set/clear creds without this problem, I don’t need UDP/TCP in listen mode. On the other hand, the firmware is quite big and I think it’s an unnecessary effort for you to look at the whole code. However, I enter the listen mode only in the loop, with the flag clearCredFlag set through a command sent via serial communication:

I’d like to try to use also the HTTP page. Has it ever happened that the browser could not load the .js file or .css of the HTTP page?

Nope, I never saw this problem.
I’ve heard of iOS and Android users which could not connect to the SoftAP at all, but not that.