[GH-ISSUE #721] setAPStaticIPConfig failed #603

Closed
opened 2026-02-28 01:26:10 +03:00 by kerem · 11 comments
Owner

Originally created by @rodri16 on GitHub (Sep 5, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/721

Basic Infos

Hardware

WiFimanager Branch/Release:

  • Master
  • Development

Esp8266/Esp32:

  • ESP8266
  • ESP32

Hardware: ESP-12e, esp01, esp25

  • ESP01
  • ESP12 E/F/S (nodemcu, wemos, feather)
  • Other

ESP Core Version: 2.4.0, staging
SDK Version 2.2.1
Core version 2.4.1
Boot version 4

Description

I am using autoconnect and callbacks, to connect to a stored WiFi SSID. In callback I am putting static IP 10.0.1.1 for the config portal.
myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));

If Wifi does not connect because I do a resetSettings(), config portal starts ok on 10.0.1.1.
When WiFi is connected using autoconnect and press a button which runs startConfigPortal() it goes to 192.168.4.1. Even adding setAPStaticIPConfig before startConfigPortal()

Settings in IDE

Module: Generic ESP8266 module
Flash size: 4M (3M SPIFFS)
all other parameters default
Additional libraries:
ESP8266mDNS.h
TimeLib.h
NtpClientLib.h
DNSServer.h
HLW8012.h
ArduinoJson.h

Debug Messages

Doing a wifiManager.resetSettings(); It works ok
*WM: [1] SETTINGS ERASED
*WM: [3] WiFi station enable
*WM: [3] enableSTA PERSISTENT ON
*WM: [3] allocating params bytes: 20
*WM: [2] Added Parameter: server
*WM: [2] Added Parameter: port
*WM: [2] Added Parameter: TimeZone
*WM: [1] AutoConnect
*WM: [2] Connecting as wifi client...
*WM: [3] WIFI station disconnect
*WM: [1] No saved credentials, skipping wifi
*WM: [2] Connection result: WL_NO_SSID_AVAIL
*WM: [3] lastconxresult: WL_NO_SSID_AVAIL
*WM: [1] AutoConnect: FAILED
*WM: [2] AccessPoint set password is VALID
*WM: [1] xxxx
*WM: [3] WIFI station disconnect
*WM: [3] WiFi station enable
*WM: [2] Disabling STA
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: xxxx
*WM: [1] Custom AP IP/GW/Subnet:
*WM: [1] AP IP address: 10.0.1.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 10.0.1.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] WiFi Scan ASYNC completed in 2186 ms
*WM: [2] WiFi Scan ASYNC found: 9

And then pressing the button to start config portal
*WM: [2] AccessPoint set password is VALID
*WM: [1] xxxx
*WM: [3] WiFi station enable
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: xxxx
*WM: [1] Custom AP IP/GW/Subnet:
*WM: [0] [ERROR] softAPConfig failed!
*WM: [1] AP IP address: 10.0.1.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 10.0.1.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] Portal Timeout In 118 seconds
*WM: [2] WiFi Scan ASYNC completed in 1589 ms
*WM: [2] WiFi Scan ASYNC found: 8

THEN aftera reboot with Wifi settings and press the button
*WM: [2] AccessPoint set password is VALID
*WM: [1] XXXXX
*WM: [3] WiFi station enable
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: XXXXX
Entered config mode
0.0.0.0
XXXXX
*WM: [1] Custom AP IP/GW/Subnet:
*WM: [0] [ERROR] softAPConfig failed!
*WM: [1] AP IP address: 192.168.4.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 192.168.4.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] Portal Timeout In 118 seconds
*WM: [2] WiFi Scan ASYNC completed in 1589 ms
*WM: [2] WiFi Scan ASYNC found: 5
*WM: [2] Portal Timeout In 88 seconds

Thanks

