Jerome Forissier | f2b2ed9 | 2025-06-25 15:19:20 +0200 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+: |
| 2 | |
| 3 | .. index:: |
| 4 | single: sntp (command) |
| 5 | |
| 6 | sntp command |
| 7 | ============ |
| 8 | |
| 9 | Synopsis |
| 10 | -------- |
| 11 | |
| 12 | :: |
| 13 | |
| 14 | sntp [serverip] |
| 15 | sntp [servername] # NET_LWIP=y && CMD_DNS=y only |
| 16 | |
| 17 | |
| 18 | Description |
| 19 | ----------- |
| 20 | |
| 21 | The sntp command gets the current time from an NTP time server and |
| 22 | syncronizes the Real Time Clock (RTC) of the board. This command needs |
| 23 | the server's IP address to be given on the command line or via the |
| 24 | `ntpserverip` environment variable. |
| 25 | |
| 26 | The address of the NTP server does not need to be given if the DHCP server |
| 27 | provides one. The legacy network stack (`CONFIG_NET=y`) can only use the |
| 28 | first NTP server provided in the `ntp-servers` DHCP option. |
| 29 | |
| 30 | When the network stack is lwIP (`CONFIG_NET_LWIP=y`) and the dns command |
| 31 | is enabled (`CONFIG_CMD_DNS=y`), then the sntp command accepts a server |
| 32 | name as an argument. |
| 33 | |
| 34 | The network time is sent as UTC. So, if you want to set the RTC to any local |
| 35 | time different from UTC, you need to set the `timeoffset` environment variable. |
| 36 | |
| 37 | Round-trip delay compensation is not implemented/not enabled. In practice |
| 38 | this should not matter much given that the RTC API does not have sub-second |
| 39 | resolution, and round-trip times are typically 10 to 100 ms at most. |
| 40 | |
| 41 | Examples |
| 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 | |
| 64 | With `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 |