diff --git a/serial2_terminal.h b/serial2_terminal.h index 1f0fcc0..0edb608 100644 --- a/serial2_terminal.h +++ b/serial2_terminal.h @@ -1,6 +1,5 @@ #ifndef SERIAL2_TERMINAL_H #define SERIAL2_TERMINAL_H - const char serial2_terminal_html[] PROGMEM = R"rawliteral( @@ -686,12 +685,35 @@ const char serial2_terminal_html[] PROGMEM = R"rawliteral( 0x2B: 'Read Device Identification' }; + function syncTimeFromPhone() { + const now = new Date(); + const timeData = { + cmd: 'syncTimeFromPhone', + year: now.getFullYear(), + month: now.getMonth() + 1, + day: now.getDate(), + hour: now.getHours(), + minute: now.getMinutes(), + second: now.getSeconds() + }; + + if (ws && ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify(timeData)); + console.log('Time sync command sent:', timeData); + } + } + function initWebSocket() { ws = new WebSocket('ws://' + window.location.hostname + ':81/'); ws.onopen = function() { console.log('WebSocket Connected'); addToTerminal('System', '🟒 Connected to Serial2 Terminal'); + + // μ‹œκ°„ 동기화 + setTimeout(function() { + syncTimeFromPhone(); + }, 500); }; ws.onmessage = function(event) { diff --git a/serial_terminal.h b/serial_terminal.h index 02b8809..0cd4b8d 100644 --- a/serial_terminal.h +++ b/serial_terminal.h @@ -685,12 +685,35 @@ const char serial_terminal_html[] PROGMEM = R"rawliteral( 0x2B: 'Read Device Identification' }; + function syncTimeFromPhone() { + const now = new Date(); + const timeData = { + cmd: 'syncTimeFromPhone', + year: now.getFullYear(), + month: now.getMonth() + 1, + day: now.getDate(), + hour: now.getHours(), + minute: now.getMinutes(), + second: now.getSeconds() + }; + + if (ws && ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify(timeData)); + console.log('Time sync command sent:', timeData); + } + } + function initWebSocket() { ws = new WebSocket('ws://' + window.location.hostname + ':81/'); ws.onopen = function() { console.log('WebSocket Connected'); addToTerminal('System', '🟒 Connected to Serial1 Terminal'); + + // μ‹œκ°„ 동기화 + setTimeout(function() { + syncTimeFromPhone(); + }, 500); }; ws.onmessage = function(event) { @@ -1213,6 +1236,4 @@ const char serial_terminal_html[] PROGMEM = R"rawliteral( )rawliteral"; - - -#endif +#endif \ No newline at end of file