Originally created by @rodri16 on GitHub (Sep 5, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/721 ### Basic Infos #### Hardware **WiFimanager Branch/Release:** - [ ] Master - [x] Development **Esp8266/Esp32:** - [x] ESP8266 - [ ] ESP32 **Hardware: ESP-12e, esp01, esp25** - [ ] ESP01 - [x] ESP12 E/F/S (nodemcu, wemos, feather) - [ ] Other **ESP Core Version: 2.4.0, staging** SDK Version 2.2.1 Core version 2.4.1 Boot version 4 ### Description I am using autoconnect and callbacks, to connect to a stored WiFi SSID. In callback I am putting static IP 10.0.1.1 for the config portal. myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); If Wifi does not connect because I do a resetSettings(), config portal starts ok on 10.0.1.1. When WiFi is connected using autoconnect and press a button which runs startConfigPortal() it goes to 192.168.4.1. Even adding setAPStaticIPConfig before startConfigPortal() ### Settings in IDE Module: Generic ESP8266 module Flash size: 4M (3M SPIFFS) all other parameters default Additional libraries: ESP8266mDNS.h TimeLib.h NtpClientLib.h DNSServer.h HLW8012.h ArduinoJson.h ### Debug Messages Doing a wifiManager.resetSettings(); It works ok *WM: [1] SETTINGS ERASED *WM: [3] WiFi station enable *WM: [3] enableSTA PERSISTENT ON *WM: [3] allocating params bytes: 20 *WM: [2] Added Parameter: server *WM: [2] Added Parameter: port *WM: [2] Added Parameter: TimeZone *WM: [1] AutoConnect *WM: [2] Connecting as wifi client... *WM: [3] WIFI station disconnect *WM: [1] No saved credentials, skipping wifi *WM: [2] Connection result: WL_NO_SSID_AVAIL *WM: [3] lastconxresult: WL_NO_SSID_AVAIL *WM: [1] AutoConnect: FAILED *WM: [2] AccessPoint set password is VALID *WM: [1] xxxx *WM: [3] WIFI station disconnect *WM: [3] WiFi station enable *WM: [2] Disabling STA *WM: [2] Enabling AP *WM: [1] StartAP with SSID: xxxx *WM: [1] Custom AP IP/GW/Subnet: *WM: [1] AP IP address: 10.0.1.1 *WM: [3] setupConfigPortal *WM: [1] Starting Web Portal *WM: [3] dns server started with ip: 10.0.1.1 *WM: [2] HTTP server started *WM: [2] WiFi Scan ASYNC started *WM: [2] Config Portal Running, blocking, waiting for clients... *WM: [2] WiFi Scan ASYNC completed in 2186 ms *WM: [2] WiFi Scan ASYNC found: 9 And then pressing the button to start config portal *WM: [2] AccessPoint set password is VALID *WM: [1] xxxx *WM: [3] WiFi station enable *WM: [2] Enabling AP *WM: [1] StartAP with SSID: xxxx *WM: [1] Custom AP IP/GW/Subnet: *WM: [0] [ERROR] softAPConfig failed! *WM: [1] AP IP address: 10.0.1.1 *WM: [3] setupConfigPortal *WM: [1] Starting Web Portal *WM: [3] dns server started with ip: 10.0.1.1 *WM: [2] HTTP server started *WM: [2] WiFi Scan ASYNC started *WM: [2] Config Portal Running, blocking, waiting for clients... *WM: [2] Portal Timeout In 118 seconds *WM: [2] WiFi Scan ASYNC completed in 1589 ms *WM: [2] WiFi Scan ASYNC found: 8 THEN aftera reboot with Wifi settings and press the button *WM: [2] AccessPoint set password is VALID *WM: [1] XXXXX *WM: [3] WiFi station enable *WM: [2] Enabling AP *WM: [1] StartAP with SSID: XXXXX Entered config mode 0.0.0.0 XXXXX *WM: [1] Custom AP IP/GW/Subnet: *WM: [0] [ERROR] softAPConfig failed! *WM: [1] AP IP address: 192.168.4.1 *WM: [3] setupConfigPortal *WM: [1] Starting Web Portal *WM: [3] dns server started with ip: 192.168.4.1 *WM: [2] HTTP server started *WM: [2] WiFi Scan ASYNC started *WM: [2] Config Portal Running, blocking, waiting for clients... *WM: [2] Portal Timeout In 118 seconds *WM: [2] WiFi Scan ASYNC completed in 1589 ms *WM: [2] WiFi Scan ASYNC found: 5 *WM: [2] Portal Timeout In 88 seconds Thanks
kerem 2026-02-28 01:26:10 +03:00
Author
Owner

@tablatronix commented on GitHub (Sep 5, 2018):

Do you have sketch ?
Is WM global or are you setting apconfig in loop where button is pressed?

<!-- gh-comment-id:418742300 --> @tablatronix commented on GitHub (Sep 5, 2018): Do you have sketch ? Is WM global or are you setting apconfig in loop where button is pressed?
Author
Owner

@tablatronix commented on GitHub (Sep 5, 2018):

I am just not seeing this at all

*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] AutoConnect: SUCCESS 
*WM: [1] STA IP Address: 10.80.30.158
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
BUTTON PRESSED
*WM: [3] WiFi station enable 
*WM: [2] Enabling AP 
*WM: [1] StartAP with SSID:  OnDemandAP
*WM: [1] Custom AP IP/GW/Subnet: 
[APConfig] local_ip: 10.0.1.99 gateway: 10.0.1.1 subnet: 255.255.255.0
[APConfig] DHCP IP start: 10.0.1.198
[APConfig] DHCP IP end: 10.0.1.42
*WM: [2] AP has anonymous access! 
bcn 0
del if1
pm open,type:2 0
add if1
pm close 7
dhcp server start:(ip:10.0.1.99,mask:255.255.255.0,gw:10.0.1.1)
bcn 100
*WM: [1] AP IP address: 10.0.1.99
*WM: [3] setupConfigPortal 
*WM: [1] Starting Web Portal 
*WM: [3] dns server started with ip:  10.0.1.99
*WM: [2] HTTP server started 
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] Config Portal Running, blocking, waiting for clients... 
wifi evt: 7
scandone
*WM: [2] WiFi Scan ASYNC completed in 2198 ms
*WM: [2] WiFi Scan ASYNC found: 9

Probably need to figure out why
*WM: [0] [ERROR] softAPConfig failed!

<!-- gh-comment-id:418746950 --> @tablatronix commented on GitHub (Sep 5, 2018): I am just not seeing this at all ``` *WM: [2] Connection result: WL_CONNECTED *WM: [3] lastconxresult: WL_CONNECTED *WM: [1] AutoConnect: SUCCESS *WM: [1] STA IP Address: 10.80.30.158 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 wifi evt: 7 BUTTON PRESSED *WM: [3] WiFi station enable *WM: [2] Enabling AP *WM: [1] StartAP with SSID: OnDemandAP *WM: [1] Custom AP IP/GW/Subnet: [APConfig] local_ip: 10.0.1.99 gateway: 10.0.1.1 subnet: 255.255.255.0 [APConfig] DHCP IP start: 10.0.1.198 [APConfig] DHCP IP end: 10.0.1.42 *WM: [2] AP has anonymous access! bcn 0 del if1 pm open,type:2 0 add if1 pm close 7 dhcp server start:(ip:10.0.1.99,mask:255.255.255.0,gw:10.0.1.1) bcn 100 *WM: [1] AP IP address: 10.0.1.99 *WM: [3] setupConfigPortal *WM: [1] Starting Web Portal *WM: [3] dns server started with ip: 10.0.1.99 *WM: [2] HTTP server started *WM: [2] WiFi Scan ASYNC started *WM: [2] Config Portal Running, blocking, waiting for clients... wifi evt: 7 scandone *WM: [2] WiFi Scan ASYNC completed in 2198 ms *WM: [2] WiFi Scan ASYNC found: 9 ``` Probably need to figure out why `*WM: [0] [ERROR] softAPConfig failed!`
Author
Owner

