Connect Particle to Wifi in code

hi Scruff -

Many thanks, let me implement it quick, I will let you know :blush:

1 Like

Scruff -

Seems to work fine, just posting the value twice but I will look into this :raised_hands: Extremely grateful!

Now just adding all the bells and whistles again and then I can finalise this product and move on to my second project :slight_smile:

Kind Regards,
Friedl

ps: Really appreciating the help from this community, much better from my previous ‘environment’

2 Likes

HI Scruff -

I am attempting to set credentials and flush current WiFi Settings in order for me to deliver the product in such a way that on startup units will connect to WiFi. I would like to achieve this without having to open the units in front of the client.

After much Google’ing and reading it seems I should have this outside of setup();

SYSTEM_MODE(SEMI_AUTOMATIC);

Then followed by the next code in setup()

WiFi.on(); 

if (!WiFi.hasCredentials()) {
      WiFi.setCredentials("SSID", "password", WPA2, WLAN_CIPHER_AES);
      WiFi.connect();
      waitUntil(WiFi.ready);
      Particle.connect();
 }    

After flashing however the Photon restarts and start by blinking Blue, almost breathing not blinking?

Am I doing something wrong here?

Many Thanks
Friedl.

That would be expected
https://docs.particle.io/tutorials/device-os/led/photon/#wi-fi-module-not-connected

Since you only call Particle.connect() when there were no credentials the device will remain in that state forevere whenever you have credentials stored.
I'd suggest you move the closing curly breace before WiFi.connect() :wink:

Scruff -

DAMN Curlies… :smiley:

Thanks!!

Hi Scruff -

Is this correct?

WiFi.on();

if (!WiFi.hasCredentials()) {
WiFi.setCredentials(“SSID”, “password”, WPA2, WLAN_CIPHER_AES);
}
WiFi.connect();
waitUntil(WiFi.ready);
Particle.connect();

Thanks again for having so much patience :slight_smile:

That looks better :+1:

1 Like

Let me try :smiley:

Hi Scruff -

I get the following error;

stray ‘\342’ in program

And a couple more?

That’s probably because you were copy pasting typographic double quotes (“ or ”) instead of (").

If you look at the code highlighting you’ll see that the string is not recognised correctly.

Scruff -

Tired eyes… thanks!!

I will amend and see if it compiles.

Working like a charm… just hopping the client got their credentials correct as they were not sure what I was talking about when asking WPA2 and AES :smile:

Hello all, I have an HTML file(Web APP) that contoles Photon I/O s.
I need to allow the clients to update their WiFi credentials through this Web APP
5 minutes after power-up if firmware does not find wifi it will put Photon in AP mode. The client would have to then connect to the Photon as a router and will follow the same steps as in the manual push-button procedure except he will not be able to claim the Photon
If 5 minutes after power-up, Photon does not receive any credentials it will go back to the client mode and search for the old WiFi for 5 minutes. What I am saying may not be the way to go about it. But client needes to be able to update Wifi credentials through my web app and my associated Firmware
Would you guys be kind enough to help me please, Tanks
PS: If it is easier I can add push button connected to an I/O or rest
pin
to put the Photon in AP mode. Of course, I have to set the Photon to run my code without a WiFi connection