Browse Source

Fix Wifi AP

Benjamin Harris 1 tháng trước cách đây
mục cha
commit
e1fddc4825
2 tập tin đã thay đổi với 26 bổ sung6 xóa
  1. 14 3
      CLAUDE.md
  2. 12 3
      ModulosDSP_101.ino

+ 14 - 3
CLAUDE.md

@@ -37,9 +37,20 @@ Credentials are stored in NVS using the `Preferences` library (namespace `"wifi"
 
 **Boot sequence:**
 
-1. `loadWifiCreds()` reads from NVS. If the `ssid` key is empty (first boot or after a reset), `startConfigAP()` is called — it never returns.
-2. Otherwise, `WiFi.begin(s_ssid, s_pass)` is called with a 15-second connection timeout.
-3. If the connection fails (wrong password, network not in range), `startConfigAP()` is called.
+1. `loadWifiCreds()` reads from NVS.
+   - If NVS has credentials, `s_ssid`/`s_pass` are populated from NVS.
+   - If NVS is empty (first boot or after a reset), `s_ssid`/`s_pass` are populated from the compile-time constants `DEFAULT_SSID`/`DEFAULT_PASS` — so an unattended device reaches the network without the config portal.
+2. `WiFi.begin(s_ssid, s_pass)` is called with a 15-second timeout.
+3. If the connection fails (wrong credentials, network out of range), `startConfigAP()` is called — it never returns.
+
+The compile-time defaults are defined near the top of `ModulosDSP_101.ino`:
+
+```cpp
+static const char DEFAULT_SSID[] = "alfred";
+static const char DEFAULT_PASS[] = "alfred16";
+```
+
+Change these before flashing. NVS credentials (saved via the portal) always take priority over the defaults on subsequent boots.
 
 **Config AP (`startConfigAP()`):**
 

+ 12 - 3
ModulosDSP_101.ino

@@ -69,7 +69,13 @@
 const char* hostname = "modulos-dsp";
 const char* version  = "VER: 260304_13";
 
-// Runtime WiFi credentials — loaded from NVS at boot
+// Compile-time default credentials — used when NVS has no saved credentials.
+// Change these before flashing. If NVS credentials are saved (via the config
+// portal) they take priority over these on subsequent boots.
+static const char DEFAULT_SSID[] = "alfred";
+static const char DEFAULT_PASS[] = "alfred16";
+
+// Runtime WiFi credentials — populated from NVS or defaults at boot
 static char s_ssid[64] = "";
 static char s_pass[64] = "";
 
@@ -710,8 +716,11 @@ void setup() {
   Serial.printf("Reset reason: %d\n", (int)esp_reset_reason());
 
   if (!loadWifiCreds()) {
-    Serial.println("No WiFi credentials stored — entering setup mode");
-    startConfigAP(); // never returns
+    // NVS empty — fall back to compile-time defaults so an unattended
+    // device can reach the network without needing the config portal.
+    strlcpy(s_ssid, DEFAULT_SSID, sizeof(s_ssid));
+    strlcpy(s_pass, DEFAULT_PASS, sizeof(s_pass));
+    Serial.println("No NVS credentials — using defaults");
   }
 
   Serial.printf("Connecting to %s", s_ssid);