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

Reduce WiFi memory consumption #295

Merged
merged 9 commits into from
Feb 7, 2024

Conversation

laszloh
Copy link
Contributor

@laszloh laszloh commented Feb 4, 2024

This PR removes the WiFi settings from the RAM entirely. To improve the performance, the NVS storage is modified:

  • own namespace for the settings
  • 1 key / Network

One WiFiSettings entry is serialized the following was:
[str:ssid] + [str:password] + [binary:static IP]

Strings use: [u8:len] + [len*u8:string] + [u8:'\0']
Static IP use: [u8:bool] + <u8 * 20:static IP block>

This allows to NVS iteration over all entries without the need to load all entries into RAM. Old WiFi settings will be migrated to the new NVS storage structure.

For discussions see: https://forum.espuino.de/t/pr-diskussion-wifi-settings-ram-reduktion/2763

@laszloh laszloh marked this pull request as draft February 4, 2024 22:06
@laszloh laszloh force-pushed the feature/wifi-memory-reduction branch 2 times, most recently from c247174 to 7d6c9f6 Compare February 4, 2024 23:14
Load hostname on request from NVS and only use it on the stack.
Minor fixes in the FSM handler functions
By using a linked list we do not need to allocate a single consistent memory block to save the wifi settings.
Fully rework the WiFiSettings struct to a C++ class.
Add function to validate an entry and serialize & deserialize the data directly to the nvs.

Integrate the new class into the Wlan.cpp and Web.cpp.

Add comments to new functions
@laszloh laszloh force-pushed the feature/wifi-memory-reduction branch from 7d6c9f6 to f174460 Compare February 6, 2024 14:54
@laszloh laszloh marked this pull request as ready for review February 6, 2024 14:57
To reduce memory use the NVS entry directly.
Remove synthetic constrain of 10 Network entries since we do not load them into the memory any more.
Add ArduinoJson converters for IPAddress class.
Mark optional support functions with [[maybe_unused]] to supress warnings.
@laszloh laszloh force-pushed the feature/wifi-memory-reduction branch from f174460 to 2c47f25 Compare February 6, 2024 20:32
@tueddy tueddy merged commit 6c58eb2 into biologist79:dev Feb 7, 2024
10 checks passed
@laszloh laszloh deleted the feature/wifi-memory-reduction branch February 8, 2024 11:16
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.

2 participants