[GH-ISSUE #1320] Using WifiManager with NTPClient #1133

Closed
opened 2026-02-28 01:28:40 +03:00 by kerem · 9 comments
Owner

Originally created by @Abhesheksh on GitHub (Dec 15, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1320

Basic Infos

Hardware

WiFimanager Branch/Release: Master

Esp8266/Esp32: ESP8266 / NodeMCU

Hardware: ESP-12E

Core Version: 2.4.0, staging

Description

Using NTPClient to get RTC doesnt work with wifimanager. Same code works when connecting with ssid and password after removing WM.

Problem description

When using NTPClient with WM, time starts from 0:0 and then refreshes but doesn't show actual time.

Settings in IDE

Module: NodeMcu

Additional libraries:

Sketch

#BEGIN

#include <Ticker.h>
#include <ESP8266WiFi.h>
#include "ESP8266Ping.h"
#include <WiFiManager.h>
//#include <EEPROM.h>
#include <EasyButton.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

Ticker ticker;

#define MOSFET 4
#define SWITCH 0
#define DETECT A0
#define LED 2
#define GLED 5
#define DEBUG True

// Update these with values suitable for your network.
WiFiManager wifiManager;

EasyButton button(SWITCH);

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");


//WiFiClient espClient;
bool isButtonPressed = false;
void onPressedForDuration();
void led_blink();
void led_blink2();

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

void configModeCallback (WiFiManager *myWiFiManager) {
  Serial.println("Entered config mode");
  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.5, tick);
}

void setup() {

  pinMode(SWITCH, INPUT);     // Initialize the GPIO2 pin as an output
  pinMode(MOSFET, OUTPUT);     // Initialize the GPIO0 pin as an output
  pinMode(DETECT, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(GLED, OUTPUT);

  ticker.attach(0.1, tick);

  digitalWrite(MOSFET, LOW);   // Turn MOSFET ON (Note that LOW or HIGH is the voltage level
  //digitalWrite(LED, HIGH);
  digitalWrite(GLED, HIGH);
  button.begin();
  button.onPressedFor(5000, onPressedForDuration);



  wifiManager.setAPCallback(configModeCallback);

#ifdef DEBUG
  Serial.begin(115200);
#endif



  //wifiManager.resetSettings();
  WiFi.mode(WIFI_STA);

  wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 1, 19), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0));


  // fetches ssid and pass from eeprom and tries to connect
  // if it does not connect it starts an access point with the specified name
  // here  "AutoConnectAP"
  // and goes into a blocking loop awaiting configuration
  wifiManager.setConfigPortalTimeout(900);
  wifiManager.setConnectTimeout(90000);
  wifiManager.setWiFiAPHidden(false);
  wifiManager.setSTAStaticIPConfig(IPAddress(192, 168, 1, 99), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0));
  wifiManager.autoConnect("TORLAJE_AP");


  if (wifiManager.autoConnect() == true)
  {
    Serial.println("OK CONNECT");
    ticker.detach();
    digitalWrite(LED, LOW);

  }
  else
  {
    Serial.println("FALSE - NO CONNECT");
   
  }


  // if you get here you have connected to the WiFi
  Serial.println("Connected.");
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());
  
  delay(200);
  timeClient.begin();
}

void loop() {

  button.read();
  timeClient.update();


  
   Serial.print(timeClient.getHours());
   Serial.print(":");
   Serial.println(timeClient.getMinutes());
 

}

void onPressedForDuration()
{
  isButtonPressed = true;
  wifiManager.resetSettings();
  ESP.eraseConfig();
  Serial.println("BUTTON PRESSED.");
  ESP.reset();
  led_blink();
  Serial.println("Button pressed");
}

void led_blink()
{
  int i = 0;
  while (i < 3)
  {
    digitalWrite(LED, HIGH);
    delay(500);
    digitalWrite(LED, LOW);
    delay(500);
    digitalWrite(LED, HIGH);
    i = i + 1;
  }
}
void led_blink2()
{
  int i = 0;
  while (i < 2)
  {
    digitalWrite(LED, LOW);
    delay(50);
    digitalWrite(LED, HIGH);
    delay(50);
    digitalWrite(LED, LOW);
    i = i + 1;
  }
}


#END

Debug Messages