@tablatronix commented on GitHub (Sep 5, 2018):

you need to enable esp debugging wifi

<!-- gh-comment-id:418752987 --> @tablatronix commented on GitHub (Sep 5, 2018): you need to enable esp debugging wifi
Author
Owner

@rodri16 commented on GitHub (Sep 5, 2018):

WM is global
*WM: [2] AccessPoint set password is VALID
*WM: [1] Dispositive
*WM: [3] WiFi station enable
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: Disp_3
Entered config mode
0.0.0.0
Disp_3
*WM: [1] Custom AP IP/GW/Subnet:
*WM: [0] [ERROR] softAPConfig failed!
mode : sta(ec:fa:bc:00:a2:5f) + softAP(ee:fa:bc:00:a2:5f)
add if1
pm close 7
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
bcn 0
del if1
pm open,type:2 0
add if1
pm close 7
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
*WM: [1] AP IP address: 192.168.4.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 192.168.4.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] Portal Timeout In 118 seconds
scandone
*WM: [2] WiFi Scan ASYNC completed in 1599 ms
*WM: [2] WiFi Scan ASYNC found: 10

Sketch

#include <FS.h>                   //this needs to be first, or it all crashes and burns...
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <DNSServer.h>
#include <TimeLib.h>
#include <NtpClientLib.h>
#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson

// Use WiFiClient class to create TCP connections
WiFiClient client;

//for LED status
#include <Ticker.h>
Ticker ticker;

//-------------------------------------variables y definiciones a cambiar----------------------------------
#define nro_dis 3    //cambiar por el numero de dispositivo 
//----------------------------------------no cambiar-------------------------------------------------------
#define BUILTIN_LED 15 // green led 15, red+relay 12. LOW is on
#define RELAY_PIN 12 //relay

#define SSID1 "Disp_"
#define password "Dispositive"

String datenow, timenow, datenowdot, timenowdot;
unsigned long previousMillis = 0;
const long interval = 5*60*1000; //envio cada 5 minutos
volatile boolean butt_flag = false;

int8_t minutesTimeZone = 0;
bool wifiFirstConnected = true;

const char* ntpServerName = "pool.ntp.org"; //"time.nist.gov";
boolean syncEventTriggered = false; // True if a time even has been triggered
NTPSyncEvent_t ntpEvent; // Last triggered event

String SSID_connected, RSSI_connected, uptime;
// the IP address for the shield:
IPAddress gw_connected() ;
int32_t ch_connected;

//define your default values here, if there are different values in config.json, they are overwritten.
//length should be max size + 1
char mqtt_server[40] ="server.com";
char mqtt_port[6] = "80";
char TimeZone[5]="3.0";

char Buf[22];

String mac,IP;

//flag for saving data
bool shouldSaveConfig = false;

const char* modes[] = { "NULL", "STA", "AP", "STA+AP" };

//---------------------- Variables del vector de datos
#define NUM_BINS 300 //cantidad de datos a almacenar

boolean stored_flag=false;
boolean start_flag=true;
int idx=0; //pocision del vector guardado


//--------------------WIFIMANAGER-----------------------------------------------------
 //Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//callback notifying us of the need to save config 
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

//gets called when WiFiManager enters configuration mode
void configModeCallback (WiFiManager *myWiFiManager) {
  Serial.println("Entered config mode");
  myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); 
  Serial.println(WiFi.softAPIP());
  //if you used auto generated SSID, print it
  Serial.println(myWiFiManager->getConfigPortalSSID());
  //entered config mode, make led toggle faster
  ticker.attach(0.2, tick);
}

//--------------------Webserver----------------------------------------------
std::unique_ptr<ESP8266WebServer> server;
String HeaderPage = "";
String FooterPage = "";
String rootPageBody = "";
String rootWebPage;

void handleRoot() {
  //digitalWrite(BUILTIN_LED, 1);
  String message = HeaderPage;
  server->send(200, "text/html", message); //"text/plain"
  //digitalWrite(BUILTIN_LED, 1);
}

void handleNotFound() {
  //digitalWrite(BUILTIN_LED, 1);
  String message = "File Not Found\n\n";
  for (uint8_t i = 0; i < server->args(); i++) {
    message += " " + server->argName(i) + ": " + server->arg(i) + "\n";
  }
  server->send(404, "text/plain", message);
  //digitalWrite(BUILTIN_LED, 0);
}

//----------------------------tick---------------------------
void tick()
{
  //toggle state
  int state = digitalRead(BUILTIN_LED);  // get the current state of GPIO1 pin
  digitalWrite(BUILTIN_LED, !state);     // set pin to the opposite state
}

 //-----------------Interrupcion Boton----------------------------------------
void ISRbuttonStateChanged() {
  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();
  // If interrupts come faster than 200ms, assume it's a bounce and ignore
  if (interrupt_time - last_interrupt_time > 200)
  {
    butt_flag = !butt_flag;
  }
  last_interrupt_time = interrupt_time;
}

//------------Evento NTP------------------------------
void processSyncEvent (NTPSyncEvent_t ntpEvent) {
  if (ntpEvent) {
    Serial.print ("Time Sync error: ");
    if (ntpEvent == noResponse)
      Serial.println ("NTP server not reachable");
    else if (ntpEvent == invalidAddress)
      Serial.println ("Invalid NTP server address");
  } else {
    Serial.print ("Got NTP time: ");
    Serial.println (NTP.getTimeDateString (NTP.getLastNTPSync ()));
  }
}

void setupSpiffs(){
  //clean FS, for testing------------------------------------- for fist time
  //SPIFFS.format();
  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);
        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");

          strcpy(mqtt_server, json["mqtt_server"]);
          strcpy(mqtt_port, json["mqtt_port"]);
          strcpy(TimeZone, json["TimeZone"]);
        } else {
          Serial.println("failed to load json config");
        }
      }
    }
  } else {
    Serial.println("failed to mount FS");
  }
//end read
}

