Post links and attach files for documentation here, also chat about these docs freely

User avatar
By lotus49
#48883
schufti wrote:@TO:
if your ESP was only ~4 min wrong for the year, you were lucky. My esp-01 was about 4min wrong per day!
I also tried to correct it in software but had to realize that the diffrence was much depending on ambient temperature. And this simple method gets very complex if your battery powered IoT gadget uses deepsleep.

So yes, one could save on the rtc but only under very specific circumstances...

Since I do have three DS3231s, I have decided I may as well use them and be reasonably sure that the time will be stable regardless of environmental factors. Clearly it is slightly harder to include one in a project than not but they are so cheap that having to add a small amount of complexity isn't a big deal.

It would be interesting to know to what extent performance varies by device and depending on environmental factors.
User avatar
By torntrousers
#48888
eriksl wrote:It's explained in the SDK documentation.

Mmm thats interesting. Hard to find examples of an ESP8266/Arduino sketch using them though so from a little playing heres one that seems to work without needing any other time libs, printing out "Thu Jun 09 23:23:15 2016":
Code: Select all#include <ESP8266WiFi.h>
#include <time.h>

void setup() {
    Serial.begin(115200); Serial.println();
    WiFi.waitForConnectResult();
    configTime(1 * 3600, 0, "pool.ntp.org", "time.nist.gov");
}

void loop() {
    delay(3000);
    time_t t = time(NULL);
    Serial.println(ctime(&t));
}
User avatar
By eriksl
#48919
torntrousers wrote:
eriksl wrote:It's explained in the SDK documentation.

Mmm thats interesting. Hard to find examples of an ESP8266/Arduino sketch using them though so from a little playing heres one that seems to work without needing any other time libs, printing out "Thu Jun 09 23:23:15 2016":
Code: Select all#include <ESP8266WiFi.h>
#include <time.h>

void setup() {
    Serial.begin(115200); Serial.println();
    WiFi.waitForConnectResult();
    configTime(1 * 3600, 0, "pool.ntp.org", "time.nist.gov");
}

void loop() {
    delay(3000);
    time_t t = time(NULL);
    Serial.println(ctime(&t));
}


I think I missed the point somewhere where you mentioned "Arduino"?
User avatar
By gerardwr
#48975
torntrousers wrote:Mmm thats interesting. Hard to find examples of an ESP8266/Arduino sketch using them though so from a little playing heres one that seems to work without needing any other time libs, printing out "Thu Jun 09 23:23:15 2016":


Yes, that works like a charm, really elegant, great find!

Looking in the library the definition is:
Code: Select allvoid configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)


I am wondering what the 2nd variable of the configTime actually does (daylightOffset_sec). I assumed it is compensating the time when DaylightSaving is applicable, but when I set the variable in the call to 3600, the reported time is the same as with the var set to 0.

Any suggestions?