⸮⸮⸮ bp⸮⸮c$r$p⸮n⸮⸮l ⸮⸮  "n⸮|⸮$⸮⸮ ⸮c⸮|~⸮N⸮l⸮⸮l ⸮ondnr⸮⸮⸮o bl s⸮⸮N bl ⸮#⸮⸮$⸮⸮r⸮`⸮⸮o⸮*WM: [1] AutoConnect
*WM: [2] Connecting as wifi client...
*WM: [3] STA static IP: 192.168.1.99
*WM: [2] Custom static IP/GW/Subnet/DNS
*WM: [2] Custom STA IP/GW/Subnet
*WM: [1] STA IP set: 192.168.1.99
*WM: [1] Connecting to SAVED AP: JHKAHKJAH
*WM: [3] Using Password: JAKHAKAH
*WM: [3] WiFi station enable
*WM: [3] enableSTA PERSISTENT ON
*WM: [2] 90000000 ms connectTimeout set
*WM: [2] 19072 ms timeout, waiting for connect...
*WM: [2] .
*WM: [2] .
*WM: [2] .
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] AutoConnect: SUCCESS
*WM: [1] STA IP Address: 192.168.1.99
*WM: [1] AutoConnect
*WM: [1] AutoConnect: ESP Already Connected
*WM: [3] STA static IP: 192.168.1.99
*WM: [2] Custom static IP/GW/Subnet/DNS
*WM: [2] Custom STA IP/GW/Subnet
*WM: [1] STA IP set: 192.168.1.99
*WM: [1] AutoConnect: SUCCESS
*WM: [1] STA IP Address: 192.168.1.99
OK CONNECT
Connected.
IP address: 192.168.1.99
0:0
0:0
0:0
0:0
0:0
0:0
0:0
0:0
0:0
0:0
0:0

