From 3e3023fa631edf1706d7ff19921cfae835b28d9a Mon Sep 17 00:00:00 2001 From: chk <79915315+ChKendel@users.noreply.github.com> Date: Fri, 12 Jun 2026 18:47:28 +0200 Subject: [PATCH] E-Stop Log --- logs/gcode_commands.log | 10 +++++++ logs/pings.log | 4 +++ public/app.js | 53 ++++++++++++++++++++++++++++++------ public/index.html | 1 + robot/ShellyEmergencyStop.js | 6 ++-- robot/TelnetSenderGRBL.js | 1 + server/InfoServer.js | 20 +++++++++++--- 7 files changed, 79 insertions(+), 16 deletions(-) diff --git a/logs/gcode_commands.log b/logs/gcode_commands.log index d310304..46874c7 100644 --- a/logs/gcode_commands.log +++ b/logs/gcode_commands.log @@ -10399,3 +10399,13 @@ 2026-06-12T16:12:57.932Z ::ffff:127.0.0.1: M114 2026-06-12T16:12:58.165Z ::ffff:127.0.0.1: G1 X1 Y2 Z3 2026-06-12T16:12:58.438Z ::ffff:127.0.0.1: G1 X1 +2026-06-12T16:34:08.466Z ::ffff:127.0.0.1: M114 +2026-06-12T16:34:08.468Z ::ffff:127.0.0.1: M114 +2026-06-12T16:34:08.483Z ::ffff:127.0.0.1: G1 X1 Y2 Z3 +2026-06-12T16:34:08.701Z ::ffff:127.0.0.1: G1 X1 Y2 Z3 +2026-06-12T16:34:08.935Z ::ffff:127.0.0.1: G1 X1 +2026-06-12T16:46:45.327Z ::ffff:127.0.0.1: M114 +2026-06-12T16:46:45.356Z ::ffff:127.0.0.1: G1 X1 Y2 Z3 +2026-06-12T16:46:46.488Z ::ffff:127.0.0.1: M114 +2026-06-12T16:46:46.701Z ::ffff:127.0.0.1: G1 X1 Y2 Z3 +2026-06-12T16:46:46.923Z ::ffff:127.0.0.1: G1 X1 diff --git a/logs/pings.log b/logs/pings.log index c7b21bc..dfe0bd9 100644 --- a/logs/pings.log +++ b/logs/pings.log @@ -14634,3 +14634,7 @@ 2026-06-12T16:00:23.226Z ::ffff:127.0.0.1 : Ping 2026-06-12T16:12:57.687Z ::ffff:127.0.0.1 : Ping 2026-06-12T16:12:57.751Z ::ffff:127.0.0.1 : Ping +2026-06-12T16:34:08.216Z ::ffff:127.0.0.1 : Ping +2026-06-12T16:34:08.427Z ::ffff:127.0.0.1 : Ping +2026-06-12T16:46:45.306Z ::ffff:127.0.0.1 : Ping +2026-06-12T16:46:46.265Z ::ffff:127.0.0.1 : Ping diff --git a/public/app.js b/public/app.js index 4e8a8ee..92fa8fc 100644 --- a/public/app.js +++ b/public/app.js @@ -175,7 +175,7 @@ document.addEventListener('DOMContentLoaded', function() { // ── Emergency Stop Panel ───────────────────────────────────────────── - // SVG-Button: Farbe + Text + Click-Handler je nach armed-Zustand wechseln. + // SVG-Button: Farbe + Text je nach armed-Zustand. // armed=true → rot "EMERGENCY STOP" → POST /api/emergency-stop // armed=false → grün "START ROBOT" → POST /api/power-on let _lastArmed = null; @@ -184,7 +184,7 @@ document.addEventListener('DOMContentLoaded', function() { if (armed === _lastArmed) return; _lastArmed = armed; - const stops = document.querySelectorAll('#estopGrad stop'); + const stops = document.querySelectorAll('#estopGrad stop'); const textPath = document.querySelector('#emergency-stop textPath'); const btnInner = document.querySelector('#emergency-stop circle:last-of-type'); const label = document.getElementById('armed-status'); @@ -198,7 +198,7 @@ document.addEventListener('DOMContentLoaded', function() { if (textPath) textPath.textContent = 'EMERGENCY STOP'; if (label) { label.textContent = '● Bestromt'; label.className = 'estop-armed-label armed'; } } else { - // Grün: Strom AUS → Klick = Strom einschalten (Start Robot) + // Grün: Strom AUS → Klick = Strom einschalten if (stops[0]) stops[0].setAttribute('stop-color', '#88ff99'); if (stops[1]) stops[1].setAttribute('stop-color', '#00aa44'); if (stops[2]) stops[2].setAttribute('stop-color', '#005522'); @@ -206,24 +206,59 @@ document.addEventListener('DOMContentLoaded', function() { if (textPath) textPath.textContent = 'START ROBOT'; if (label) { label.textContent = '○ Kein Strom'; label.className = 'estop-armed-label disarmed'; } } + } - const div = document.getElementById('emergency-stop'); - if (div) { - div.onclick = armed - ? () => fetch('/api/emergency-stop', { method: 'POST' }) - : () => fetch('/api/power-on', { method: 'POST' }); + // ── Click-Handler (einmalig registriert, liest _lastArmed dynamisch) ───────── + // + // Zeigt Lade-/Erfolgs-/Fehlerstatus unter dem Button. + // Schreibt console.warn ⚠️ für den Browser-Dev-Tools-Log. + async function handleEstopClick() { + const armed = _lastArmed; + const url = armed ? '/api/emergency-stop' : '/api/power-on'; + const action = armed ? 'EmergencyStop' : 'PowerOn'; + const statusEl = document.getElementById('estop-action-status'); + + if (statusEl) { statusEl.textContent = '⏳ …'; statusEl.className = 'estop-status'; } + console.warn(`⚠️ [${action}] wird ausgeführt …`); + + try { + const res = await fetch(url, { method: 'POST' }); + const data = await res.json(); + const ok = data.ok || (data.results || []).every(r => r.ok || r.skipped); + if (ok) { + if (statusEl) { statusEl.textContent = `✅ ${action} OK`; statusEl.className = 'estop-status ok'; } + console.warn(`⚠️ [${action}] OK`); + } else { + const failed = (data.results || []) + .filter(r => !r.ok && !r.skipped) + .map(r => `${r.name}(${r.error || '?'})`) + .join(', '); + if (statusEl) { statusEl.textContent = `⚠️ Teilfehler: ${failed}`; statusEl.className = 'estop-status err'; } + console.warn(`⚠️ [${action}] Teilfehler — ${failed}`); + } + } catch (err) { + if (statusEl) { statusEl.textContent = `❌ Netzwerkfehler`; statusEl.className = 'estop-status err'; } + console.error(`❌ [${action}] Netzwerkfehler: ${err.message}`); } } + // onclick einmalig setzen — bleibt dauerhaft, Handler liest _lastArmed dynamisch. + const estopDiv = document.getElementById('emergency-stop'); + if (estopDiv) estopDiv.onclick = handleEstopClick; + async function pollPowerStatus() { try { const res = await fetch('/api/power-status'); if (!res.ok) return; const data = await res.json(); - if (data.ok) updateEmergencyStopButton(data.armed); + // Immer aktualisieren (auch bei ok:false → disarmed als sicherer Fallback) + updateEmergencyStopButton(data.ok ? data.armed : false); } catch { /* Netzwerkfehler → Button bleibt im letzten Zustand */ } } + // Sofort sicheren Startzustand (grün "START ROBOT") setzen, damit der onclick + // sofort aktiv ist — noch bevor der erste Poll antwortet. + updateEmergencyStopButton(false); pollPowerStatus(); setInterval(pollPowerStatus, 2000); diff --git a/public/index.html b/public/index.html index c57a8e6..f87f4a4 100644 --- a/public/index.html +++ b/public/index.html @@ -105,6 +105,7 @@
+