-
I am using a NTP-server for getting the local time. Thnx, henk Sketch fragment: configTime(TZ_INFO, NTP_SERVER);
uint32_t startTime = millis();
Serial.print("wait for first valid timestamp ");
while (time(nullptr) < 100000ul) {
Serial.printf(".");
delay(100);
}
uint32_t runtimeMillis = millis() - startTime;
Serial.printf("\ntime synced in %d ms.\n", runtimeMillis); |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
You can
|
Beta Was this translation helpful? Give feedback.
-
Thnx for your fast answer: sntp_init() didn't help. Yesterday I found a solution: Sketch change: gr henk |
Beta Was this translation helpful? Give feedback.
-
Hi Adam,
I tried your suggestion but it didn’t help.
I still have to wait ca 30s for the first NTP sync.
Gr henk
My sketch:
#include <ESP8266WiFi.h>
#include <time.h>
#include <sntp.h>
…
void setup() {
Serial.begin(115200);
Serial.println("\n----------------------");
Serial.println("Booting ESP8266");
WiFi.mode(WIFI_STA);
WiFi.setSleepMode(WIFI_NONE_SLEEP);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) yield();
Serial.print("WiFi address:"); Serial.println(WiFi.localIP());
Serial.print("Host:"); Serial.println(host);
configTime(TZ_INFO, NTP_SERVER);
uint32_t startTime = millis();
// does not help...
sntp_stop();
sntp_init();
Serial.print("wait for first valid timestamp ");
while (time(nullptr) < 100000ul) {
Serial.printf(".");
delay(500);
}
uint32_t runtimeMillis = millis() - startTime;
Serial.printf("\ntime synced in %d ms.\n", runtimeMillis); // takes 0-30 seconds !!!! Don't know why it takes so long to sync.
}
Van: Adam H ***@***.***>
Verzonden: dinsdag 31 augustus 2021 11:38
Aan: esp8266/Arduino ***@***.***>
CC: henk1311 ***@***.***>; Author ***@***.***>
Onderwerp: Re: [esp8266/Arduino] NTP sync first time (#8032)
The simplest way to force an immediate update would be to call
sntp_stop();
sntp_init();
after you get the IP from Wifi. A simple init doesn't do the trick.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#8032 (reply in thread)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AUCSIMZBKWWMT5VAPYZKPCLT7SPG7ANCNFSM445UIK5Q> .
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub> . <https://github.com/notifications/beacon/AUCSIM5L3NAY3WZJQTNON53T7SPG7A5CNFSM445UIK52YY3PNVWWK3TUL52HS4DFWFCGS43DOVZXG2LPNZBW63LNMVXHJKTDN5WW2ZLOORPWSZGOAAJTI3Q.gif>
|
Beta Was this translation helpful? Give feedback.
-
Please pay attention to message format, otherwise it's an hardly readable mess :-( . You can try: sntp_stop();
configTime(timeZone.c_str(), ntpServer.c_str());
sntp_init(); |
Beta Was this translation helpful? Give feedback.
-
Hi Pablo. This is the trick.Now I get an immediate NTP respons.Thanks a lot.Gr Henk Verzonden vanaf mijn Galaxy
-------- Oorspronkelijk bericht --------Van: Pablo2048 ***@***.***> Datum: 04-09-2021 10:40 (GMT+01:00) Aan: esp8266/Arduino ***@***.***> Cc: henk1311 ***@***.***>, Author ***@***.***> Onderwerp: Re: [esp8266/Arduino] NTP sync first time (#8032)
Please pay attention to message format, otherwise it's an hardly readable mess :-( . You can try:
sntp_stop();
configTime(timeZone.c_str(), ntpServer.c_str());
sntp_init();
—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Beta Was this translation helpful? Give feedback.
Thnx for your fast answer: sntp_init() didn't help.
Yesterday I found a solution:
Forcing the sntp_startup_delay to zero was strangely not the solution, but reducing sntp_update_delay to 15 seconds (RFC minimum) was.
After the first ntp response I set this value back to the default value (1 hour):
Sketch change:
uint32_t sntp_update_delay_MS_rfc_not_less_than_15000 ()
{
// //info_sntp_update_delay_MS_rfc_not_less_than_15000_has_been_called = true;
if (FirstDNS) {
FirstDNS = false;
return 15000; // min = 15000 = 15s
} else
return 3600000; // 1 hour
}
gr henk