Skip to content

Commit d81f745

Browse files
committed
feature: Update documentation.
1 parent 9b0ae39 commit d81f745

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

docs/API.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ WebScreen exposes a comprehensive set of functions to JavaScript applications ru
2222
"display": {
2323
"brightness": 200
2424
},
25+
"timezone": "EST5EDT,M3.2.0,M11.1.0",
2526
"script": "my_app.js"
2627
}
2728
```
@@ -86,6 +87,56 @@ The following functions are available in your JavaScript applications:
8687
- **wifi_get_ip()**
8788
Returns the local IP address as a string.
8889

90+
### NTP Time Functions
91+
92+
Time is automatically synchronized via NTP when the device connects to WiFi. The timezone is configured in `webscreen.json` using a POSIX TZ string (see the WebScreen Admin tool for a full dropdown of all timezones).
93+
94+
- **ntp_synced()**
95+
Returns `true` if NTP time has been synchronized, `false` otherwise. Always check this before using other time functions.
96+
```javascript
97+
if (ntp_synced()) {
98+
print("Time is available");
99+
}
100+
```
101+
102+
- **get_hours()**
103+
Returns the current hour (0-23) in the configured timezone, or -1 if NTP is not synced.
104+
105+
- **get_minutes()**
106+
Returns the current minute (0-59), or -1 if NTP is not synced.
107+
108+
- **get_seconds()**
109+
Returns the current second (0-59), or -1 if NTP is not synced.
110+
111+
- **get_year()**
112+
Returns the current year (e.g. 2026), or -1 if NTP is not synced.
113+
114+
- **get_month()**
115+
Returns the current month (1-12), or -1 if NTP is not synced.
116+
117+
- **get_day()**
118+
Returns the current day of the month (1-31), or -1 if NTP is not synced.
119+
120+
- **get_weekday()**
121+
Returns the day of the week (0=Sunday, 6=Saturday), or -1 if NTP is not synced.
122+
123+
- **get_epoch()**
124+
Returns the current Unix timestamp in seconds, or -1 if time is not valid (before 2021).
125+
126+
**Example: Simple Clock**
127+
```javascript
128+
// Wait for NTP sync
129+
if (wifi_status() && ntp_synced()) {
130+
let h = get_hours();
131+
let m = get_minutes();
132+
let s = get_seconds();
133+
let time_str = numberToString(h) + ":" +
134+
(m < 10 ? "0" : "") + numberToString(m) + ":" +
135+
(s < 10 ? "0" : "") + numberToString(s);
136+
set_text(time_label, time_str);
137+
}
138+
```
139+
89140
### HTTP Functions
90141

91142
- **http_get(url)**

docs/SerialCommands.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ WebScreen> /help
6161
/ping <host> - Test network connectivity
6262
/backup [save|restore] - Backup/restore configuration
6363
/brightness <0-255> - Set display brightness
64+
/time - Show current device time
65+
/settime <epoch> [tz] - Set device time from epoch
6466
/monitor [cpu|mem|net] - Live system monitoring
6567
/reboot - Restart the device
6668
@@ -368,6 +370,60 @@ Live Monitor - Press any key to stop
368370
- Debug WiFi connectivity issues
369371
- Performance profiling during development
370372

373+
### Time Commands
374+
375+
#### `/time`
376+
Displays the current device time, epoch timestamp, and day of week. Time is sourced from NTP (Network Time Protocol) and requires a WiFi connection for initial synchronization.
377+
378+
**Usage:**
379+
```
380+
WebScreen> /time
381+
Current time: 2026-02-17 14:23:45
382+
Epoch: 1771337025
383+
Day of week: 2 (0=Sun)
384+
```
385+
386+
**Notes:**
387+
- Returns an error if NTP has not synced yet
388+
- Time is displayed in the device's configured timezone
389+
- NTP automatically syncs when WiFi connects (server: `pool.ntp.org` by default)
390+
391+
#### `/settime <epoch> [timezone]`
392+
Manually sets the device time from a Unix epoch timestamp, with an optional POSIX timezone string.
393+
394+
**Usage:**
395+
```
396+
WebScreen> /settime 1771337025
397+
Time set: 2026-02-17 14:23:45
398+
399+
WebScreen> /settime 1771337025 EST5EDT,M3.2.0,M11.1.0
400+
Time set: 2026-02-17 09:23:45
401+
```
402+
403+
**Parameters:**
404+
- `epoch` - Unix timestamp in seconds (must be after 2021-01-01)
405+
- `timezone` - Optional POSIX TZ string that sets the device timezone
406+
407+
**POSIX TZ String Examples:**
408+
| Location | POSIX TZ String |
409+
|---|---|
410+
| UTC | `UTC0` |
411+
| US Eastern | `EST5EDT,M3.2.0,M11.1.0` |
412+
| US Pacific | `PST8PDT,M3.2.0,M11.1.0` |
413+
| Buenos Aires | `<-03>3` |
414+
| Tokyo | `JST-9` |
415+
| London | `GMT0BST,M3.5.0/1,M10.5.0` |
416+
| Berlin | `CET-1CEST,M3.5.0,M10.5.0/3` |
417+
418+
**Notes:**
419+
- The WebScreen Admin tool provides a timezone dropdown that maps IANA names to POSIX TZ strings automatically
420+
- Full POSIX TZ database: https://github.com/nayarsystems/posix_tz_db
421+
422+
**Use Cases:**
423+
- Set time when WiFi/NTP is not available
424+
- Override timezone from the serial console
425+
- Used by the WebScreen Admin tool's "Sync Time to Device" feature
426+
371427
### Configuration Management
372428

373429
#### `/config get <key>`

0 commit comments

Comments
 (0)