Photon - how to provide new WiFi credentials

This will erase/write the credentials with every run of setup, which might wear out the respective memory. You might want to avoid running it like that without further checks.

I run this just once to update my WiFi credentials and flash my program.

1 Like

I recently wrote a blog post that demonstrates how to set wifi credentials via code on your Particle device. Check it out to get some clarification on how best to set wifi credentials from within your Photon code.

Sorry if this has been asked before - and it must have - just cant find the concise answer…
I need to ‘OWN’ all photons that get shipped - to enable OTA updates etc.
The customer must be able to set their own wifi credentials - obviously, but not take ownership.

I assume using the particle ‘apps’ it requires a particle account, and to be logged in, and to have ownership of the photon - or am I wrong?

At worst case - we have access to the Uart so could poke the data in that way using the hosting products display, buts it’s cumbersome as there is no qwerty keyboard available.

Did I miss the best practise in this instance because once the photon leave our premises we are relying on the end user to be able to get it onto their own wifi network.

Hi @rowifi -

This is something that I encounter often as I seldom am “on site” when products are delivered. More so, I do not want to open products on site.

Quick question;

Do you have the WiFi Credentials of your client prior to shipping? I use one of two methods at this stage, I can offer either if I know whether you have this information.

If the customers own iPhones, then yes they can Skip Authentication with the Particle App to setup the wifi.
Particle wants to add this feature to Android but doesn’t have a firm schedule for it.

The Photon also provides a SoftAP feature where it can act a WiFi access point and a user can connect to it with any WiFi client, navigate to 192.168.1.1 which serves a HTTP page to enter new credentials.

https://docs.particle.io/reference/device-os/firmware/photon/#softap-http-pages

2 Likes

We wouldn’t have the wifi credentials prior to shipping.
Additionally: ‘SoftAP HTTP Pages is presently an advanced feature, requiring moderate C++ knowledge.’
I suspect that I could get it going - but I’ve got enough to sort out already.

I’m surprised that the Android Skip Authentication function doesn’t exist yet.
From my viewpoint, Android is as much a used tool as IOS, and sending out pre-owned devices that need new credentials would surely be the norm for any business model except perhaps hobby use,
I can’t see why making it as simple as possible doesn’t already exist for a reasonably mature product.

Note: I seem to remember a few years back that someone in this community made a web application that cleverly provided the setup feature. Anybody know where that might be?

Without even moderate C++ knowledge, you'll probably face more severe problems cobbling together any project on these devices.
When it comes to SoftAP, the example given in the linked docs is a drop-in, fully working project which can be taken as is and you'd only add your own code.

I think you are remembering SoftAP.

2 Likes

Thanks.
I can manage C and C++ enough to get things going. I’ll checkout the soft AP properly.

There was a contribution somewhere definitely that I could create an html webpage that did all the wifi credentials. I remember using it and someone having written the encryption stuff required.
It was several years ago.
It made the laptop connect to the photon and allow credentials to be entered. So yes, I guess it was the SoftAP mode - but I don’t think it needed to log in to a particle account. So in effect it could be hosted on our own webserver and the customer sent there to do the credentials.

I recall trying to whitelabel it without success, I think I was trying to hide reference to photon or particle at the time.

I’m guessing this is pretty much what the web setup does these days - without the white labelling ability?

This would be done in the HTML code that's part of the SoftAP example.

And yes, SoftAP doesn't require a Particle account to work.

Hi @rowifi -

@ScruffR advice of using SoftAP seems to be your best bet. If for some reason you cannot get that going, here is some code that have used recently:


STARTUP(WiFi.setListenTimeout(300)); // exits listen mode after 5 minutes 
unsigned long old_time = millis();            // setup WiFi connecting before entering Listening Mode

Void Setup();

//Your Code//

Void loop();
{ 

// == ENTER lstening mode if no current Wifi credentials are not valid == //
     if(millis() - old_time >= 20000 && millis()) {
             if(!WiFi.ready()){
                 WiFi.listen();
             }
      }
}

Please refer to the full code here on Github as @ScruffR pointed out some errors in my code above :see_no_evil:

Once you you cleared WiFi credentials and you restart the device I will enter listen mode if it cannot connect to WiFi. This also helps for when your client have the WiFi credentials charged for some reason i.e. Password change, new router etc. Client can now use the Particle App to connect the device to new WiFi credentials.

SoftAP still sound like a more solid solution though :slight_smile: Full disclosure, I have very moderate knowledge of C++ and the Android Particle app. That said, this product was delivered to a Client with Android and they had no problems assigning new WiFi credentials.

ps: I also had a case where I had to deliver fully assembled (closed) and tested product to a client, but without any credentials and in listening mode. If this can help I will gladly send you the code.

Hope something makes sense. Best of luck!!
Friedl.

Thanks again everyone - I’ll plod on… gotta get the stuff ready for an exhibition this week!!

I believe this is the SoftAp web app that you were remembering.

Yes thats’s the one. Well done!

1 Like

IIRC, that’s actually the one that’s featured in the docs :wink:
With the “difference” that his web page (with dependencies) is hosted on the device.

1 Like

Not sure what that post is referring to and how it contributes to this thread.

Hello sir, How can I code the device to automatically enter listening mode after a certain time without a WiFi connection?
Thank you very much Sir this is a very important comment just what I was looking for. Do you have to set Photon to run code without Wifi, to begin with?
Could you possibly share the code with us, please
I would appreciate your help

Thank you Mr. Mooors7, once Photon is in listening mode how can I
set a timeout if my code is not running anymore