I have several systems with Photons that will be moved from location to location and I prefer not to require a laptop. I had mistakenly assumed that the Particle app could be used to provide new credentials once the Photon was in setup mode.
I’ve read through several discussions about the topic, but would like to know the current thinking of best practice to address this situation. In other words, how do I provide a Photon with new WiFi credentials without having to change the application or drag along a laptop? If there are some code examples, that would be great! Thanks in advance for newbie assistance!
I’ve kind of discovered the following. If I hold the SETUP button until the light blinks blue (Listening mode), I’m then able to tap the “+” key on the Particle app and setup the WiFi credentials. I chose to use the same name as before and all seems good.
So…is this an acceptable way to provide new credentials or am I setting myself up for pain? One of my devices is in a very small enclosure that does not facilitate getting to the SETUP button. However, I can redesign around that issue if the above solution is appropriate.
@ctmorrison Yes, that method is going to be the best to accomplish changing WiFi connections with out needing a laptop with you. Same goes for the one device in the small enclosure.
That should indeed work. That’s kind of how it’s intended to work as well. Entering listening mode allows you to (Re)configure your credentials.
If necessary you could code the device to automatically enter listening mode after a certain time without a connection. That way, you wouldn’t have to access the setup button. Make sure you add a timeout to that, so unintentional network disruptions don’t cause your device to ‘hang’ in listening mode indefinitely.
If you go to the wifi section of the reference documentation (https://docs.particle.io/reference/firmware/photon/) you will see that there several functions that can manipulate the stored access point login details.
From there I have developed this algorithm (below) that loads five SSID/password pairs from a string array (apGroup) that stores the required APs in preference order. This routine reverses the loading order to ensure the required priority is used.
The Photon moves automatically between these AP’s seemingly only when the signal becomes insufficient to maintain the current connection.
Is someone had figured out how this code works ? I’m trying to understand and he should be really great to have a code like that to add new credentials to our beloved boards.
For now, I retro-engineering this part of the code :
char* SSID = "your SSID";
char* PASSWORD = "your PASSWORD";
#define led1 D7
void setup() {
Serial.begin(9600);
Serial.print("Loading ...");
pinMode(led1, OUTPUT);
flashLED();
WiFi.disconnect();
WiFi.on();
waitFor(Serial.isConnected, 10000);
WiFi.setCredentials(SSID, PASSWORD);
}
void loop() {
while (!WiFi.ready()){
Serial.println("Attempting to connect to WiFi...");
delay(1000);
Serial.println("-----------------------------");
Serial.println("Try again in 5 seconds...");
delay(5000);
}
Serial.println("Photon is up in the sky !");
}
int flashLED() {
for (int i = 1:5) {
digitalWrite(led1, HIGH);
digitalWrite(led1, LOW);
delay(250);
}
}
What about the waitFor part ?? what is this function ?
And the more important, I would like to know how to load a code in my photon without using the WiFi.
Yeah tks Moors7 but I dont have all the knowledge to understand all the informations in the docs sometimes. And I’m a bit in a rush for a school project… I’ll give another look so.
I’m actually a bit stumped by the use of waitFor() in conjunction with Serial.isConnected but just reading it literally, this would wait for up to 10 sec (=10000 milliseconds) for a serial connection via USB before proceeding to catch all the output.
Not too difficult to grasp IMHO
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 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.
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.