logo elektroda
logo elektroda
X
logo elektroda

How do I save an empty password in the code? Wi-Fi configuration.

pier 1296 13
ADVERTISEMENT
This content has been translated flag-pl » flag-en View the original version here
  • #1 19736135
    pier
    Level 24  
    Hi.
    I have a program that allows me to set up a wifi connection from a browser. Sketch works fine but I am fine with configuring without a wifi password for some reason. I have corrected the program to the point that it ingests the configuration without a password but after that esp crashes and I have to give it a manual reset. After that it works fine. Probably the program crashes on trying to save a blank password. I have added comments in the code where I made the changes.
    I would not like to throw away the original functionality just to add the ability to save a blank password.
    Can you suggest a solution?

    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #2 19736727
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #3 19736737
    pier
    Level 24  
    khoam wrote:
    pier wrote:
    I wouldn't want to throw away the original functionality just add the ability to save an empty password.
    .
    If it's going to be "blank", why save it? Are you talking about logging into an open WiFi network?
    .
    You have to save something because otherwise the "configurator" doesn't execute. This is how I want to log in to the open network, for now at least but this will change in the future.
  • #4 19736757
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #5 19736904
    pier
    Level 24  
    khoam wrote:
    Insert after line:
    Code: C / C++
    Log in, to see the code
    .
    in addition:
    Code: C / C++
    Log in, to see the code
    .
    What value is shown:
    .

    Value = 0

    This is the end of the record from the monitor serial:
    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #6 19737431
    Anonymous
    Level 1  
  • #7 19737436
    pier
    Level 24  
    khoam wrote:
    Strange, but it looks like the WTD is being triggered due to insufficient current capacity of the ESP power supply and a drop in supply voltage.
    .
    And wait wait wait because I am powering from the adapter already switching on the battery power.

    But no, correct power supply doesn't change anything. Still the same serial message and crashes.
    After the sequence turn off on correctly connects to the open network.
  • #8 19737594
    Anonymous
    Level 1  
  • #9 19737615
    pier
    Level 24  
    khoam wrote:
    Instead of EEPROM.commit() type:
    Code: C / C++
    Log in, to see the code
    .
    I'm curious if it's on commit that it crashes. A properly executed commit returns true, so it should display "1".


    It displays "1⸮"
  • #10 19737625
    Anonymous
    Level 1  
  • #11 19737639
    pier
    Level 24  
    khoam wrote:
    This next command that can trigger WTD is just ESP.reset() :) .
    Maybe try using ESP.restart().


    Didn't help. WDT reset twice and it hangs.

    Code: C / C++
    Log in, to see the code
    .

    I think I'll let it go. For testing it will be what it is and then I'll secure the network anyway because I'll have neighbours eventually.
  • #12 19737641
    Anonymous
    Level 1  
  • #13 19739530
    pier
    Level 24  
    khoam wrote:
    For the record, before ESP.reset() or ESP.restart() there should be an EEPROM.end() command and a WiFi stop.
    .

    Khoam but before my code modification these commands were not there and everything worked as expected.
  • #14 19739535
    Anonymous
    Level 1  

Topic summary

✨ The discussion revolves around a programming issue related to saving an empty password for Wi-Fi configuration using an ESP8266 module. The user has modified their code to accept a blank password for connecting to an open Wi-Fi network but encounters crashes after attempting to save this configuration. Responses suggest troubleshooting steps, including checking EEPROM commit behavior, ensuring proper power supply, and using commands like ESP.reset() and ESP.restart(). The user reports persistent issues despite these adjustments and considers reverting to a secured network in the future.
Generated by the language model.

FAQ

TL;DR: On ESP8266, EEPROM.commit() should print 1 on success; "A properly executed commit returns true." Handle zero‑length passwords, finalize EEPROM, and avoid immediate ESP.reset() to prevent WDT resets. [Elektroda, khoam, post #19737594]

Why it matters: This helps ESP8266 makers fix WDT resets when saving blank Wi‑Fi passwords and connect to open networks reliably.

Quick Facts

How do I save an empty Wi‑Fi password on ESP8266 without crashing?

Accept a zero‑length password in your handler. After writing SSID/pass and calling EEPROM.commit(), call EEPROM.end(). Stop Wi‑Fi, then call ESP.restart() instead of ESP.reset(). This sequence preserves your original behavior and prevents post‑save WDT resets during the HTTP handler. [Elektroda, khoam, post #19737641]

Why does the board WDT reset right after saving settings?

Calling ESP.reset() inside the request handler can trip the watchdog. Use ESP.restart() for a cleaner reset path after closing resources. As the expert noted: "This next command that can trigger WTD is just ESP.reset()." [Elektroda, khoam, post #19737625]

Do I need to save anything for an open Wi‑Fi network?

Your flow may require it. As the author confirmed: "You have to save something because otherwise the 'configurator' doesn't execute." If your UI or boot logic expects stored credentials, keep SSID and store an empty pass. [Elektroda, pier, post #19736737]

What length should I expect for an empty password from the form?

Expect qpass.length() to be 0. The serial log showed: "Value = 0" followed by WDT resets, confirming the handler received an empty string and then crashed later. [Elektroda, pier, post #19736904]

How do I confirm EEPROM saved credentials successfully?

Print the result of EEPROM.commit(). A correct save prints 1, meaning true. As the helper put it: "A properly executed commit returns true." If you see 1, your crash likely occurs after commit, during reset/cleanup. [Elektroda, khoam, post #19737594]

How do I connect to an open Wi‑Fi network in code?

Use WiFi.begin(ssid) without providing a password. This form joins open networks and aligns with accepting an empty pass in your configurator. [ESP8266WiFi — WiFi.begin()]

How long does this sketch wait for Wi‑Fi, and can I change it?

It waits 10 seconds: 20 attempts with 500 ms delay in testWifi(). Increase reliability by raising the loop count or delay. Example: double the attempts for 20 seconds of total wait time. [Elektroda, pier, post #19736135]

Could power supply issues cause WDT resets here?

Yes. Low supply capacity can cause voltage dips and watchdog timeouts. As noted: "it looks as if the WTD is triggered due to insufficient current capacity of the ESP supply." Use a stable 3.3 V source with adequate peak current. [Elektroda, khoam, post #19737431]

Whats a safe reset sequence after saving credentials?

Follow this quick sequence:
  1. EEPROM.commit(), then EEPROM.end().
  2. Stop Wi‑Fi cleanly.
  3. Call ESP.restart() instead of ESP.reset(). This reduces watchdog trips in the HTTP handler. [Elektroda, khoam, post #19737641]

Should I clear EEPROM before writing new SSID/password?

Yes. The sketch clears the first 96 bytes, then writes SSID and password. That avoids mixing old and new bytes and keeps reads clean on next boot. [Elektroda, pier, post #19736135]

How can I quickly reproduce and diagnose the issue?

Add serial diagnostics in the handler. Print qpass.length() to confirm empty input. Then save and observe the serial output to locate the stage of failure. This isolates form parsing from storage and reset behavior. [Elektroda, khoam, post #19736757]

Why does it connect after a power cycle but crash immediately after save?

A full power cycle starts cleanly, so saved open‑network credentials work. The crash stems from the immediate post‑save reset path. Fix the handler exit by finalizing EEPROM and stopping Wi‑Fi before restart. [Elektroda, pier, post #19737436]
Generated by the language model.
ADVERTISEMENT