-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added multi WiFi saving feature #3705
Conversation
Up to 5 for ESP32 and Up to 3 for ESP8266 based devices
Thank you. Will have a look ASAP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is nice but I find implementation a bit inefficient.
There are multiple areas that need addressing.
I particularly do not like static memory allocation and handling of JSON. Unfortunately I did not delve in JavaScript and settings page due to lack of time. I will comment on those at some later time.
The only way to change the SSID is by deleting it and then adding it again
Also, improved the way of saving the WiFi into the json config. Note: Lost backward compatibility with IP settings
Now we don't use Delay() for waiting a connection before trying the next network
Bug 1: Deleting a middle WiFi could lead to delete the wrong WiFi Bug 2: Deleting a middle WiFi could leave an empty space between the remaining WiFis
@blazoncek I've implemented all the changes that you requested until now. Feel free to add more feedback to it. |
Closed in favour of #3709 |
(Note: This is a rebase of #3703 with the 0_15 branch)
TL;DR:
This PR adds the Multi-Wifi saving feature, which was requested and discussed in #2845, #2974, #852, #1228, and other issues that I may not found.
How it works:
User's side
For the user I tried to make it as simple as possible: Now the WiFi setting page will have three "new" sections:
In back-end
Nowadays WLED saves the WiFi setting in two global vars: clientSSID and clientPass. Both are strings (well... Char array). Now, I removed these vars and created three new ones: clientNetsSSID, clientNetsPass and clientSavedNets. The first two are almost the same as the old vars, but now they're Strings Array (or Char Matrix, or Char Array Array, or whatever you want to call it), which can save up to 5 Networks in ESP32, or 3 in ESP8266 (those limits were selected arbitrarily). While clientSavedNets is a Byte that stores how many networks are saved and loaded into memory.
When WLED wants to connect to a network, it first scan for every nearby networks and start looking for the nearest saved network. Then, tries to connect to it, and if it can't, then try with the next near one. Each attempt has like 5 seconds before failing. This amount of time was selected because "Last reconnect too old" message was being fired immediately with anything greater than 5 seconds and with just one network.
Backward compatibility
Now WLED will check if the config file has a network saved with the last scheme, and if there's, then it will add it as the first network and then it'll save the config file with the new scheme
Drawbacks
Because I'm not familiar with Improv and EEPROM saving in WLED, and because of backward compatibility concerns, in both cases it'll set/load the first network. For example:
This shouldn't be a big issue for most users, except for those who uses Improv/EEPROM and wanted to save multiple WiFi networks.
Also, as mentioned before, now the IP Settings will affect to every network, even if the subnets differs com each others.
Files Changed:
ssid%d
andpsk%d
, where%d
goes from 0 to 4, instead ofssid
andpsk
respectivelyWLED_MAX_SAVED_NETWORKS
,SUBPAGE_MAIN_SETTINGS
, andSUBPAGE_WIFI_NETWORKS
constantloadJS()
function to letting load more than one JS.input[type="password"]
to the sameinput[type="text"]
style.getSettingsJS
tovoid getSettingsJS(byte subPage, char* dest, byte subSettings);
, so it can load sub-settings from the same page.clientSSID
andclientPass
global vars withclientNetsSSID
andclientNetsPass
respectively.clientSavedNets
global var.WLED_WIFI_CONFIGURED
will be true if the first network is configured, or ifclientSavedNets
is greater than zero.serveSettingsJS
will accept thes
argument for loading sub-settings from the same page.s
is zero (default behavior). It'll return theGetV
JS function. Otherwise, it'll return theGetW
one.SUBPAGE_WIFI_NETWORKS
sub-setting inSUBPAGE_WIFI
page. In this case, it'll return a tuple of three where the first item is the amount of saved networks, while the second item is the maximum amount of networks that can be saved, and the last item is an array of every saved network.