//---------------------------SETUP----------------------------------------------------------
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
 
  //set rekay pin as output
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, HIGH);

  //set led pin as output
  pinMode(BUILTIN_LED, OUTPUT);

   // start ticker with 0.5 because we start in AP mode and try to connect
  ticker.attach(0.6, tick);

  //read configuration from FS json
  Serial.println("mounting FS...");
  setupSpiffs();
  
  Serial.println(mqtt_server);Serial.println(TimeZone);

  
// The extra parameters to be configured (can be either global or just in the setup)
// After connecting, parameter.getValue() will get you the configured value
// id/name placeholder/prompt default length
  WiFiManagerParameter custom_mqtt_server("server", "Server address", mqtt_server, 40);
  WiFiManagerParameter custom_mqtt_port("port", "Server port", mqtt_port, 5);
  WiFiManagerParameter custom_TimeZone("TimeZone", "Time Zone", TimeZone, 5); 

  // create SSID with BioBarica_ y nro disp
  String address1 = String(SSID1)+String(nro_dis);
  address1.toCharArray(Buf, 50);

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //reset settings - for testing--------------------------------------
  //wifiManager.resetSettings();  //Uncomment for reset WiFi values 

  //---------Dev Branch-------
  std::vector<const char *> menu = {"wifi","sep","param","sep","exit"};
  //std::vector<const char *> menu = {"wifi","sep","param","sep","info","exit"};
  wifiManager.setMenu(menu);
  // set dark theme
  wifiManager.setClass("invert");

  //add all your parameters here
  wifiManager.addParameter(&custom_mqtt_server);
  wifiManager.addParameter(&custom_mqtt_port);
  wifiManager.addParameter(&custom_TimeZone);

  //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
  wifiManager.setAPCallback(configModeCallback);

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  wifiManager.setMinimumSignalQuality();

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect(Buf, password)) {
    Serial.println("failed to connect and hit timeout");
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(1000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");
  Serial.println(modes[WiFi.getMode()]);
  WiFi.mode(WIFI_STA);
  Serial.println(modes[WiFi.getMode()]);

  //read updated parameters
  strcpy(mqtt_server, custom_mqtt_server.getValue());
  strcpy(mqtt_port, custom_mqtt_port.getValue());
  strcpy(TimeZone, custom_TimeZone.getValue());
  
  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["mqtt_server"] = mqtt_server;
    json["mqtt_port"] = mqtt_port;
    json["TimeZone"] = TimeZone;
  
    json["ip"] = WiFi.localIP().toString();
    json["gateway"] = WiFi.gatewayIP().toString();
    json["subnet"] = WiFi.subnetMask().toString();

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }

    json.prettyPrintTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }
//-------------------------------end SPIFFS configuration-----------
  Serial.println();
  ticker.detach();

  //keep LED on
  digitalWrite(BUILTIN_LED, 1);
  
//----------------------------webserver-------------
  server.reset(new ESP8266WebServer(WiFi.localIP(), 80));

  server->on("/", handleRoot);

//---------------------mdns---------------
  if (!MDNS.begin(Buf)) {
    Serial.println("Error setting up MDNS responder!");
    while(1) { 
      delay(1000);
    }
  }
  Serial.println("mDNS responder started");
//---------------------webserver-------  
  server->onNotFound(handleNotFound);
  server->begin();
  Serial.println("HTTP server started");
  
//---- Add service to MDNS-SD
  MDNS.addService("http", "tcp", 80);

// ------------- INTERRUPTS ----------------------------
  pinMode(0, INPUT_PULLUP);  // GPIO0 as input for Config mode selection
  attachInterrupt(0, ISRbuttonStateChanged, CHANGE);

  mac = WiFi.macAddress();
  SSID_connected = WiFi.SSID();
  ch_connected = WiFi.channel();
  Serial.print("SSID: "); Serial.print(SSID_connected); Serial.print(", Channel: "); Serial.println(ch_connected);
  Serial.print("MAC: "); Serial.println(mac);
  IP=WiFi.localIP().toString();;
  Serial.print("IP: "); Serial.println(IP);
  Serial.print("GW_IP: "); Serial.println(WiFi.gatewayIP());
  Serial.print("Subnet: "); Serial.println(WiFi.subnetMask());
  delay(1000);
    
//-------------------------------------NTP-----------------------
  NTP.onNTPSyncEvent ([](NTPSyncEvent_t event) {
    ntpEvent = event;
    syncEventTriggered = true;
  });
}//---------------------End Setup-----------

//-------------MAIN LOOP-------------------------------------------------------------------------------------
void loop() {
  // put your main code here, to run repeatedly:
  server->handleClient();

  static int last = 0;
  if (wifiFirstConnected) {
    wifiFirstConnected = false;
    NTP.begin (ntpServerName, atoi(TimeZone), false, minutesTimeZone);
    delay(1000);
  }

  if (syncEventTriggered) {
    processSyncEvent (ntpEvent);
    syncEventTriggered = false;
  }

  
 //----------------------------------------Button para reconfigurar  ------------
  if (butt_flag == true) {

  //set config save notify callback
  //wifiManager.setSaveConfigCallback(saveConfigCallback);

  WiFiManagerParameter custom_mqtt_server("server", "Server address", mqtt_server, 40);
  WiFiManagerParameter custom_mqtt_port("port", "Server port", mqtt_port, 5);
  WiFiManagerParameter custom_TimeZone("TimeZone", "Time Zone", TimeZone, 5); 

  //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
  wifiManager.setAPCallback(configModeCallback);

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();
  ticker.attach(0.2, tick);
  wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); 
  wifiManager.setConfigPortalTimeout(120); // auto close configportal after n seconds
    
    if (!wifiManager.startConfigPortal(Buf,password)) {
        Serial.println("failed to connect or hit timeout");
        delay(300);
      } else {
        //if you get here you have connected to the WiFi
        Serial.println("connected...yeey :)");
        Serial.println(modes[WiFi.getMode()]);
        WiFi.mode(WIFI_STA);
        Serial.println(modes[WiFi.getMode()]);
        ticker.detach();
        //keep LED on
        digitalWrite(BUILTIN_LED, 1);
      }
      
    //read updated parameters
  strcpy(mqtt_server, custom_mqtt_server.getValue());
  strcpy(mqtt_port, custom_mqtt_port.getValue());
  strcpy(TimeZone, custom_TimeZone.getValue());
 
  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["mqtt_server"] = mqtt_server;
    json["mqtt_port"] = mqtt_port;
    json["TimeZone"] = TimeZone;
  
    json["ip"] = WiFi.localIP().toString();
    json["gateway"] = WiFi.gatewayIP().toString();
    json["subnet"] = WiFi.subnetMask().toString();

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }

    json.prettyPrintTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }
