feat: refine portal flow and examples

This commit is contained in:
2026-09-03 18:54:41 +10:00
parent f8b87f7865
commit 2fec33b952
42 changed files with 870 additions and 212 deletions
+9
View File
@@ -0,0 +1,9 @@
# Station Profiles
This example gives WiFiManager a small application-owned EEPROM store. The portal accepts a required primary Wi-Fi network and an optional fallback, verifies a submitted network before saving it, then remembers the last successful choice across restarts.
On a blank board, connect to **WiFiManager Profiles** with password **example-pass** and open `http://192.168.4.1/`. Enter a primary network and, if useful, one fallback. After a successful connection, restart the board to confirm that it tries the saved profiles before reopening the portal.
`StoredProfiles` is intentionally simple so the ownership boundary is visible. A production application should add its own record versioning and integrity protection around the application’s complete configuration; WiFiManager only owns network-selection policy.
See [Station profiles](../../docs/STATION_PROFILES.md) and the shared [example guide](../README.md).
@@ -0,0 +1,63 @@
#include <Arduino.h>
#include <EEPROM.h>
#include <WiFiManager.h>
namespace {
constexpr uint32_t kStoreMagic = 0x574D5031; // "WMP1"
struct StoredProfiles {
uint32_t magic;
WiFiManagerStationProfiles profiles;
};
class EepromProfileStore final : public WiFiManagerStationProfileStore {
public:
bool begin() {
#if defined(ESP32)
return EEPROM.begin(sizeof(StoredProfiles));
#else
EEPROM.begin(sizeof(StoredProfiles));
return true;
#endif
}
bool load(WiFiManagerStationProfiles& profiles) override {
StoredProfiles stored{};
EEPROM.get(0, stored);
if (stored.magic != kStoreMagic) {
return false;
}
profiles = stored.profiles;
return true;
}
bool save(const WiFiManagerStationProfiles& profiles) override {
EEPROM.put(0, StoredProfiles{kStoreMagic, profiles});
return EEPROM.commit();
}
bool clear() override {
EEPROM.put(0, StoredProfiles{});
return EEPROM.commit();
}
};
EepromProfileStore profileStore;
WiFiManager portal;
} // namespace
void setup() {
Serial.begin(115200);
if (!profileStore.begin()) {
Serial.println("Could not initialise EEPROM profile storage");
return;
}
portal.setStationProfileStore(&profileStore);
portal.setStationRecoveryInterval(30000);
portal.startStationConnection("WiFiManager Profiles", "example-pass");
}
void loop() {
portal.process();
}
+26
View File
@@ -0,0 +1,26 @@
[platformio]
default_envs = esp8266
src_dir = .
[common]
framework = arduino
lib_ldf_mode = deep+
lib_deps =
WiFiManager=symlink://../..
[env:esp8266]
extends = common
platform = espressif8266
board = d1_mini
platform_packages =
platformio/framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#521ae60a89e64bb0d1eb7a0b7addf620ced5cad3
[env:esp32]
extends = common
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.05/platform-espressif32.zip
board = esp32dev
build_unflags = -std=gnu++11
build_flags =
-std=gnu++14
-DSOC_WIFI_SUPPORTED=1
-I${platformio.packages_dir}/framework-arduinoespressif32/libraries/Network/src