Connect to new wi-fi network

hello
i wrote an android app that turn - on and off led.
there is something that I doesn’t understand - if I want to use my device in new place with new unknown Wi-Fi , how can I connect to my photon?
how can I enter the new Wi-Fi password to the photon?
i don’t want to connect with usb to the device - only with smartphone

thanks
moshe

Try this
https://docs.particle.io/guide/getting-started/start/photon/#step-2-connect-with-your-smartphone

To put your device into Listening Mode to set up additional WiFi networks press and hold SETUP till the RGB LED turns blue.

Once you got your device in Listening Mode you can go with the official way (see above link) or use a third party way via this
http://photonsoftap.meteor.com/
Discussion can be found here

4 Likes

Hello
thanks for the answer but i still does not understand-
if i build a product i my home, and i want to use it in new place,
how can i tell the device only with my android app that the photon should looking for new wi-fi network, and to give him the new password.
it is mystery for me - i think i should app BT connection to my product.
what do you think about it - am i wright?

You need to read the docs and links carefully.

If you have your own (selfwritten) app then you can’t use this app to do it.

You either need the Particle app, use one of theSoftAP solutions or have to build the SoftAP logic into your own app (which it obviously has not, otherwise you would not be asking this question ;-)).

And the communication is not BT but WiFi (even in Listening Mode).


The alternative way via your device firmware (by means of WiFi.listen() and WiFi.setCredentials()) would only be available while you got cloud connection, which seems to be not available given your description.
But if you had your device connected to the cloud (e.g. via your mobile phone AP), you might be able to setup a Particle.function() to achieve this.

1 Like

@ScruffR Can you share an example code for the SoftAP solution? Does a device need to be claimed by the some account and/or the claim_code used for configuring and setting Wi-Fi SSID over SoftAP? Can it be done without a claiming/authentication step? TIA.

A working SoftAP demo can be found in the docs and no, your device doesn’t need to be claimed for running SoftAP either.
https://docs.particle.io/reference/firmware/photon/#complete-example

We tried to use the example app for soft AP page to configure the wifi. We were able to see the page after connecting to the Particle’s SSID, but faced a few issues.

  1. When scanning for the networks available, we were seeing a lot of Wi-Fi network names being repeated in the selectable list. Is that a known issue?

  2. We observed that on the same Photon device, configuring the WI-Fi works fine for the first time we use the SoftAP page to configure wi-fi and we can see the connection being established. But using the webpage in subsequent times to connect to a different network does not work (and we do not see the device connected with the network either). Is that a known issue?

I did some digging and it seems that if the SSID is already saved in the device (is it saved in DCT tables?), then the creds are updated in the same entry in the list, but the SSIDs at entry position 0 is used for WLAN connection. Could this be the issue?

PS, we the network is created via mobile hotspot / tethering. Also, the web page handlers are defined and set in the application firmware code.

TIA,
Synergy Labs

That's not an issue per se. I'm in an environment where multiple routers broadcast the same SSID and hance I should see a line per router.

I can't confirm 2 - for me that works just fine.

Where did you find that?
AFAIK (which is based on reading older sources - might need to look in most recent code again) that's not the case. The way how creds are stored only uses the index for the next free slot and doesn't check any already stored SSIDs.

@ScruffR, I found this logic in add_wiced_wifi_credentials call in wlan HAL. PFA the screenshot.

I’ll have to check, since that might pose an issue for cases where you got several networks sharing a common SSID but different passwords.
(I recall another thread where exactly that was discussed … searching)


Update:
Yup, confirmed - that’s the current behaviour. Setting new credentials for any SSID already present replaces the old set of credentials. But I think that is not the best choice.
@jvanier, what do you think?
How would one have different passwords at different locations but still use the same SSID?
e.g. the default Android tether SSID is AndroidAP but every phone might have its own PWD, but with the current logic there seems no way to keep the default SSID (irrespective if that’s good practice) but have a Photon set up to connect to mulitple such APs.
Is this worth a GitHub issue?

I don’t think the Photon should allow configuring different passwords for different locations that use the same SSID. That’s what I see on my phone too for example.

Yup, that’s what I found out too, but is this really clever?
I’m not sure anymore, but I think to remember in the (long gone) past before HAL that was possible.

@scruffr Slightly different query but related to this discussion thread - I am using a modified version of the SoftAP setup process for Wifi. This works pretty well except for 2 points:

  1. If I enter the WiFi network password incorrectly I get no specific feedback - wifi.setCredentials() has no way for returning whether the password is good or not because it hasn’t tried using the credentials at that point, it has just stored them in the wifi module. Are there any ways of checking the password is correct you know of?
  2. The way the SoftAP process works is that to put in listening mode (to create a wifi hotspot) you need to delete all the stored credentials otherwise the device will just try and connect to the first stored wifi it can. This effectively means that only one wifi network can be setup using this method. Have I missed something or is there a way to stop this happening so that the SoftAP method can be used to add wifi networks to the existing one(s) stored already?

This is true when the previously stored WiFi is in reach and your newly added creds don't work.
If the recently added one is the only one in reach, you can be sure the PW was correct when you get a connection.
AFAIK the connection attempts will start with the network added last. So if you check the SSID after a successful connect and if it is the same as you just added, you can be almost certain that the PW was correct.

@ScruffR I get your point, the problem is that this is not easy to provide clear feedback for an end-user because if I have a device that I want to move around between WAPs I can’t be certain that the WAPs are not overlapping when setup is requested so when I call WiFi.listen() if the device has credentials for a WAP in range it will just connect straight away to that WAP and the setup process is not possible. I have 2 wifi setup product types - one with a screen to provide setup feedback and another with just LEDs on the outside of the case. The other situation I have experienced is that the wifi module credentials sometime need to be cleared out - so that requires another setup mode that allows the credentials to be cleared and then listening to start. Definitely need to think a bit more about the logic. Thanks for your insight as always. :wink:

This is not what I experience.
When my program executes WiFi.listen() (even after the device connected to another AP) the device does not (re)attempt to connect to any AP till I either call WiFi.listen(false) (requires SYSTEM_THREAD(ENABLED)) or the SoftAP process finished.
And after that the device will try to connect to the most recently added WiFi first, so when the creds supplied where correct and that network is available, a subsequent (after WiFi.ready()==true) call to WiFi.SSID() should give you the SSID you just entered. If not either the creds were wrong or the network was not accessible (enough) to connect to.

How do you know to end the listening? I currently keep checking for WiFi.hasCredentials() which of course will not work if there are pre-existing wifi credentials stored. Are you checking the number of wifi credentials stored has been increased by 1 using = WiFi.getCredentials(ap, 5)?. I will retest this logic. The SoftAP logic - how are you getting or would you get the SSID selected from that to compare against the Wifi.SSID()? My javascript is not good enough to unpick the rather dense code in that solution.

Since my app runs multi threaded I can keep checking all kinds of ways (e.g. button state, timeout, Serial, Serial1, …) while WiFi.listening()==true.

You can change the setup HTML to send the data back to your app before passing it on to the JS