//-------------------------------end SPIFFS configuration-----------
  Serial.println();
  ticker.detach();

  //keep LED on
  digitalWrite(BUILTIN_LED, 1);
 
  //----------------------------webserver-------------
  server.reset(new ESP8266WebServer(WiFi.localIP(), 80));

  server->on("/", handleRoot);

//---------------------mdns---------------
  if (!MDNS.begin(Buf)) {
    Serial.println("Error setting up MDNS responder!");
    while(1) { 
      delay(1000);
    }
  }
  Serial.println("mDNS responder started");
//---------------------webserver-------  
  server->onNotFound(handleNotFound);
  server->begin();
  Serial.println("HTTP server started");
  
//---- Add service to MDNS-SD
  MDNS.addService("http", "tcp", 80);
  butt_flag = false;
  }
  else {
  }
}

<!-- gh-comment-id:418761987 --> @rodri16 commented on GitHub (Sep 5, 2018): WM is global *WM: [2] AccessPoint set password is VALID *WM: [1] Dispositive *WM: [3] WiFi station enable *WM: [2] Enabling AP *WM: [1] StartAP with SSID: Disp_3 Entered config mode 0.0.0.0 Disp_3 *WM: [1] Custom AP IP/GW/Subnet: *WM: [0] [ERROR] softAPConfig failed! mode : sta(ec:fa:bc:00:a2:5f) + softAP(ee:fa:bc:00:a2:5f) add if1 pm close 7 dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1) bcn 100 bcn 0 del if1 pm open,type:2 0 add if1 pm close 7 dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1) bcn 100 *WM: [1] AP IP address: 192.168.4.1 *WM: [3] setupConfigPortal *WM: [1] Starting Web Portal *WM: [3] dns server started with ip: 192.168.4.1 *WM: [2] HTTP server started *WM: [2] WiFi Scan ASYNC started *WM: [2] Config Portal Running, blocking, waiting for clients... *WM: [2] Portal Timeout In 118 seconds scandone *WM: [2] WiFi Scan ASYNC completed in 1599 ms *WM: [2] WiFi Scan ASYNC found: 10 Sketch ```C++ #include <FS.h> //this needs to be first, or it all crashes and burns... #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino #include <ESP8266WebServer.h> #include <ESP8266mDNS.h> #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager #include <DNSServer.h> #include <TimeLib.h> #include <NtpClientLib.h> #include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson // Use WiFiClient class to create TCP connections WiFiClient client; //for LED status #include <Ticker.h> Ticker ticker; //-------------------------------------variables y definiciones a cambiar---------------------------------- #define nro_dis 3 //cambiar por el numero de dispositivo //----------------------------------------no cambiar------------------------------------------------------- #define BUILTIN_LED 15 // green led 15, red+relay 12. LOW is on #define RELAY_PIN 12 //relay #define SSID1 "Disp_" #define password "Dispositive" String datenow, timenow, datenowdot, timenowdot; unsigned long previousMillis = 0; const long interval = 5*60*1000; //envio cada 5 minutos volatile boolean butt_flag = false; int8_t minutesTimeZone = 0; bool wifiFirstConnected = true; const char* ntpServerName = "pool.ntp.org"; //"time.nist.gov"; boolean syncEventTriggered = false; // True if a time even has been triggered NTPSyncEvent_t ntpEvent; // Last triggered event String SSID_connected, RSSI_connected, uptime; // the IP address for the shield: IPAddress gw_connected() ; int32_t ch_connected; //define your default values here, if there are different values in config.json, they are overwritten. //length should be max size + 1 char mqtt_server[40] ="server.com"; char mqtt_port[6] = "80"; char TimeZone[5]="3.0"; char Buf[22]; String mac,IP; //flag for saving data bool shouldSaveConfig = false; const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; //---------------------- Variables del vector de datos #define NUM_BINS 300 //cantidad de datos a almacenar boolean stored_flag=false; boolean start_flag=true; int idx=0; //pocision del vector guardado //--------------------WIFIMANAGER----------------------------------------------------- //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager; //callback notifying us of the need to save config void saveConfigCallback () { Serial.println("Should save config"); shouldSaveConfig = true; } //gets called when WiFiManager enters configuration mode void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("Entered config mode"); myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); Serial.println(WiFi.softAPIP()); //if you used auto generated SSID, print it Serial.println(myWiFiManager->getConfigPortalSSID()); //entered config mode, make led toggle faster ticker.attach(0.2, tick); } //--------------------Webserver---------------------------------------------- std::unique_ptr<ESP8266WebServer> server; String HeaderPage = ""; String FooterPage = ""; String rootPageBody = ""; String rootWebPage; void handleRoot() { //digitalWrite(BUILTIN_LED, 1); String message = HeaderPage; server->send(200, "text/html", message); //"text/plain" //digitalWrite(BUILTIN_LED, 1); } void handleNotFound() { //digitalWrite(BUILTIN_LED, 1); String message = "File Not Found\n\n"; for (uint8_t i = 0; i < server->args(); i++) { message += " " + server->argName(i) + ": " + server->arg(i) + "\n"; } server->send(404, "text/plain", message); //digitalWrite(BUILTIN_LED, 0); } //----------------------------tick--------------------------- void tick() { //toggle state int state = digitalRead(BUILTIN_LED); // get the current state of GPIO1 pin digitalWrite(BUILTIN_LED, !state); // set pin to the opposite state } //-----------------Interrupcion Boton---------------------------------------- void ISRbuttonStateChanged() { static unsigned long last_interrupt_time = 0; unsigned long interrupt_time = millis(); // If interrupts come faster than 200ms, assume it's a bounce and ignore if (interrupt_time - last_interrupt_time > 200) { butt_flag = !butt_flag; } last_interrupt_time = interrupt_time; } //------------Evento NTP------------------------------ void processSyncEvent (NTPSyncEvent_t ntpEvent) { if (ntpEvent) { Serial.print ("Time Sync error: "); if (ntpEvent == noResponse) Serial.println ("NTP server not reachable"); else if (ntpEvent == invalidAddress) Serial.println ("Invalid NTP server address"); } else { Serial.print ("Got NTP time: "); Serial.println (NTP.getTimeDateString (NTP.getLastNTPSync ())); } } void setupSpiffs(){ //clean FS, for testing------------------------------------- for fist time //SPIFFS.format(); if (SPIFFS.begin()) { Serial.println("mounted file system"); if (SPIFFS.exists("/config.json")) { //file exists, reading and loading Serial.println("reading config file"); File configFile = SPIFFS.open("/config.json", "r"); if (configFile) { Serial.println("opened config file"); size_t size = configFile.size(); // Allocate a buffer to store contents of the file. std::unique_ptr<char[]> buf(new char[size]); configFile.readBytes(buf.get(), size); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.parseObject(buf.get()); json.printTo(Serial); if (json.success()) { Serial.println("\nparsed json"); strcpy(mqtt_server, json["mqtt_server"]); strcpy(mqtt_port, json["mqtt_port"]); strcpy(TimeZone, json["TimeZone"]); } else { Serial.println("failed to load json config"); } } } } else { Serial.println("failed to mount FS"); } //end read } //---------------------------SETUP---------------------------------------------------------- void setup() { // put your setup code here, to run once: Serial.begin(115200); //set rekay pin as output pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, HIGH); //set led pin as output pinMode(BUILTIN_LED, OUTPUT); // start ticker with 0.5 because we start in AP mode and try to connect ticker.attach(0.6, tick); //read configuration from FS json Serial.println("mounting FS..."); setupSpiffs(); Serial.println(mqtt_server);Serial.println(TimeZone); // The extra parameters to be configured (can be either global or just in the setup) // After connecting, parameter.getValue() will get you the configured value // id/name placeholder/prompt default length WiFiManagerParameter custom_mqtt_server("server", "Server address", mqtt_server, 40); WiFiManagerParameter custom_mqtt_port("port", "Server port", mqtt_port, 5); WiFiManagerParameter custom_TimeZone("TimeZone", "Time Zone", TimeZone, 5); // create SSID with BioBarica_ y nro disp String address1 = String(SSID1)+String(nro_dis); address1.toCharArray(Buf, 50); //set config save notify callback wifiManager.setSaveConfigCallback(saveConfigCallback); //reset settings - for testing-------------------------------------- //wifiManager.resetSettings(); //Uncomment for reset WiFi values //---------Dev Branch------- std::vector<const char *> menu = {"wifi","sep","param","sep","exit"}; //std::vector<const char *> menu = {"wifi","sep","param","sep","info","exit"}; wifiManager.setMenu(menu); // set dark theme wifiManager.setClass("invert"); //add all your parameters here wifiManager.addParameter(&custom_mqtt_server); wifiManager.addParameter(&custom_mqtt_port); wifiManager.addParameter(&custom_TimeZone); //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode wifiManager.setAPCallback(configModeCallback); //set minimu quality of signal so it ignores AP's under that quality //defaults to 8% wifiManager.setMinimumSignalQuality(); //fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name //and goes into a blocking loop awaiting configuration if (!wifiManager.autoConnect(Buf, password)) { Serial.println("failed to connect and hit timeout"); //reset and try again, or maybe put it to deep sleep ESP.reset(); delay(1000); } //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); Serial.println(modes[WiFi.getMode()]); WiFi.mode(WIFI_STA); Serial.println(modes[WiFi.getMode()]); //read updated parameters strcpy(mqtt_server, custom_mqtt_server.getValue()); strcpy(mqtt_port, custom_mqtt_port.getValue()); strcpy(TimeZone, custom_TimeZone.getValue()); //save the custom parameters to FS if (shouldSaveConfig) { Serial.println("saving config"); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject(); json["mqtt_server"] = mqtt_server; json["mqtt_port"] = mqtt_port; json["TimeZone"] = TimeZone; json["ip"] = WiFi.localIP().toString(); json["gateway"] = WiFi.gatewayIP().toString(); json["subnet"] = WiFi.subnetMask().toString(); File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { Serial.println("failed to open config file for writing"); } json.prettyPrintTo(Serial); json.printTo(configFile); configFile.close(); //end save } //-------------------------------end SPIFFS configuration----------- Serial.println(); ticker.detach(); //keep LED on digitalWrite(BUILTIN_LED, 1); //----------------------------webserver------------- server.reset(new ESP8266WebServer(WiFi.localIP(), 80)); server->on("/", handleRoot); //---------------------mdns--------------- if (!MDNS.begin(Buf)) { Serial.println("Error setting up MDNS responder!"); while(1) { delay(1000); } } Serial.println("mDNS responder started"); //---------------------webserver------- server->onNotFound(handleNotFound); server->begin(); Serial.println("HTTP server started"); //---- Add service to MDNS-SD MDNS.addService("http", "tcp", 80); // ------------- INTERRUPTS ---------------------------- pinMode(0, INPUT_PULLUP); // GPIO0 as input for Config mode selection attachInterrupt(0, ISRbuttonStateChanged, CHANGE); mac = WiFi.macAddress(); SSID_connected = WiFi.SSID(); ch_connected = WiFi.channel(); Serial.print("SSID: "); Serial.print(SSID_connected); Serial.print(", Channel: "); Serial.println(ch_connected); Serial.print("MAC: "); Serial.println(mac); IP=WiFi.localIP().toString();; Serial.print("IP: "); Serial.println(IP); Serial.print("GW_IP: "); Serial.println(WiFi.gatewayIP()); Serial.print("Subnet: "); Serial.println(WiFi.subnetMask()); delay(1000); //-------------------------------------NTP----------------------- NTP.onNTPSyncEvent ([](NTPSyncEvent_t event) { ntpEvent = event; syncEventTriggered = true; }); }//---------------------End Setup----------- //-------------MAIN LOOP------------------------------------------------------------------------------------- void loop() { // put your main code here, to run repeatedly: server->handleClient(); static int last = 0; if (wifiFirstConnected) { wifiFirstConnected = false; NTP.begin (ntpServerName, atoi(TimeZone), false, minutesTimeZone); delay(1000); } if (syncEventTriggered) { processSyncEvent (ntpEvent); syncEventTriggered = false; } //----------------------------------------Button para reconfigurar ------------ if (butt_flag == true) { //set config save notify callback //wifiManager.setSaveConfigCallback(saveConfigCallback); WiFiManagerParameter custom_mqtt_server("server", "Server address", mqtt_server, 40); WiFiManagerParameter custom_mqtt_port("port", "Server port", mqtt_port, 5); WiFiManagerParameter custom_TimeZone("TimeZone", "Time Zone", TimeZone, 5); //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode wifiManager.setAPCallback(configModeCallback); //set minimu quality of signal so it ignores AP's under that quality //defaults to 8% //wifiManager.setMinimumSignalQuality(); ticker.attach(0.2, tick); wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); wifiManager.setConfigPortalTimeout(120); // auto close configportal after n seconds if (!wifiManager.startConfigPortal(Buf,password)) { Serial.println("failed to connect or hit timeout"); delay(300); } else { //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); Serial.println(modes[WiFi.getMode()]); WiFi.mode(WIFI_STA); Serial.println(modes[WiFi.getMode()]); ticker.detach(); //keep LED on digitalWrite(BUILTIN_LED, 1); } //read updated parameters strcpy(mqtt_server, custom_mqtt_server.getValue()); strcpy(mqtt_port, custom_mqtt_port.getValue()); strcpy(TimeZone, custom_TimeZone.getValue()); //save the custom parameters to FS if (shouldSaveConfig) { Serial.println("saving config"); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject(); json["mqtt_server"] = mqtt_server; json["mqtt_port"] = mqtt_port; json["TimeZone"] = TimeZone; json["ip"] = WiFi.localIP().toString(); json["gateway"] = WiFi.gatewayIP().toString(); json["subnet"] = WiFi.subnetMask().toString(); File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { Serial.println("failed to open config file for writing"); } json.prettyPrintTo(Serial); json.printTo(configFile); configFile.close(); //end save } //-------------------------------end SPIFFS configuration----------- Serial.println(); ticker.detach(); //keep LED on digitalWrite(BUILTIN_LED, 1); //----------------------------webserver------------- server.reset(new ESP8266WebServer(WiFi.localIP(), 80)); server->on("/", handleRoot); //---------------------mdns--------------- if (!MDNS.begin(Buf)) { Serial.println("Error setting up MDNS responder!"); while(1) { delay(1000); } } Serial.println("mDNS responder started"); //---------------------webserver------- server->onNotFound(handleNotFound); server->begin(); Serial.println("HTTP server started"); //---- Add service to MDNS-SD MDNS.addService("http", "tcp", 80); butt_flag = false; } else { } } ```
Author
Owner

