blob: d97f83053f769a9d3658d6979cd710aac96ca9da [file] [log] [blame]
Jerome Forissierf2b2ed92025-06-25 15:19:20 +02001.. SPDX-License-Identifier: GPL-2.0+:
2
3.. index::
4 single: sntp (command)
5
6sntp command
7============
8
9Synopsis
10--------
11
12::
13
14 sntp [serverip]
15 sntp [servername] # NET_LWIP=y && CMD_DNS=y only
16
17
18Description
19-----------
20
21The sntp command gets the current time from an NTP time server and
22syncronizes the Real Time Clock (RTC) of the board. This command needs
23the server's IP address to be given on the command line or via the
24`ntpserverip` environment variable.
25
26The address of the NTP server does not need to be given if the DHCP server
27provides one. The legacy network stack (`CONFIG_NET=y`) can only use the
28first NTP server provided in the `ntp-servers` DHCP option.
29
30When the network stack is lwIP (`CONFIG_NET_LWIP=y`) and the dns command
31is enabled (`CONFIG_CMD_DNS=y`), then the sntp command accepts a server
32name as an argument.
33
34The network time is sent as UTC. So, if you want to set the RTC to any local
35time different from UTC, you need to set the `timeoffset` environment variable.
36
37Round-trip delay compensation is not implemented/not enabled. In practice
38this should not matter much given that the RTC API does not have sub-second
39resolution, and round-trip times are typically 10 to 100 ms at most.
40
41Examples
42--------
43
44::
45
46 => setenv ntpserverip 109.190.177.205
47 => date
48 Date: 2025-06-16 (Monday) Time: 15:19:35
49 => date reset
50 Reset RTC...
51 Date: 2000-01-01 (Saturday) Time: 0:00:00
52 => date
53 Date: 2000-01-01 (Saturday) Time: 0:00:03
54 => sntp
55 Date: 2025-06-16 Time: 15:19:43
56 => date
57 Date: 2025-06-16 (Monday) Time: 15:19:47
58 => setenv timeoffset 7200
59 => sntp
60 Date: 2025-06-16 Time: 17:19:55
61 => date
62 Date: 2025-06-16 (Monday) Time: 17:19:57
63
64With `CONFIG_NET_LWIP=y` and `CONFIG_CMD_DNS=y`:
65
66::
67
68 => date reset
69 Reset RTC...
70 Date: 2000-01-01 (Saturday) Time: 0:00:00
71 => sntp 0.us.pool.ntp.org
72 Date: 2025-06-16 Time: 15:10:59