Hi,
fist of all, I love WLED and recently build 4 LED columns / bar / tube / pipe or whatever it is called
These LED columns need to work in our home from the local network but also from another router whenever I take them for a party. So I would like the support of multiple SSIDs so that I don’t need to reconfigure the columns each time.
Since this feature is not supported, I made my own simple implementation. It is far from perfect, but it works for me. it supports two SSIDs and passwords but could easily be extended. If one SSID is configured, there is no difference with the current way of working. For multiple SSIDs, there is a penalty of 10 seconds between attempts to connect to connect multiple SSIDs. With no connection, the fallback to AP mode still works.
The SSID names are separated by a ‘,’ in the configuration, the same holds for passwords. E.g “ssid1,ssid2” and “passw1,passw2”. Make sure they are in the same order. The maximum number of characters specified for the SSID array and password array can be increased if you like. There is no check that the input will fit the array, so be carefull.
The code that needs to be adapted is in wled.cpp:
The original call to WiFi.begin needs to be replaced by:
std::string ssid_str(clientSSID);
std::string passw_str(clientPass);
std::string delim = “,”;
auto start1 = 0U;
auto end1 = ssid_str.find(delim);
auto start2 = 0U;
auto end2 = passw_str.find(delim);
if (end1 == std::string::npos) // Only one SSID specified
{
WiFi.begin(clientSSID, clientPass);
} else
{
//Serial.println (ssid_str.substr(start1, end1).c_str());
WiFi.begin(ssid_str.substr(start1, end1).c_str(), passw_str.substr(start2, end2).c_str());
delay(10000);
if( WiFi.status() != WL_CONNECTED)
{
start1 = end1 + delim.length();
end1 = ssid_str.find(delim, start1);
start2 = end2 + delim.length();
end2 = passw_str.find(delim, start2);
//Serial.println (ssid_str.substr(start1, end1).c_str());
WiFi.begin(ssid_str.substr(start1, end1).c_str(), passw_str.substr(start2, end2).c_str());
delay(10000);
}
}
Give it try if you have the same issue as I have.
WLED rules!
1 Like
srg74
January 13, 2024, 6:14pm
2
If you want to implement this feature to a WLED project make a pull request on GitHub.
Please fork WLED repo, make changes and open a PR.
Hi, this is by far not a good solution to the problem, it is merely a hack to at least solve my problem in the simplest way. I am merely sharing this piece of code to help people with the same issue so it might help them in a simple way.
I have no intend of making this a PR. Maybe when the snow is gone, I will sit down in the sun and try to find a better solution
ALDIY
January 20, 2024, 4:02pm
5
I thought you are the one who made this PR
Aircoookie:0_15
← JPZV:multi_ssid_0_15
opened 08:10PM - 18 Jan 24 UTC
(Note: This is a rebase of #3703 with the 0_15 branch)
## TL;DR:
This PR a… dds 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:
- _Connect to a new network_: Here the user can scan for a nearby network or add it manually with the option "_Other network..._"
- _Saved networks_: Here the user can manage its saved network by changing the SSID, the Password, or deleting it.
- _Addresses settings_: Here is the old DHCP/IP and mDNS settings. Sadly, this will affect to all networks, so, for example, setting a static IP to 192.168.0.64/24 while on _networkA,_ this will be used for every other network, even if the subnet of _networkB_ starts from 192.168.1.0/24. So, DHCP is fully recommended from now on if using multiple networks.
### 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:
```diff
- readStringFromEEPROM( 0, clientSSID, 32);
- readStringFromEEPROM( 32, clientPass, 64);
- readStringFromEEPROM( 96, cmDNS, 32);
+ readStringFromEEPROM( 0, clientNetsSSID[0], 32);
+ readStringFromEEPROM( 32, clientNetsPass[0], 64);
+ readStringFromEEPROM( 96, cmDNS, 32);
```
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:
- **cfg.cpp**: Now the WiFi settings will be saved as `ssid%d` and `psk%d`, where `%d` goes from 0 to 4, instead of `ssid` and `psk` respectively
- **const.h**: Added `WLED_MAX_SAVED_NETWORKS`, `SUBPAGE_MAIN_SETTINGS`, and `SUBPAGE_WIFI_NETWORKS` constant
- **data/settings_wifi.htm**: Added three new sections: _Connect to a new network_, _Saved networks_, and _Addresses settings_. Also, changed the `loadJS()` function to letting load more than one JS.
- **data/style.css**: Added `input[type="password"]` to the same `input[type="text"]` style.
- **fcn_declare.h**: Changed the declaration of `getSettingsJS` to `void getSettingsJS(byte subPage, char* dest, byte subSettings);`, so it can load sub-settings from the same page.
- **improv.cpp**, **set.cpp**, **wled.cpp** and **wled_eeprom.cpp**: Added support for multiple WiFi settings.
- **wled.h**:
- Replaced `clientSSID` and `clientPass` global vars with `clientNetsSSID` and `clientNetsPass` respectively.
- Added `clientSavedNets` global var.
- Now `WLED_WIFI_CONFIGURED` will be true if the first network is configured, or if `clientSavedNets` is greater than zero.
- **wled_server.cpp**: Now the function `serveSettingsJS` will accept the `s` argument for loading sub-settings from the same page.
- In case `s` is zero (default behavior). It'll return the `GetV` JS function. Otherwise, it'll return the `GetW` one.
- **xml.cpp**: Added support for `SUBPAGE_WIFI_NETWORKS` sub-setting in `SUBPAGE_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.
It turned out to be rather simple to implement this. The only real work was to make UI as comfortable as possible, while providing all options.
Here’s my attempt.
Aircoookie:0_15
← Aircoookie:multiwifi
opened 11:32PM - 20 Jan 24 UTC
- similar/alternative to #3705
- solves #2845, #2974, #852
1 Like