@rodri16 commented on GitHub (Sep 5, 2018):

*WM: [2] AccessPoint set password is VALID
*WM: [1] Dispositive
*WM: [3] WiFi station enable
*WM: [2] Enabling AP
*WM: [1] StartAP with SSID: Disp_3
Entered config mode
0.0.0.0
Disp_3
*WM: [1] Custom AP IP/GW/Subnet:
[APConfig] local_ip: 10.0.1.1 gateway: 10.0.1.1 subnet: 255.255.255.0
[APConfig] wifi_softap_dhcps_stop failed!
[APConfig] wifi_set_ip_info failed!
[APConfig] DHCP IP start: 10.0.1.100
[APConfig] DHCP IP end: 10.0.1.200
[APConfig] wifi_set_ip_info failed!
[APConfig] wifi_softap_set_dhcps_lease_time failed!
[APConfig] wifi_softap_dhcps_start failed!
[APConfig] IP config Invalid?!
*WM: [0] [ERROR] softAPConfig failed!
mode : sta(ec:fa:bc:00:a2:5f) + softAP(ee:fa:bc:00:a2:5f)
add if1
pm close 7
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
wifi evt: 8
wifi evt: 8
bcn 0
del if1
pm open,type:2 0
add if1
pm close 7
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
*WM: [1] AP IP address: 192.168.4.1
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 192.168.4.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan ASYNC started
*WM: [2] Config Portal Running, blocking, waiting for clients...
*WM: [2] Portal Timeout In 118 seconds
scandone
*WM: [2] WiFi Scan ASYNC completed in 1600 ms
*WM: [2] WiFi Scan ASYNC found: 12
wifi evt: 7