messages here
Originally created by @Abhesheksh on GitHub (Dec 15, 2021). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1320 ### Basic Infos #### Hardware WiFimanager Branch/Release: Master Esp8266/Esp32: ESP8266 / NodeMCU Hardware: ESP-12E Core Version: 2.4.0, staging ### Description Using NTPClient to get RTC doesnt work with wifimanager. Same code works when connecting with ssid and password after removing WM. Problem description When using NTPClient with WM, time starts from 0:0 and then refreshes but doesn't show actual time. ### Settings in IDE Module: NodeMcu Additional libraries: ### Sketch ```cpp #BEGIN #include <Ticker.h> #include <ESP8266WiFi.h> #include "ESP8266Ping.h" #include <WiFiManager.h> //#include <EEPROM.h> #include <EasyButton.h> #include <NTPClient.h> #include <WiFiUdp.h> Ticker ticker; #define MOSFET 4 #define SWITCH 0 #define DETECT A0 #define LED 2 #define GLED 5 #define DEBUG True // Update these with values suitable for your network. WiFiManager wifiManager; EasyButton button(SWITCH); // Define NTP Client to get time WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "pool.ntp.org"); //WiFiClient espClient; bool isButtonPressed = false; void onPressedForDuration(); void led_blink(); void led_blink2(); void tick() { //toggle state int state = digitalRead(LED); // get the current state of GPIO1 pin digitalWrite(LED, !state); // set pin to the opposite state } void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("Entered config mode"); 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.5, tick); } void setup() { pinMode(SWITCH, INPUT); // Initialize the GPIO2 pin as an output pinMode(MOSFET, OUTPUT); // Initialize the GPIO0 pin as an output pinMode(DETECT, INPUT); pinMode(LED, OUTPUT); pinMode(GLED, OUTPUT); ticker.attach(0.1, tick); digitalWrite(MOSFET, LOW); // Turn MOSFET ON (Note that LOW or HIGH is the voltage level //digitalWrite(LED, HIGH); digitalWrite(GLED, HIGH); button.begin(); button.onPressedFor(5000, onPressedForDuration); wifiManager.setAPCallback(configModeCallback); #ifdef DEBUG Serial.begin(115200); #endif //wifiManager.resetSettings(); WiFi.mode(WIFI_STA); wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 1, 19), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0)); // fetches ssid and pass from eeprom and tries to connect // if it does not connect it starts an access point with the specified name // here "AutoConnectAP" // and goes into a blocking loop awaiting configuration wifiManager.setConfigPortalTimeout(900); wifiManager.setConnectTimeout(90000); wifiManager.setWiFiAPHidden(false); wifiManager.setSTAStaticIPConfig(IPAddress(192, 168, 1, 99), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0)); wifiManager.autoConnect("TORLAJE_AP"); if (wifiManager.autoConnect() == true) { Serial.println("OK CONNECT"); ticker.detach(); digitalWrite(LED, LOW); } else { Serial.println("FALSE - NO CONNECT"); } // if you get here you have connected to the WiFi Serial.println("Connected."); Serial.print("IP address:\t"); Serial.println(WiFi.localIP()); delay(200); timeClient.begin(); } void loop() { button.read(); timeClient.update(); Serial.print(timeClient.getHours()); Serial.print(":"); Serial.println(timeClient.getMinutes()); } void onPressedForDuration() { isButtonPressed = true; wifiManager.resetSettings(); ESP.eraseConfig(); Serial.println("BUTTON PRESSED."); ESP.reset(); led_blink(); Serial.println("Button pressed"); } void led_blink() { int i = 0; while (i < 3) { digitalWrite(LED, HIGH); delay(500); digitalWrite(LED, LOW); delay(500); digitalWrite(LED, HIGH); i = i + 1; } } void led_blink2() { int i = 0; while (i < 2) { digitalWrite(LED, LOW); delay(50); digitalWrite(LED, HIGH); delay(50); digitalWrite(LED, LOW); i = i + 1; } } #END ``` ### Debug Messages ⸮⸮⸮ bp⸮⸮c$`r$p⸮n⸮⸮l ⸮⸮  "n⸮|⸮$⸮⸮ ⸮c⸮|~⸮N⸮l⸮⸮l ⸮ond`nr⸮⸮⸮o bl s⸮⸮N bl ⸮#⸮⸮$⸮⸮r⸮`⸮⸮o⸮*WM: [1] AutoConnect *WM: [2] Connecting as wifi client... *WM: [3] STA static IP: 192.168.1.99 *WM: [2] Custom static IP/GW/Subnet/DNS *WM: [2] Custom STA IP/GW/Subnet *WM: [1] STA IP set: 192.168.1.99 *WM: [1] Connecting to SAVED AP: JHKAHKJAH *WM: [3] Using Password: JAKHAKAH *WM: [3] WiFi station enable *WM: [3] enableSTA PERSISTENT ON *WM: [2] 90000000 ms connectTimeout set *WM: [2] 19072 ms timeout, waiting for connect... *WM: [2] . *WM: [2] . *WM: [2] . *WM: [2] Connection result: WL_CONNECTED *WM: [3] lastconxresult: WL_CONNECTED *WM: [1] AutoConnect: SUCCESS *WM: [1] STA IP Address: 192.168.1.99 *WM: [1] AutoConnect *WM: [1] AutoConnect: ESP Already Connected *WM: [3] STA static IP: 192.168.1.99 *WM: [2] Custom static IP/GW/Subnet/DNS *WM: [2] Custom STA IP/GW/Subnet *WM: [1] STA IP set: 192.168.1.99 *WM: [1] AutoConnect: SUCCESS *WM: [1] STA IP Address: 192.168.1.99 OK CONNECT Connected. IP address: 192.168.1.99 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 ``` messages here ```
kerem 2026-02-28 01:28:40 +03:00
  • closed this issue
  • added the
    Question
    label
Author
Owner

@Abhesheksh commented on GitHub (Dec 16, 2021):

https://github.com/tzapu/WiFiManager/issues/1097

Same issue but he solved it by removing static IP. Is there anyway I can keep the static IP?

<!-- gh-comment-id:995450835 --> @Abhesheksh commented on GitHub (Dec 16, 2021): https://github.com/tzapu/WiFiManager/issues/1097 Same issue but he solved it by removing static IP. Is there anyway I can keep the static IP?
Author
Owner

@tablatronix commented on GitHub (Feb 3, 2022):

Not sure why this would make a difference, it should still work

<!-- gh-comment-id:1028549806 --> @tablatronix commented on GitHub (Feb 3, 2022): Not sure why this would make a difference, it should still work
Author
Owner

@Georgie9117 commented on GitHub (Nov 1, 2022):

Just leave wifiManager.setSTAStaticIPConfig and use this after wifiManager.autoConnect

WiFi.begin();
WiFi.config(IPAddress(192, 168, 1, 148), IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0));

It working for me on ESP8266.

<!-- gh-comment-id:1298419089 --> @Georgie9117 commented on GitHub (Nov 1, 2022): Just leave `wifiManager.setSTAStaticIPConfig` and use this after `wifiManager.autoConnect` ``` WiFi.begin(); WiFi.config(IPAddress(192, 168, 1, 148), IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0)); ``` It working for me on ESP8266.
Author
Owner

