시간 동기화

This commit is contained in:
2025-12-07 20:53:31 +00:00
parent 1743eb37f9
commit 26d3b798d2
2 changed files with 47 additions and 4 deletions

View File

@@ -1,6 +1,5 @@
#ifndef SERIAL2_TERMINAL_H #ifndef SERIAL2_TERMINAL_H
#define SERIAL2_TERMINAL_H #define SERIAL2_TERMINAL_H
const char serial2_terminal_html[] PROGMEM = R"rawliteral( const char serial2_terminal_html[] PROGMEM = R"rawliteral(
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@@ -686,12 +685,35 @@ const char serial2_terminal_html[] PROGMEM = R"rawliteral(
0x2B: 'Read Device Identification' 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() { function initWebSocket() {
ws = new WebSocket('ws://' + window.location.hostname + ':81/'); ws = new WebSocket('ws://' + window.location.hostname + ':81/');
ws.onopen = function() { ws.onopen = function() {
console.log('WebSocket Connected'); console.log('WebSocket Connected');
addToTerminal('System', '🟢 Connected to Serial2 Terminal'); addToTerminal('System', '🟢 Connected to Serial2 Terminal');
// 시간 동기화
setTimeout(function() {
syncTimeFromPhone();
}, 500);
}; };
ws.onmessage = function(event) { ws.onmessage = function(event) {

View File

@@ -685,12 +685,35 @@ const char serial_terminal_html[] PROGMEM = R"rawliteral(
0x2B: 'Read Device Identification' 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() { function initWebSocket() {
ws = new WebSocket('ws://' + window.location.hostname + ':81/'); ws = new WebSocket('ws://' + window.location.hostname + ':81/');
ws.onopen = function() { ws.onopen = function() {
console.log('WebSocket Connected'); console.log('WebSocket Connected');
addToTerminal('System', '🟢 Connected to Serial1 Terminal'); addToTerminal('System', '🟢 Connected to Serial1 Terminal');
// 시간 동기화
setTimeout(function() {
syncTimeFromPhone();
}, 500);
}; };
ws.onmessage = function(event) { ws.onmessage = function(event) {
@@ -1213,6 +1236,4 @@ const char serial_terminal_html[] PROGMEM = R"rawliteral(
</html> </html>
)rawliteral"; )rawliteral";
#endif #endif