Open mrWheel opened 2 years ago
Strange ..?
If I put this in setup()
:
//-- 0, 0 because we will use TZ in the next line configTime(0, 0, ntpServer); //-- Set environment variable with your time zone setenv("TZ", getTzByLocation(TzLocation).c_str(), 1); tzset(); printLocalTime();
then it "works"!
Attempting to connect to WPA SSID: myNetwork setup ( 79): Connected to WiFi network. setup ( 80): Connect with Telnet client to 192.168.12.141 printLocalTime ( 22): Saturday, March 26 2022 13:27:25 HTTP httpServer started printLocalTime ( 22): Saturday, March 26 2022 13:28:20
@mrWheel: Can you test something for me? In the original code, can you add the following for me?
#define ARDUINO_ARCH_ESP32
Right above:
#include "time_zones.h"
My guess is that the identifier ARDUINO_ARCH_ESP32
not being defined for your board, so instead of using the ESP32 code, it was using the code for the ESP8266.
@marciot Ok. added the #define:
#include <WiFi.h> #define ARDUINO_ARCH_ESP32 #include "time_zones.h"
With no change. Still cannot obtain the time :-(
Failed to obtain time Failed to obtain time .
I had already changed configTimeWithTz()
to:
void configTimeWithTz(String tz, String ntp_addr) { #ifdef ESP8266 // ESP8266 configTime(tz.c_str(), ntp_addr.c_str()); // --> for the ESP8266 only #else // ESP32 seems to be a little more complex: configTime(0, 0, ntp_addr.c_str()); // 0, 0 because we will use TZ in the next line setenv("TZ", tz.c_str(), 1); // Set environment variable with your time zone tzset(); #endif }
As most libraries nowadays test for ESP8266
@mrWheel: Did you have an extra #include
? If that wasn't a typo, then try removing that and see if it makes a difference.
#include <-- Not this
#define ARDUINO_ARCH_ESP32
#include "time_zones.h"
As most libraries nowadays test for ESP8266
Good to know! I can change that.
Did you have an extra #include? No, it is "#include
Good to know! I can change that.
But it did not make it "work"!!!
@mrWheel: How about changing configTimeWithTz
to:
void configTimeWithTz(String tz, String ntp_addr) {
// ESP32 seems to be a little more complex:
configTime(0, 0, ntp_addr.c_str()); // 0, 0 because we will use TZ in the next line
setenv("TZ", tz.c_str(), 1); // Set environment variable with your time zone
tzset();
}
Since this is a ESP32 example, I guess I don't really need code for the ESP8266
Already did that too.
I think the problem is in the scope of setenv()
or tzset()
..
@mrWheel: That's so peculiar.
Maybe it has to do with executing “something” on the wrong CPU and than losing focus?
Hi
I have the same problem, and already tried the #define ARDUINO_ARCH_ESP32 suggestion. I'm on arduino IDE 1.8.19, board:ESP32 Dev Moduke, esp32 library 2.0.3 .
Hello,
Writing to inquire if anyone has found a solution at this time. I am running Arduino 2.0.1 on board Adafruit ESP32 Feather.
For anyone looking for a workaround, if you identify the element number of the timezone of interest you can still call:
configTzTime(timezones[element_of_interest], ntpserver1, ntpserver2);
Great project!
I tried it without any change (accept for the WiFi credentials) and this is the output:
Is something broken?
"bare"
ESP32 Wrover Module
Just tested this code:
.. and that works ..