Switching between multiple WiFi networks


#1

Hi

I am trying to make photon work with multiple networks, each for a different purpose, for my project. Say I could use WiFi A as my main network and use WiFi B as a backup network or use this network to restart the power supply of WiFi A, essentially restarting WiFi A, whenever WiFi A loses internet connection or WiFi A is down for some reason. As a backup network, WiFi B is always powered, meaning photon is able to detect both networks.

I imagine the pseudo-code can be something like:

if (WiFi A loses connection){
WiFi.disconnect();
WiFi.connect(WiFiB, passwordB);
//then with a peripheral connected to WiFi B, restart the power for WiFi A
WiFi.disconnect();
WiFi.connect(WiFiA, passwordA);
}

However, WiFi.connect() is not made to be used that way. Instead, we have WiFi.setCredentials(SSID, PASSWORD); and a separate WiFi.connect(). And, also, WiFi.connect(), in the presence of multiple available networks chooses the connection with the strongest RSSI, and not necessarily as preferred by the user. (Multiple WVLANs)

One approach I’ve seen here in Switching between Wifi devices [Solved] makes use of clearing and setting the credentials of the WiFi Networks. In the same thread, however, …

So, yeah, that’s where I am now. And what I know so far.
And so it boils down to this question:

  1. What is the best way to switch connections between multiple known networks via the code? (I see that this is possible with listening mode in tandem with the mobile app, but as it is for the purpose of a backup network, I believe it is best accomplished as an automatic feature - written in the firmware and no user interaction required)

Thanks in advance!


#2

This is a good question, and I think there is another reason for wanting some more control here. As far as I can tell the Photon insists on connecting to the last configured WiFi point if it can see it. On the unit on my bench it is connected to a network at -80dB thats 20m away with several brick walls inbetween, however it also configured to talk to an AP 2m away with a signal around -40dB, but has chosen not to, this is silly. At -80dB Photons do not work well and are pretty much incapable of carry out OTA updates, and ignoring that I can tell you that attempting to use that -80dB AP on devices with better WiFi reception is not exactly a pleasant experience, both the signal power and the interference form 5 other networks in a shared office space next door conspire against you.


#3

I do recall a discussion about such feature and I thought there already was an open issue about that, but as it turns out there isn’t (or I just couldn’t find it).

Could you open an issue to propose that feature, please?


#4

Thanks.

I’ve already made an issue for the feature. I hope I did it right.
So, I guess, I’ll have to work with the clear and set credentials for now.
If you have any better ideas, I’ll be glad to hear them :slight_smile:

One question though. Is it possible to make a network out of a photon in listening mode - i mean using the softAP? What I mean is, in cases where WiFi A is down, I will connect my photon to another photon which is in listening mode then, maybe the two photon can communicate so that the second photon can make a restart on WiFi A. (Sorry if I’m using the ideas/terms wrongly, I barely have a knowledge regarding this softAP thing)

Thanks!

Tim


#5

Not really since the SoftAP doesn’t really implement a lot of the functionality needed to run a full network, but having one Photon enter SoftAP mode when it loses its “home network” and have another one “subscribing” to that SoftAP SSID should be possible. The trouble with this tho’ is that the communication between the two would be rather cumbersome, since - AFAIK - these two can only communicate via HTTP.


#6

A light! A light! haha
Thanks.

I guess, I’ll just have to learn more. Thanks!


#7

For those who might find themselves wondering about the same inquiry I had.