Skip to content
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 #3703

Closed
wants to merge 35 commits into from
Closed

Added multi WiFi saving feature #3703

wants to merge 35 commits into from

Conversation

JPZV
Copy link
Contributor

@JPZV JPZV commented Jan 18, 2024

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:

  • 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:

-  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.

@JPZV JPZV mentioned this pull request Jan 18, 2024
@blazoncek
Copy link
Collaborator

Thank you.
Please re-base this for 0_15 branch.

@blazoncek blazoncek linked an issue Jan 18, 2024 that may be closed by this pull request
w00000dy and others added 27 commits January 18, 2024 15:05
By adding a random string to the path of the js file every time, we make sure to never hit the browser cache.
By setting the response header "Cache-Control" to "no-store" and setting "Expires" to 0, we make sure the browsers and place calling this never store it in cache.
* purge old (not yet processes) NTP responses
* validate server responses before updating WLED time
* purge receive buffer when package is rejected (avoids mem leak on esp32)
when NTP got enabled via UI, WLED would wait up to 12 hours before issuing the first NTP request.
Fix for UCS8904 hasWhite().
I've found a code spellchecker, so this is what can be corrected easily. Changes are only affecting comments, readme and a few user-visible strings. So no functional impact expected.
if you can spell Fahrenheit, you can't spell Celsius. And vice versa :-)
obuf is reset to nullptr in some cases
PHST abbreviation added for clarity.
According to the technical manual, GPIO 16 + 17 are used for onboard flash, so cannot be used by WLED.

example buildenv:

[env:esp32_pico]
extends = env:esp32dev_qio80
board = pico32
if case of invalid or impossible sunset/sunrise results, retry with the previous day. max 3 days back, to prevent infinite loops and far-away results.
sunset = 0 is a valid result, as the function result is in UTC and not local time .
Example: local time is UTC-8, local sunrise = 08:00am => getSunriseUTC()  = 0.

So we cannot use "0" for "invalid". Using UINT16_MAX resolves the problem, and even allows to simplify calculateSunriseAndSunset() a bit.
Pointed link to current directions for compiling WLED
drasch and others added 8 commits January 18, 2024 15:16
make WS2814 explicit in LED driver drop-down menu
…-dev#3672)

when only two bytes were received in a packet, the "for" condition `packetsize -3` would underflow, leading to an infinite loop.
Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.26.15 to 1.26.18.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](urllib3/urllib3@1.26.15...1.26.18)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Up to 5 for ESP32 and Up to 3 for ESP8266 based devices

Fixed typo in cfg.cpp

Fixed minor bug in Settings_Wifi.html

Minor Bug: If setting a SSID empty, then any followed network will be ignored
@blazoncek blazoncek changed the base branch from main to 0_15 January 18, 2024 19:06
@blazoncek
Copy link
Collaborator

Something went wrong as there are 88 files changed. I cannot review that.
Can you please follow https://github.com/Aircoookie/WLED/wiki/How-to-properly-submit-a-PR and open a new PR? Select 0_15 branch when doing so.

@JPZV
Copy link
Contributor Author

JPZV commented Jan 18, 2024

Something went wrong as there are 88 files changed. I cannot review that. Can you please follow https://github.com/Aircoookie/WLED/wiki/How-to-properly-submit-a-PR and open a new PR? Select 0_15 branch when doing so.

Hi, yes! The rebase went extremely wrong, so I had to clone the 0_15 branch and patch all the files by hand. Right now I'm half way.

I'll open a new PR, so for now I'll close this one as it got corrupted. Sorry for that

@JPZV JPZV closed this Jan 18, 2024
@blazoncek
Copy link
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Two or more WiFi settings
9 participants