<!-- gh-comment-id:418768911 --> @rodri16 commented on GitHub (Sep 5, 2018): *WM: [2] AccessPoint set password is VALID *WM: [1] Dispositive *WM: [3] WiFi station enable *WM: [2] Enabling AP *WM: [1] StartAP with SSID: Disp_3 Entered config mode 0.0.0.0 Disp_3 *WM: [1] Custom AP IP/GW/Subnet: [APConfig] local_ip: 10.0.1.1 gateway: 10.0.1.1 subnet: 255.255.255.0 [APConfig] wifi_softap_dhcps_stop failed! [APConfig] wifi_set_ip_info failed! [APConfig] DHCP IP start: 10.0.1.100 [APConfig] DHCP IP end: 10.0.1.200 [APConfig] wifi_set_ip_info failed! [APConfig] wifi_softap_set_dhcps_lease_time failed! [APConfig] wifi_softap_dhcps_start failed! [APConfig] IP config Invalid?! *WM: [0] [ERROR] softAPConfig failed! mode : sta(ec:fa:bc:00:a2:5f) + softAP(ee:fa:bc:00:a2:5f) add if1 pm close 7 dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1) bcn 100 wifi evt: 8 wifi evt: 8 bcn 0 del if1 pm open,type:2 0 add if1 pm close 7 dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1) bcn 100 *WM: [1] AP IP address: 192.168.4.1 *WM: [3] setupConfigPortal *WM: [1] Starting Web Portal *WM: [3] dns server started with ip: 192.168.4.1 *WM: [2] HTTP server started *WM: [2] WiFi Scan ASYNC started *WM: [2] Config Portal Running, blocking, waiting for clients... *WM: [2] Portal Timeout In 118 seconds scandone *WM: [2] WiFi Scan ASYNC completed in 1600 ms *WM: [2] WiFi Scan ASYNC found: 12 wifi evt: 7
Author
Owner