@samuraiyy commented on GitHub (Jul 17, 2023):

This is my method,it works:

 //wm.setSTAStaticIPConfig(IPAddress(192,168,2,123), IPAddress(192,168,2,1), IPAddress(255,255,255,0) ); // set static ip,gw,sn  
 wm.setShowStaticFields(true);
 wm.setShowDnsFields(true);  

or

 wm.setSTAStaticIPConfig(IPAddress(192,168,2,123), IPAddress(192,168,2,1), IPAddress(255,255,255,0), IPAddress(192,168,2,1) ); // set static ip,gw,sn  
 wm.setShowStaticFields(true);
 wm.setShowDnsFields(true);  
<!-- gh-comment-id:1638388145 --> @samuraiyy commented on GitHub (Jul 17, 2023): This is my method,it works: //wm.setSTAStaticIPConfig(IPAddress(192,168,2,123), IPAddress(192,168,2,1), IPAddress(255,255,255,0) ); // set static ip,gw,sn wm.setShowStaticFields(true); wm.setShowDnsFields(true); or wm.setSTAStaticIPConfig(IPAddress(192,168,2,123), IPAddress(192,168,2,1), IPAddress(255,255,255,0), IPAddress(192,168,2,1) ); // set static ip,gw,sn wm.setShowStaticFields(true); wm.setShowDnsFields(true);
Author
Owner

@ChumKiu commented on GitHub (Feb 7, 2025):

Just leave wifiManager.setSTAStaticIPConfig and use this after wifiManager.autoConnect

WiFi.begin();
WiFi.config(IPAddress(192, 168, 1, 148), IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0));

It working for me on ESP8266.

This working form me on a ESP32, here below my code snippet into the setup() function:

`WiFiManager wm;

// Set static IP (also visible into the AP page)
//wm.setSTAStaticIPConfig(IPAddress(192,168,2,199), IPAddress(192,168,2,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

bool res;
res = wm.autoConnect("AutoConnectAP","MyPassword");

WiFi.begin();
WiFi.config(IPAddress(192, 168, 2, 199), IPAddress(192, 168, 2, 1), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0));

if(!res) {
wm.resetSettings();
delay(1000);
// AP connection failed
Serial.println("(Start) Failed to connect to the AutoConnectAP AP!");
Serial.println("(Start) System will be reset...");
delay(3000);
ESP.restart();
delay(5000);
}
else {
// WiFi connection with saved credential was succesfully
Serial.print("(Start) Connected to: ");
Serial.println(WiFi.localIP());

}

// --------------------------------------------------
// NTP settings
// --------------------------------------------------

sntp_servermode_dhcp(1); // (optional)
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");
sntp_set_time_sync_notification_cb(timeavailable); // set notification call-back function
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2);`

<!-- gh-comment-id:2643973926 --> @ChumKiu commented on GitHub (Feb 7, 2025): > Just leave `wifiManager.setSTAStaticIPConfig` and use this after `wifiManager.autoConnect` > > ``` > WiFi.begin(); > WiFi.config(IPAddress(192, 168, 1, 148), IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0)); > ``` > > It working for me on ESP8266. This working form me on a ESP32, here below my code snippet into the setup() function: `WiFiManager wm; // Set static IP (also visible into the AP page) //wm.setSTAStaticIPConfig(IPAddress(192,168,2,199), IPAddress(192,168,2,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 bool res; res = wm.autoConnect("AutoConnectAP","MyPassword"); WiFi.begin(); WiFi.config(IPAddress(192, 168, 2, 199), IPAddress(192, 168, 2, 1), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); if(!res) { wm.resetSettings(); delay(1000); // AP connection failed Serial.println("(Start) Failed to connect to the AutoConnectAP AP!"); Serial.println("(Start) System will be reset..."); delay(3000); ESP.restart(); delay(5000); } else { // WiFi connection with saved credential was succesfully Serial.print("(Start) Connected to: "); Serial.println(WiFi.localIP()); } // -------------------------------------------------- // NTP settings // -------------------------------------------------- sntp_servermode_dhcp(1); // (optional) while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" CONNECTED"); sntp_set_time_sync_notification_cb(timeavailable); // set notification call-back function configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2);`
Author
Owner

