diff --git a/frontend/src/pages/engineering/developer/ApiReferencePage.jsx b/frontend/src/pages/engineering/developer/ApiReferencePage.jsx index f8a98a9..8d9d0f4 100644 --- a/frontend/src/pages/engineering/developer/ApiReferencePage.jsx +++ b/frontend/src/pages/engineering/developer/ApiReferencePage.jsx @@ -495,13 +495,52 @@ const NAMESPACES = [ cmd: 'clock.sync_ntp', handler: 'ClockHandler', transports: ['All'], - description: 'Run an NTP time sync (blocks up to ~5 s). Always returns SUCCESS — the outcome is only logged.', + description: 'Sync now (fw 3.1.0+). Queues a user-initiated NTP session and replies immediately; the session (a few seconds: 5 queries over the configured servers, at least 3 must answer and agree within 1 s) runs on the TimeSync task, never on the network thread. Poll clock.get_ntp until sync_in_progress is false; the outcome is in last_sync. Works even with auto off. Applies a correction of any size at once (automatic syncs hold jumps over 10 min for a second session), except in fixed timezone mode, where differences over 5 min are reported as mismatch_not_applied and never applied.', contents: null, - response: '{ "status": "SUCCESS", "type": "clock.sync_ntp", "message": "NTP sync initiated" }', - errors: [], + response: '{ "status": "SUCCESS", "type": "clock.sync_ntp", "data": { "started": true } }', + errors: [ + { message: 'NTP is not used in local timezone mode', condition: 'Timezone mode is local' }, + { message: 'No network connection', condition: 'Not connected' }, + { message: 'Device is in AP mode (no internet)', condition: 'Running its own access point' }, + { message: 'A sync is already running - check clock.get_ntp in a few seconds', condition: 'A session is queued or running' }, + ], example: '{ "v": 2, "cmd": "clock.sync_ntp" }', warning: null, }, + { + cmd: 'clock.set_ntp', + handler: 'ClockHandler', + transports: ['All'], + description: 'NTP settings (fw 3.1.0+). Automatic syncs = nightly at sync_time (local time, retried hourly for 3 h if it fails), a few seconds after a network (re)connect while the RTC is not yet synced this boot, every 5 min while the RTC is untrusted, and the confirmation session for large jumps. None of them run in local timezone mode. Replies with the clock.get_ntp payload.', + contents: [ + { field: 'auto', type: 'bool', required: false, notes: 'Automatic syncs on/off (default true). Off = only clock.sync_ntp. At least one of auto / sync_time / servers.' }, + { field: 'sync_time', type: 'string', required: false, notes: 'Nightly sync time "HH:MM", device local time, default "04:30" (outside the usual 01:00-04:00 DST switch hours).' }, + { field: 'servers', type: 'string[]', required: false, notes: '1-3 NTP host names, queried round-robin. Default ["pool.ntp.org", "time.google.com", "time.cloudflare.com"]. Needs outbound UDP 123.' }, + ], + response: '{\n "status": "SUCCESS",\n "type": "clock.set_ntp",\n "data": {\n "auto": true,\n "sync_time": "04:30", "sync_time_min": 270,\n "servers": ["pool.ntp.org", "time.google.com", "time.cloudflare.com"],\n "rtc_synced": true, "sync_in_progress": false, "pending_confirmation": false,\n "last_sync": {\n "result": "applied", "message": "RTC corrected", "applied": true,\n "servers_answered": 5, "servers_queried": 5,\n "ntp_utc": 1793196300, "drift_ms": 3412,\n "at": 1793196301, "user_initiated": true\n }\n }\n}', + errors: [ + { message: 'Provide at least one of: auto, sync_time, servers', condition: 'None present' }, + { message: 'sync_time must be "HH:MM" (00:00-23:59)', condition: 'Malformed or out of range' }, + { message: 'servers must be an array of 1-3 host names', condition: 'Not an array, empty, or more than 3' }, + { message: 'Invalid server host name', condition: 'Empty, longer than 63 chars, or contains a space' }, + { message: 'Settings busy - try again', condition: 'State lock not available within 1 s (should not happen)' }, + ], + example: '{\n "v": 2,\n "cmd": "clock.set_ntp",\n "contents": { "auto": true, "sync_time": "03:15" }\n}', + warning: null, + }, + { + cmd: 'clock.get_ntp', + handler: 'ClockHandler', + transports: ['All'], + description: 'NTP settings and state (fw 3.1.0+). rtc_synced = the RTC holds real UTC (set by NTP or clock.set_time). last_sync is null until the first session since boot. last_sync.result: applied | in_sync (RTC within 2 s, nothing written) | pending_confirmation (automatic jump over 10 min, waiting for a second session ~15 min later) | mismatch_not_applied (fixed mode, over 5 min off) | failed (message says why). drift_ms = NTP minus RTC before any write; ntp_utc and at are UTC epoch seconds.', + contents: null, + response: '{\n "status": "SUCCESS",\n "type": "clock.get_ntp",\n "data": {\n "auto": true,\n "sync_time": "04:30", "sync_time_min": 270,\n "servers": ["pool.ntp.org", "time.google.com", "time.cloudflare.com"],\n "rtc_synced": true, "sync_in_progress": false, "pending_confirmation": false,\n "last_sync": {\n "result": "applied", "message": "RTC corrected", "applied": true,\n "servers_answered": 5, "servers_queried": 5,\n "ntp_utc": 1793196300, "drift_ms": 3412,\n "at": 1793196301, "user_initiated": true\n }\n }\n}', + errors: [ + { message: 'Settings busy - try again', condition: 'State lock not available within 1 s (should not happen)' }, + ], + example: '{ "v": 2, "cmd": "clock.get_ntp" }', + warning: null, + }, { cmd: 'clock.enable', handler: 'ClockHandler', @@ -565,9 +604,9 @@ const NAMESPACES = [ cmd: 'clock.get_config', handler: 'ClockHandler', transports: ['All'], - description: 'Read full clock configuration — outputs, timings, alerts, backlight, silence, enabled state, NTP server and timezone (the timezone field is the clock.get_timezone object; fw 3.0.0 replaced gmt_offset_sec / dst_offset_sec).', + description: 'Read full clock configuration — outputs, timings, alerts, backlight, silence, enabled state, NTP settings and timezone (timezone = the clock.get_timezone object, fw 3.0.0 replaced gmt_offset_sec / dst_offset_sec; ntp = the settings part of clock.get_ntp, fw 3.1.0 replaced ntp_server).', contents: null, - response: '{\n "status": "SUCCESS",\n "type": "clock.get_config",\n "data": {\n "enabled": true,\n "c1output": 4, "c2output": 5,\n "pulse_duration": 100, "pause_duration": 500,\n "physical_hour": 10, "physical_minute": 30,\n "next_is_c1": true, "last_sync_time": 1740000000,\n "alert_type": "HOURS", "alert_interval": 1,\n "hour_bell": 5, "half_bell": 255, "quarter_bell": 255,\n "backlight": true, "backlight_output": 6,\n "backlight_on": "07:00", "backlight_off": "22:00",\n "daytime_silence": false, "daytime_on": "00:00", "daytime_off": "00:00",\n "night_silence": true, "night_on": "22:00", "night_off": "07:00",\n "timezone": { ...same object as clock.get_timezone... },\n "ntp_server": "pool.ntp.org"\n }\n}', + response: '{\n "status": "SUCCESS",\n "type": "clock.get_config",\n "data": {\n "enabled": true,\n "c1output": 4, "c2output": 5,\n "pulse_duration": 100, "pause_duration": 500,\n "physical_hour": 10, "physical_minute": 30,\n "next_is_c1": true, "last_sync_time": 1740000000,\n "alert_type": "HOURS", "alert_interval": 1,\n "hour_bell": 5, "half_bell": 255, "quarter_bell": 255,\n "backlight": true, "backlight_output": 6,\n "backlight_on": "07:00", "backlight_off": "22:00",\n "daytime_silence": false, "daytime_on": "00:00", "daytime_off": "00:00",\n "night_silence": true, "night_on": "22:00", "night_off": "07:00",\n "timezone": { ...same object as clock.get_timezone... },\n "ntp": { "auto": true, "sync_time": "04:30", "sync_time_min": 270, "servers": ["pool.ntp.org", "time.google.com", "time.cloudflare.com"] }\n }\n}', errors: [], example: '{ "v": 2, "cmd": "clock.get_config" }', warning: null,