ntp

Package ntp provides an implementation of a Simple NTP (SNTP) client capable of querying the current time from a remote NTP server.

Index

Functions

func Time

1func Time(address string) (time.Time, error)

Time returns the current, corrected local time using information returned from the remote NTP server. On error, Time returns the uncorrected local system time.

The server address is of the form “host”, “host:port”, “host%zone:port”, “[host]:port” or “[host%zone]:port”. The host may contain an IPv4, IPv6 or domain name address. When specifying both a port and an IPv6 address, one of the bracket formats must be used. If no port is included, NTP default port 123 is used.

This examples demonstrates how to query the NPT time from the public NTP server "pool.ntp.org". The NTP time is then encoded and sent to different group addresses.

 1var t, err = ntp.Time("pool.ntp.org")
 2if err != nil {
 3	println(err)
 4	return
 5}
 6
 7// Encode as DPT 10.001 (Date)
 8var date = hkknx.DPT10001(t)
 9hkknx.GroupWrite(date, "1/0/1")
10
11// Encode as DPT 11.001 (Time)
12var time = hkknx.DPT11001(t)
13hkknx.GroupWrite(time, "1/0/2")
14
15// Encode as DPT 19.001 (Date & Time)
16var dateTime = hkknx.DPT19001(t)
17hkknx.GroupWrite(dateTime, "1/0/3")

© Matthias Hochgatterer – MastodonGithubRésumé