@tablatronix commented on GitHub (Feb 8, 2025):

This is literally in one of the examples and works

<!-- gh-comment-id:2644429701 --> @tablatronix commented on GitHub (Feb 8, 2025): This is literally in one of the examples and works
Author
Owner

@ChumKiu commented on GitHub (Feb 8, 2025):

This is literally in one of the examples and works

Hi, I've see the AutoConnectWithStaticIP.ino example, but the sequence of the instruction is different, the setSTAStaticIPConfig() method is before the autoConnect() call and this is not working for me, the only way is to put the instructions sequence:

WiFi.begin();
WiFi.config(IPAddress(192, 168, 2, 199), IPAddress(192, 168, 2, 1), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0));

after the autoConnect() method call. In this way looking at the log start I can see for a moment the Dinamic IP set through the DHCP immediately followed by the static IP assignement, but this is not a problem for me, here a shot of the output log:

Starting
*wm:AutoConnect
*wm:Connecting to SAVED AP: ITALSENSOR-BASE
*wm:connectTimeout not set, ESP waitForConnectResult...
*wm:AutoConnect: SUCCESS
*wm:STA IP Address: 192.168.2.198
(Start) Connected to: 192.168.2.199

the (Start) means my output, the other line is from the library. You can see that after the AutoConnect I've the dynamic IP ...198 followed by the static one ...199.

There is other specific example about to set the static IP?

As a side note, may be useful, in my design I'm using at this time:

  • WiFiManager (to have AP and configure local WiFi network)
  • HTTP Web Server (to manage some commands)
  • SD manager (to store and retrieve large file)
  • FTP manager (to upload / download file from SD card)
  • NTP Client (to have an update timestamp)

Thanks and best regards.
ChumKiu

<!-- gh-comment-id:2644737122 --> @ChumKiu commented on GitHub (Feb 8, 2025): > This is literally in one of the examples and works Hi, I've see the **AutoConnectWithStaticIP.ino** example, but the sequence of the instruction is different, the **setSTAStaticIPConfig()** method is before the **autoConnect()** call and this is not working for me, the only way is to put the instructions sequence: ` WiFi.begin();` ` WiFi.config(IPAddress(192, 168, 2, 199), IPAddress(192, 168, 2, 1), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); ` after the **autoConnect()** method call. In this way looking at the log start I can see for a moment the Dinamic IP set through the DHCP immediately followed by the static IP assignement, but this is not a problem for me, here a shot of the output log: `Starting` `*wm:AutoConnect` `*wm:Connecting to SAVED AP: ITALSENSOR-BASE` `*wm:connectTimeout not set, ESP waitForConnectResult... ` `*wm:AutoConnect: SUCCESS ` `*wm:STA IP Address: 192.168.2.198` `(Start) Connected to: 192.168.2.199` the (Start) means my output, the other line is from the library. You can see that after the AutoConnect I've the dynamic IP ...198 followed by the static one ...199. There is other specific example about to set the static IP? As a side note, may be useful, in my design I'm using at this time: - WiFiManager (to have AP and configure local WiFi network) - HTTP Web Server (to manage some commands) - SD manager (to store and retrieve large file) - FTP manager (to upload / download file from SD card) - NTP Client (to have an update timestamp) Thanks and best regards. ChumKiu
Author
Owner

@tablatronix commented on GitHub (Feb 8, 2025):

Are you sure this isnt esp autoconnect?
Have you tested without calling wm at all ?

or add wifi mode off

<!-- gh-comment-id:2645739127 --> @tablatronix commented on GitHub (Feb 8, 2025): Are you sure this isnt esp autoconnect? Have you tested without calling wm at all ? or add wifi mode off
Author
Owner

@ChumKiu commented on GitHub (Feb 10, 2025):

Are you sure this isnt esp autoconnect? Have you tested without calling wm at all ?

or add wifi mode off

Hi,
I think to have solved, after reading with more attention the README I've see the following note related to the NTP stuff:

NOTE: You should fill DNS server if you have HTTP requests with hostnames or syncronize time (NTP). It's the same as gateway ip or a popular (Google DNS: 8.8.8.8).

