Notifications
Clear all

WiFiManager Tutorial Doesn't Seem to Work

24 Posts
3 Users
0 Likes
1,546 Views
(@fishbone)
Member
Joined: 1 year ago
Posts: 54
Topic starter  

@zander  You are 100% correct.  For coding in Arduino framework, I think Arduino environment seems to be best.  I first chose PlatformIO because of some of the editing features and debug features (esp32-C3 has embedded JTAG so you can debug without additional hardware).  However, I believe Arduino 2.x has these features as well so like you said, it makes more sense to use it.   I'll probably finish up this project on PIO then pull the whole thing into Arduino.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@fishbone I think you will find as I have there is almost never a need for a debugger. The reason is the majority of the code is in libraries so we only need to write a few dozens or hundreds and very rarely as much as a KLOC (thousand lines of code) Of course when I was a pro, I often wrote in excess of 100KLOC and even had to debug millions of LOC. Even then most debugging was done with the debugger between my ears and no such thing as hardware debugger.

I think the arduino IDE has a software debugger where you can put in 'watch's' and single step your way thru but I have yet to need any of that. My advanced debugging is using mqtt to send the equivalent of serial.println to a raspberry pi screen. Write small functional modules and you will have fewer bugs.

BTW, all you need to do to use the arduino IDE is to rt click and 'Open In' I don't think you need anything more.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@fishbone)
Member
Joined: 1 year ago
Posts: 54
Topic starter  

UPDATE:  I got WiFiManager to work, but am still having an issue.  I am trying to grab the time off NTP server (see this tutorial https://lastminuteengineers.com/esp32-ntp-server-date-time-tutorial/).   I am using WiFiManager on demand and my subroutine is this:

// WiFi Connect
void startWiFi(){ 
  int wifiTimeout = 180;
  const char* ntpServer = "pool.ntp.org";
  const long utcOffsetSeconds = -3600*utcOffset;
  u8g2.clearBuffer();
  u8g2.setFontMode(1);
  u8g2.setDrawColor(2);
  WiFi.mode(WIFI_STA);
  WiFiManager wm;
  wm.resetSettings();
  u8g2.setFont(u8g2_font_freedomSuperTiny_mf);
  u8g2.setCursor(0, 15);
  u8g2.print("STARTING WIFI...");
  u8g2.sendBuffer();
  wm.setConfigPortalTimeout(wifiTimeout); 
  u8g2.setCursor(0, 30);
  u8g2.print("SELECT 'ENCOM DW 1.0'...");
  u8g2.sendBuffer();
  if (!wm.startConfigPortal("ENCOM DW 1.0")) {
    u8g2.setCursor(0, 45);
    u8g2.print("FAILED. WIFI TIMEOUT");
    u8g2.sendBuffer();
    delay(3000);
  }
  else {
    u8g2.setCursor(0,45);
    u8g2.print("CONNECTED: IP "+ WiFi.localIP().toString());
    u8g2.sendBuffer();
    delay(3000);
    configTime(utcOffsetSeconds, 3600*dstFlag, ntpServer);
    tm esp32Now = rtcESP32.getTimeStruct();
    Serial.println(&esp32Now, "%A, %B %d %Y %H:%M:%S");
    rtcDS3231.adjust(DateTime(mktime(&esp32Now)));
  }
  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
  u8g2.setCursor(0, 60);
  u8g2.print("WIFI DISCONNECTED");
  u8g2.sendBuffer();
}  

It appears to work, but the time/date are not correct (yesterday at about 5:00PM Central, I ran it and the time displayed was  1:43 PM WED December 27, 2000 )  

Its a bit off...any ideas?  I checked utcOffsetSeconds was being calculated correctly as was dstFlag.  The line

rtcDS3231.adjust(DateTime(mktime(&esp32Now)));
just syncs the DS3231 clock with the esp32 clock.
 
Fish

   
ReplyQuote
(@fishbone)
Member
Joined: 1 year ago
Posts: 54
Topic starter  

i think I figured out part of this.  When you use configTime, you set the esp32 internal time but NOT the time of the object rtcESP32.  


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@fishbone I would try the esp32time library example and see what that produces.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@fishbone)
Member
Joined: 1 year ago
Posts: 54
Topic starter  

The ESP32Time library uses the esp32 internal time.  The strange thing is, it does update the time correctly, but only after a 2-3 second delay.  During that delay the code is still running because the seconds on the clock display are still moving.  Also, to get this to work, I had to comment out the lines :

  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);

It is acting like it is still getting data from the server but I don't think that is right because I THINK configTime is blocking. 

 

Fish


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@fishbone Those two lines APPEAR to turn off the WiFi so commenting them out allows the WiFi to run. No idea about configTime, never used it.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@fishbone)
Member
Joined: 1 year ago
Posts: 54
Topic starter  

@zander  so here is what I found:  

the configTime(); calls sntp_init(); which keeps updating the esp32s time at certain intervals (I believe default interval is 1 hour). However, you can use sntp_get_sync_status(); to see if the time has completed syncing. sntp_get_sync_status(); can be the following values:

  1. SNTP_SYNC_STATUS_RESET (0): SNTP client is not initialized or has been reset.
  2. SNTP_SYNC_STATUS_IDLE (1): SNTP client is idle and not actively synchronizing time.
  3. SNTP_SYNC_STATUS_IN_PROGRESS (2): SNTP client is currently synchronizing time.
  4. SNTP_SYNC_STATUS_COMPLETED (3): SNTP client has successfully synchronized time.
  5. SNTP_SYNC_STATUS_FAILED (4): SNTP synchronization has failed.

So I changed my code as follows:

// WiFi Connect
void startWiFi(){
int wifiTimeout = 180;
const char* ntpServer = "pool.ntp.org";
const long utcOffsetSeconds = 3600*utcOffset;
sntp_sync_status_t syncStatus;
WiFi.mode(WIFI_STA);
WiFiManager wm;
wm.resetSettings();
wm.setConfigPortalTimeout(wifiTimeout);

if (!wm.startConfigPortal("ENCOM DW 1.0")) {
u8g2.setCursor(0, 45);
u8g2.print("FAILED. WIFI TIMEOUT");
u8g2.sendBuffer();
delay(3000);
}
else {
u8g2.setCursor(0,45);
u8g2.print("CONNECTED.");
u8g2.setCursor(0,60);
u8g2.print("IP "+ WiFi.localIP().toString());
u8g2.sendBuffer();
configTime(utcOffsetSeconds, 3600*dstFlag, ntpServer);
syncStatus = sntp_get_sync_status();
while (syncStatus != SNTP_SYNC_STATUS_COMPLETED) {
syncStatus = sntp_get_sync_status();
delay(100); // Adjust the delay time as per your requirements
}
sntp_stop(); //resets syncStatus to SNTP_SYNC_STATUS_RESET for the next time I initiate

}
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
}

This seems to work well and does what I want it to do.  I think you don't see this in a lot of the tutorials because they either just demonstrate you can get an IP address "yeeey...." or you can grab the time within the next few seconds.  My digital watch is grabbing the time and setting a DS3231 RTC module so I need to make sure I have the esp32 time set before I set the DS3231.  BTW...this pretty much completes my software for my digital watch project!  I will probably find bugs and may add some other features, but for now it is done.  I want to make a video and post soon!

 

Fish


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@fishbone If you have the DS3231 then I don't understand the need to set it more than once. Depending on the size of battery it can last months to years with secs per year accuracy.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 2 / 2