You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a ESP32-wroom and testing how it works with SNTP. DHCP provides first server and two more fall back servers in configuration.
I see that after IP address lease expired SNTP configuration lost 2 of 3 servers and if first server is unavailable then time can not be synchronized at all.
Is it a bug? Or i do it in a wrong way?
Lease expiration 5 minutes. SNTP on 10.64.1.1 down.
#include<esp_sntp.h>
#include<WiFi.h>
#include"esp_netif.h"
#include"esp_netif_sntp.h"voidtime_sync_notification_cb(structtimeval* tv) {
Serial.println("Synced");
//esp_sntp_servermode_dhcp(0);
}
voidsetup() {
Serial.begin(115200);
Serial.printf("CONFIG_LWIP_SNTP_MAX_SERVERS: %i", CONFIG_LWIP_SNTP_MAX_SERVERS);
esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG_MULTIPLE(2, ESP_SNTP_SERVER_LIST("10.17.1.1", "10.17.1.8"));
config.start = false; // start SNTP service explicitly (after connecting)
config.server_from_dhcp = true; // accept NTP offers from DHCP server, if any (need to enable *before* connecting)
config.renew_servers_after_new_IP = true; // let esp-netif update configured SNTP server(s) after receiving DHCP lease
config.index_of_first_server = 1; // updates from server num 1, leaving server 0 (from DHCP) intact// configure the event on which we renew servers
config.ip_event_to_renew = IP_EVENT_STA_GOT_IP;
config.sync_cb = time_sync_notification_cb; // only if we need the notification function
WiFi.begin("SSID", "password");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println(WiFi.localIP());
Serial.println("Connected");
setenv("TZ", "<+03>-3", 1);
tzset();
// Can not init before connected - erroresp_netif_sntp_init(&config);
esp_sntp_set_sync_interval(1 * 60 * 1000);
esp_netif_sntp_start();
// Get DHCP 42 option
WiFi.reconnect();
}
voidprint(uint8_t index) {
constip_addr_t* address = esp_sntp_getserver(index);
uint32_t a = address->u_addr.ip4.addr;
constuint32_t *a6 = address->u_addr.ip6.addr;
constchar* name = esp_sntp_getservername(index);
name = name == 0 ? "n/a" : name;
Serial.printf("esp_sntp_getserver(%i): %d %d.%d.%d.%d (%d:%d:%d:%d:%d), sntp_getservername(%i): %s, sntp_getreachability(%i): %d\r\n", index,
address->type, a & 0xFF, (a >> 8) & 0xFF, (a >> 16) & 0xFF, (a >> 24) & 0xFF, a6[0], a6[1], a6[2], a6[3], address->u_addr.ip6.zone, index, name, index, esp_sntp_getreachability(index));
}
char sname[3][50];
uint32_t saddress[3];
uint8_t sreachability[3];
boolequals(uint8_t index) {
constip_addr_t* address = esp_sntp_getserver(index);
uint32_t a = address->u_addr.ip4.addr;
constchar* name = esp_sntp_getservername(index);
uint8_t reachability = esp_sntp_getreachability(index);
if (a != saddress[index]
|| (name != 0 && strcmp(sname[index], name) != 0)
|| (name == 0 && sname[index][0] != 0)
|| sreachability[index] != reachability) {
if (name != 0) {
strcpy(sname[index], name);
} else {
sname[index][0] = 0;
}
saddress[index] = a;
sreachability[index] = reachability;
returnfalse;
} else {
returntrue;
}
}
voidloop() {
bool hasChanges = false;
for (uint8_tindex = 0; index < 3; index++) {
hasChanges |= !equals(index);
}
if (hasChanges) {
tm timeInfo;
getLocalTime(&timeInfo);
Serial.printf("Loop %d.%02d.%02d %02d:%02d:%02d\r\n", timeInfo.tm_year + 1900, timeInfo.tm_mon + 1, timeInfo.tm_mday, timeInfo.tm_hour, timeInfo.tm_min, timeInfo.tm_sec);
for (uint8_t si = 0; si < 3; si++) {
print(si);
}
}
delay(1000);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a ESP32-wroom and testing how it works with SNTP. DHCP provides first server and two more fall back servers in configuration.
I see that after IP address lease expired SNTP configuration lost 2 of 3 servers and if first server is unavailable then time can not be synchronized at all.
Is it a bug? Or i do it in a wrong way?
Lease expiration 5 minutes. SNTP on 10.64.1.1 down.
Beta Was this translation helpful? Give feedback.
All reactions