in my first code, into the setSTAStaticIPConfig() method call, I've not set the DNS value, by putting it now all is working as expected so here below my updated setup() code:

  WiFiManager wm;

  // Set static IP (also visible into the AP page)
  wm.setSTAStaticIPConfig(IPAddress(192,168,2,199), IPAddress(192,168,2,1), IPAddress(255,255,255,0), IPAddress(192,168,2,1)); // set static ip,gw,sn,dns
  wm.setShowStaticFields(true); // force show static ip fields
  wm.setShowDnsFields(true);    // force show dns field always

  bool res;
  res = wm.autoConnect("AutoConnectAP","MyPassword");
  if(!res) {
      wm.resetSettings();
      delay(1000);
      // AP connection failed
      Serial.println("(Start) Failed to connect to the AutoConnectAP AP!");
      Serial.println("(Start) System will be reset...");
      delay(3000);
      ESP.restart();
      delay(5000);
  } 
  else {
      // WiFi connection with saved credential was succesfully
      Serial.print("(Start) Connected to: ");
      Serial.println(WiFi.localIP());
      
      // Read ESP32 MAC address and print over serial
      uint64_t espChipID = ESP.getEfuseMac();
      Serial.print("(Start) ESP32 MAC: ");
      Serial.println(mac2String((byte*) &espChipID));
  }

and also the NTP is working properly.

And here below my start log:

 Starting
*wm:AutoConnect 
*wm:STA IP set: 192.168.2.199
*wm:No wifi saved, skipping 
*wm:AutoConnect: FAILED for  1 ms
*wm:StartAP with SSID:  AutoConnectAP
*wm:AP IP address: 192.168.4.1
*wm:Starting Web Portal 
*wm:19 networks found
*wm:19 networks found
*wm:STA IP set: 192.168.2.199
*wm:Connecting to NEW AP: ITALSENSOR-BASE
*wm:connectTimeout not set, ESP waitForConnectResult... 
*wm:Connect to new AP [SUCCESS] 
*wm:Got IP Address: 
*wm:192.168.2.199 
*wm:config portal exiting 
(Start) Connected to: 192.168.2.199
...

Thanks!!

BR
ChumKiu

<!-- gh-comment-id:2647311604 --> @ChumKiu commented on GitHub (Feb 10, 2025): > Are you sure this isnt esp autoconnect? Have you tested without calling wm at all ? > > or add wifi mode off Hi, I think to have solved, after reading with more attention the README I've see the following note related to the NTP stuff: ```` NOTE: You should fill DNS server if you have HTTP requests with hostnames or syncronize time (NTP). It's the same as gateway ip or a popular (Google DNS: 8.8.8.8). ```` in my first code, into the **setSTAStaticIPConfig()** method call, I've not set the DNS value, by putting it now all is working as expected so here below my updated **setup()** code: ``` WiFiManager wm; // Set static IP (also visible into the AP page) wm.setSTAStaticIPConfig(IPAddress(192,168,2,199), IPAddress(192,168,2,1), IPAddress(255,255,255,0), IPAddress(192,168,2,1)); // set static ip,gw,sn,dns wm.setShowStaticFields(true); // force show static ip fields wm.setShowDnsFields(true); // force show dns field always bool res; res = wm.autoConnect("AutoConnectAP","MyPassword"); if(!res) { wm.resetSettings(); delay(1000); // AP connection failed Serial.println("(Start) Failed to connect to the AutoConnectAP AP!"); Serial.println("(Start) System will be reset..."); delay(3000); ESP.restart(); delay(5000); } else { // WiFi connection with saved credential was succesfully Serial.print("(Start) Connected to: "); Serial.println(WiFi.localIP()); // Read ESP32 MAC address and print over serial uint64_t espChipID = ESP.getEfuseMac(); Serial.print("(Start) ESP32 MAC: "); Serial.println(mac2String((byte*) &espChipID)); } ``` and also the NTP is working properly. And here below my start log: ``` Starting *wm:AutoConnect *wm:STA IP set: 192.168.2.199 *wm:No wifi saved, skipping *wm:AutoConnect: FAILED for 1 ms *wm:StartAP with SSID: AutoConnectAP *wm:AP IP address: 192.168.4.1 *wm:Starting Web Portal *wm:19 networks found *wm:19 networks found *wm:STA IP set: 192.168.2.199 *wm:Connecting to NEW AP: ITALSENSOR-BASE *wm:connectTimeout not set, ESP waitForConnectResult... *wm:Connect to new AP [SUCCESS] *wm:Got IP Address: *wm:192.168.2.199 *wm:config portal exiting (Start) Connected to: 192.168.2.199 ... ``` Thanks!! BR ChumKiu
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#1133
No description provided.