[GH-ISSUE #1233] Static ip not working #1056

Open
opened 2026-02-28 01:28:19 +03:00 by kerem · 2 comments
Owner

Originally created by @emredusmez on GitHub (Mar 26, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1233

Basic Infos

Hardware

WiFimanager Branch/Release: Master

Esp8266/Esp32:

Hardware: ESP32-wroom32-u

Core Version: 2.4.0, staging

Description

When I turn the device off and on, it automatically turns to automatic ip mode

Settings in IDE

Module: Nodemcu

Additional libraries:

Sketch

#BEGIN
/**
 * WiFiManager advanced demo, contains advanced configurartion options
 * Implements TRIGGEN_PIN button press, press for ondemand configportal, hold for 3 seconds for reset settings.
 */
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager

#define TRIGGER_PIN 0

WiFiManager wm; // global wm instance
WiFiManagerParameter custom_field; // global param ( for non blocking w params )

void setup() {
 WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP  
  Serial.begin(115200);
  Serial.setDebugOutput(true);  
  delay(3000);
  Serial.println("\n Starting");

  pinMode(TRIGGER_PIN, INPUT);
  
  // wm.resetSettings(); // wipe settings

  // add a custom input field
  int customFieldLength = 40;


  // new (&custom_field) WiFiManagerParameter("customfieldid", "Custom Field Label", "Custom Field Value", customFieldLength,"placeholder=\"Custom Field Placeholder\"");
  
  // test custom html input type(checkbox)
  // new (&custom_field) WiFiManagerParameter("customfieldid", "Custom Field Label", "Custom Field Value", customFieldLength,"placeholder=\"Custom Field Placeholder\" type=\"checkbox\""); // custom html type
  
  // test custom html(radio)
  const char* custom_radio_str = "<br/><label for='customfieldid'>Custom Field Label</label><input type='radio' name='customfieldid' value='1' checked> One<br><input type='radio' name='customfieldid' value='2'> Two<br><input type='radio' name='customfieldid' value='3'> Three";
  new (&custom_field) WiFiManagerParameter(custom_radio_str); // custom html input
  
  wm.addParameter(&custom_field);
  wm.setSaveParamsCallback(saveParamCallback);

  // custom menu via array or vector
  // 
  // menu tokens, "wifi","wifinoscan","info","param","close","sep","erase","restart","exit" (sep is seperator) (if param is in menu, params will not show up in wifi page!)
  // const char* menu[] = {"wifi","info","param","sep","restart","exit"}; 
  // wm.setMenu(menu,6);
  std::vector<const char *> menu = {"wifi","info","param","sep","restart","exit"};
  wm.setMenu(menu);

  // set dark theme
  wm.setClass("invert");


  //set static ip
  // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // set static ip,gw,sn
   wm.setShowStaticFields(true); // force show static ip fields
  wm.setShowDnsFields(true);    // force show dns field always

   wm.setConnectTimeout(20); // how long to try to connect for before continuing
  wm.setConfigPortalTimeout(30); // auto close configportal after n seconds
  // wm.setCaptivePortalEnable(false); // disable captive portal redirection
  // wm.setAPClientCheck(true); // avoid timeout if client connected to softap

  // wifi scan settings
  // wm.setRemoveDuplicateAPs(false); // do not remove duplicate ap names (true)
  // wm.setMinimumSignalQuality(20);  // set min RSSI (percentage) to show in scans, null = 8%
  // wm.setShowInfoErase(false);      // do not show erase button on info page
  // wm.setScanDispPerc(true);       // show RSSI as percentage not graph icons
  
  // wm.setBreakAfterConfig(true);   // always exit configportal even if wifi save fails

  bool res;
  // res = wm.autoConnect(); // auto generated AP name from chipid
  // res = wm.autoConnect("AutoConnectAP"); // anonymous ap
  res = wm.autoConnect("AutoConnectAP","password"); // password protected ap

  if(!res) {
    Serial.println("Failed to connect or hit timeout");
    // ESP.restart();
  } 
  else {
    //if you get here you have connected to the WiFi    
    Serial.println("connected...yeey :)");
  }
}

void checkButton(){
  // check for button press
  if ( digitalRead(TRIGGER_PIN) == LOW ) {
    // poor mans debounce/press-hold, code not ideal for production
    delay(50);
    if( digitalRead(TRIGGER_PIN) == LOW ){
      Serial.println("Button Pressed");
      // still holding button for 3000 ms, reset settings, code not ideaa for production
      delay(3000); // reset delay hold
      if( digitalRead(TRIGGER_PIN) == LOW ){
        Serial.println("Button Held");
        Serial.println("Erasing Config, restarting");
        wm.resetSettings();
        ESP.restart();
      }
      
      // start portal w delay
      Serial.println("Starting config portal");
      wm.setConfigPortalTimeout(120);
      
      if (!wm.startConfigPortal("OnDemandAP","password")) {
        Serial.println("failed to connect or hit timeout");
        delay(3000);
        // ESP.restart();
      } else {
        //if you get here you have connected to the WiFi
        Serial.println("connected...yeey :)");
      }
    }
  }
}


String getParam(String name){
  //read parameter from server, for customhmtl input
  String value;
  if(wm.server->hasArg(name)) {
    value = wm.server->arg(name);
  }
  return value;
}

void saveParamCallback(){
  Serial.println("[CALLBACK] saveParamCallback fired");
  Serial.println("PARAM customfieldid = " + getParam("customfieldid"));
}

void loop() {
  checkButton();
  // put your main code here, to run repeatedly:
}
#END

Debug Messages

messages here
Originally created by @emredusmez on GitHub (Mar 26, 2021). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1233 ### Basic Infos #### Hardware WiFimanager Branch/Release: Master Esp8266/Esp32: Hardware: ESP32-wroom32-u Core Version: 2.4.0, staging ### Description When I turn the device off and on, it automatically turns to automatic ip mode ### Settings in IDE Module: Nodemcu Additional libraries: ### Sketch ```cpp #BEGIN /** * WiFiManager advanced demo, contains advanced configurartion options * Implements TRIGGEN_PIN button press, press for ondemand configportal, hold for 3 seconds for reset settings. */ #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager #define TRIGGER_PIN 0 WiFiManager wm; // global wm instance WiFiManagerParameter custom_field; // global param ( for non blocking w params ) void setup() { WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP Serial.begin(115200); Serial.setDebugOutput(true); delay(3000); Serial.println("\n Starting"); pinMode(TRIGGER_PIN, INPUT); // wm.resetSettings(); // wipe settings // add a custom input field int customFieldLength = 40; // new (&custom_field) WiFiManagerParameter("customfieldid", "Custom Field Label", "Custom Field Value", customFieldLength,"placeholder=\"Custom Field Placeholder\""); // test custom html input type(checkbox) // new (&custom_field) WiFiManagerParameter("customfieldid", "Custom Field Label", "Custom Field Value", customFieldLength,"placeholder=\"Custom Field Placeholder\" type=\"checkbox\""); // custom html type // test custom html(radio) const char* custom_radio_str = "<br/><label for='customfieldid'>Custom Field Label</label><input type='radio' name='customfieldid' value='1' checked> One<br><input type='radio' name='customfieldid' value='2'> Two<br><input type='radio' name='customfieldid' value='3'> Three"; new (&custom_field) WiFiManagerParameter(custom_radio_str); // custom html input wm.addParameter(&custom_field); wm.setSaveParamsCallback(saveParamCallback); // custom menu via array or vector // // menu tokens, "wifi","wifinoscan","info","param","close","sep","erase","restart","exit" (sep is seperator) (if param is in menu, params will not show up in wifi page!) // const char* menu[] = {"wifi","info","param","sep","restart","exit"}; // wm.setMenu(menu,6); std::vector<const char *> menu = {"wifi","info","param","sep","restart","exit"}; wm.setMenu(menu); // set dark theme wm.setClass("invert"); //set static ip // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // set static ip,gw,sn wm.setShowStaticFields(true); // force show static ip fields wm.setShowDnsFields(true); // force show dns field always wm.setConnectTimeout(20); // how long to try to connect for before continuing wm.setConfigPortalTimeout(30); // auto close configportal after n seconds // wm.setCaptivePortalEnable(false); // disable captive portal redirection // wm.setAPClientCheck(true); // avoid timeout if client connected to softap // wifi scan settings // wm.setRemoveDuplicateAPs(false); // do not remove duplicate ap names (true) // wm.setMinimumSignalQuality(20); // set min RSSI (percentage) to show in scans, null = 8% // wm.setShowInfoErase(false); // do not show erase button on info page // wm.setScanDispPerc(true); // show RSSI as percentage not graph icons // wm.setBreakAfterConfig(true); // always exit configportal even if wifi save fails bool res; // res = wm.autoConnect(); // auto generated AP name from chipid // res = wm.autoConnect("AutoConnectAP"); // anonymous ap res = wm.autoConnect("AutoConnectAP","password"); // password protected ap if(!res) { Serial.println("Failed to connect or hit timeout"); // ESP.restart(); } else { //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); } } void checkButton(){ // check for button press if ( digitalRead(TRIGGER_PIN) == LOW ) { // poor mans debounce/press-hold, code not ideal for production delay(50); if( digitalRead(TRIGGER_PIN) == LOW ){ Serial.println("Button Pressed"); // still holding button for 3000 ms, reset settings, code not ideaa for production delay(3000); // reset delay hold if( digitalRead(TRIGGER_PIN) == LOW ){ Serial.println("Button Held"); Serial.println("Erasing Config, restarting"); wm.resetSettings(); ESP.restart(); } // start portal w delay Serial.println("Starting config portal"); wm.setConfigPortalTimeout(120); if (!wm.startConfigPortal("OnDemandAP","password")) { Serial.println("failed to connect or hit timeout"); delay(3000); // ESP.restart(); } else { //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); } } } } String getParam(String name){ //read parameter from server, for customhmtl input String value; if(wm.server->hasArg(name)) { value = wm.server->arg(name); } return value; } void saveParamCallback(){ Serial.println("[CALLBACK] saveParamCallback fired"); Serial.println("PARAM customfieldid = " + getParam("customfieldid")); } void loop() { checkButton(); // put your main code here, to run repeatedly: } #END ``` ### Debug Messages ``` messages here ```
Author
Owner

@EgHubs commented on GitHub (Apr 1, 2021):

Can you please provide some logs, at first connection for static then when pressing reset.

<!-- gh-comment-id:811563217 --> @EgHubs commented on GitHub (Apr 1, 2021): Can you please provide some logs, at first connection for static then when pressing reset.
Author
Owner

@tablatronix commented on GitHub (Apr 1, 2021):

Where else is it supposed to get an ip from , I see nothing in your code about static ips...

<!-- gh-comment-id:811606631 --> @tablatronix commented on GitHub (Apr 1, 2021): Where else is it supposed to get an ip from , I see nothing in your code about static ips...
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1056
No description provided.