Connect and add new wifi via Particle.function

Hi all.

I need to implement a Particle.function to add and connect to new wifi.

What is the best practice for adding new wifi credentials with Particle.function and connecting my device to new wifi via Particle.function?

I wrote something that works, but i think that there is a better way of doing it.
will be happy for some advices,
Thanks is advance. :slight_smile:

If you show what you have we may be able to suggest what to improve :wink:
However, youโ€™ll be using WiFi.setCredentials() (with checking the return value for success).
If you want to store creds for a hidden or non-present WiFi network, you need to supply all four parameters to the function.
I usually also call Particle.process() and add some short delay after that, then power-cycle the WiFi module to ensure the new creds taking effect.


Hi ScruffR :slight_smile: thank you for the help!

I had two solutions in mind, the first one was to write a function that recives a string of parameters seperated by a delimiter and parse the recieved string with by that delimiter.
This solution was not so good for a few reasons, one of them is the 32 bytes parameter limit of the particle.function.
Another idea I had was to write a unique function for each argument - first for ssid, second for password etc.
The problem I have with this design is that it seems unefficient (I can only write limited number of cloud functions).
The other thing is, how can I select a WiFi network and connect my photon to it.

That limitation should not apply anymore with 0.8.0-rc.4 and later - it should be now 622byte, but even before it was 63 characters.
So even with the legacy limits you could send a credentials string with a SSID+PWD taking up to 59 characters followed by a two digit number representing encryption and WLAN cipher

You currently canโ€™t select which of the stored credentials will be used. The creds stored last will be the ones tried to connect to first.

1 Like