[Issue #1] - Added configurable NTPServer option in config.go; also added DNS name resolution so you don't have to use IPs
This commit is contained in:
@@ -109,16 +109,27 @@ func main() {
|
||||
// Extract IP string from the returned NetworkStack
|
||||
ipStr := netStack.localIP.String()
|
||||
|
||||
// Sync wall time using public NTP (e.g. Cloudflare: 162.159.200.1 / time.cloudflare.com)
|
||||
println("Synchronizing clock via NTP...")
|
||||
oled.ClearBuffer()
|
||||
tinyfont.WriteLine(oled, defaultFont, 0, 32, "Syncing NTP...", white)
|
||||
oled.Display()
|
||||
ntpServer := netip.MustParseAddr("162.159.200.1")
|
||||
timeOffset, err := syncNTP(netStack, ntpServer, 5*time.Second)
|
||||
if err != nil {
|
||||
panicErr("NTP sync failed", err)
|
||||
}
|
||||
println("Resolving NTP server:", NTPServer)
|
||||
oled.ClearBuffer()
|
||||
tinyfont.WriteLine(oled, defaultFont, 0, 32, "Resolving NTP...", white)
|
||||
oled.Display()
|
||||
|
||||
ntpServer, err := resolveHostToIP(netStack, NTPServer, 5*time.Second)
|
||||
if err != nil {
|
||||
panicErr("NTP DNS lookup failed", err)
|
||||
}
|
||||
println("NTP server IP: ", ntpServer.String())
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
println("Synchronizing clock via NTP...")
|
||||
oled.ClearBuffer()
|
||||
tinyfont.WriteLine(oled, defaultFont, 0, 32, "Syncing NTP...", white)
|
||||
oled.Display()
|
||||
|
||||
timeOffset, err := syncNTP(netStack, ntpServer, 5*time.Second)
|
||||
if err != nil {
|
||||
panicErr("NTP sync failed", err)
|
||||
}
|
||||
|
||||
println("NTP synced successfully!")
|
||||
oled.ClearBuffer()
|
||||
|
||||
Reference in New Issue
Block a user