@tablatronix commented on GitHub (Sep 5, 2018):

cant reproduce, it has something to do with your other code, or the mode its in

wifi_softap_dhcps_stop failed
I have no idea why this would be failing, maybe conflict with starting mode, or is not switching ap correctly.

It could also be an open issue I have in esp with enableAP

you can maybe add a delay in

bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
    DEBUG_WIFI("[APConfig] local_ip: %s gateway: %s subnet: %s\n", local_ip.toString().c_str(), gateway.toString().c_str(), subnet.toString().c_str());
    if(!WiFi.enableAP(true)) {
        // enable AP failed
        DEBUG_WIFI("[APConfig] enableAP failed!\n");
        return false;
    }
delay(1000); // race condition delay workaround
``
<!-- gh-comment-id:418781537 --> @tablatronix commented on GitHub (Sep 5, 2018): cant reproduce, it has something to do with your other code, or the mode its in `wifi_softap_dhcps_stop failed` I have no idea why this would be failing, maybe conflict with starting mode, or is not switching ap correctly. It could also be an open issue I have in esp with enableAP you can maybe add a delay in ```C++ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet) { DEBUG_WIFI("[APConfig] local_ip: %s gateway: %s subnet: %s\n", local_ip.toString().c_str(), gateway.toString().c_str(), subnet.toString().c_str()); if(!WiFi.enableAP(true)) { // enable AP failed DEBUG_WIFI("[APConfig] enableAP failed!\n"); return false; } delay(1000); // race condition delay workaround ``
Author
Owner

@tablatronix commented on GitHub (Sep 5, 2018):

I also wonder if swapping the order of these 2 would help

// wifimanager.cpp
  // setup optional soft AP static ip config
  if (_ap_static_ip) {
    DEBUG_WM(F("Custom AP IP/GW/Subnet:"));
    if(!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)){
      DEBUG_WM(DEBUG_ERROR,"[ERROR] softAPConfig failed!");
    }
  }

  #ifdef ESP8266
    // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372
    if(!WiFi.enableAP(true)) {
      DEBUG_WM(DEBUG_ERROR,"[ERROR] enableAP failed!");
      return false;
    }
    delay(500); // workaround delay
  #endif

and place the enableap before the softAPConfig

<!-- gh-comment-id:418786980 --> @tablatronix commented on GitHub (Sep 5, 2018): I also wonder if swapping the order of these 2 would help ```C++ // wifimanager.cpp // setup optional soft AP static ip config if (_ap_static_ip) { DEBUG_WM(F("Custom AP IP/GW/Subnet:")); if(!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)){ DEBUG_WM(DEBUG_ERROR,"[ERROR] softAPConfig failed!"); } } #ifdef ESP8266 // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372 if(!WiFi.enableAP(true)) { DEBUG_WM(DEBUG_ERROR,"[ERROR] enableAP failed!"); return false; } delay(500); // workaround delay #endif ``` and place the enableap before the softAPConfig
Author
Owner

@rodri16 commented on GitHub (Sep 6, 2018):

Yes you are right @tablatronix! Swapping enableAP before softAPConfig problem solved!!! Thank you!

<!-- gh-comment-id:419039836 --> @rodri16 commented on GitHub (Sep 6, 2018): Yes you are right @tablatronix! Swapping enableAP before softAPConfig problem solved!!! Thank you!
Author
Owner

@tablatronix commented on GitHub (Sep 20, 2018):

#722

<!-- gh-comment-id:423259928 --> @tablatronix commented on GitHub (Sep 20, 2018): #722
Author
Owner

@tablatronix commented on GitHub (Oct 12, 2018):

I moved the wifiManager.setAPCallback(); after startap, I think will break this implementation
It now fires after ap is started , so it can get ip and stuff

do we need a startapconfig callback, is there anything that needs to be done here that cannot be set via wm ahead of time ?

<!-- gh-comment-id:429461173 --> @tablatronix commented on GitHub (Oct 12, 2018): I moved the wifiManager.setAPCallback(); after startap, I think will break this implementation It now fires after ap is started , so it can get ip and stuff do we need a startapconfig callback, is there anything that needs to be done here that cannot be set via wm ahead of time ?
Author
Owner

@tablatronix commented on GitHub (May 11, 2020):

Where did we leave off here ? ughh

I think its safe to close, might need to reopen a new issue for more callbacks if needed

<!-- gh-comment-id:626866191 --> @tablatronix commented on GitHub (May 11, 2020): Where did we leave off here ? ughh I think its safe to close, might need to reopen a new issue for more callbacks if needed
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#603
No description provided.