From 981c7a65b52a87f887086b4dabcb0174f5341ff6 Mon Sep 17 00:00:00 2001 From: ginnoir Date: Thu, 8 Oct 2026 02:05:46 -0500 Subject: [PATCH] fix(cameras): PTZ page waits for each step's OK, drops zoom, narrows MQTT ACL neolink 0.6.2 moves for amount/32 s per command and queues them, so the page sends the next step only after the previous reply; in/out are todo!() upstream. Co-Authored-By: Claude Opus 5.5 --- ...026-10-08-reolink-camera-frigate-design.md | 2 +- stacks/cameras/mosquitto/acl | 7 ++- stacks/cameras/ptz/index.html | 59 +++++++++++-------- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/docs/superpowers/specs/2026-10-08-reolink-camera-frigate-design.md b/docs/superpowers/specs/2026-10-08-reolink-camera-frigate-design.md index a2db03e..c7a49a5 100644 --- a/docs/superpowers/specs/2026-10-08-reolink-camera-frigate-design.md +++ b/docs/superpowers/specs/2026-10-08-reolink-camera-frigate-design.md @@ -172,7 +172,7 @@ neolink (now `mqtt-rtsp`) ◄── mosquitto:1883 ────┘ topics neol clients to: - publish: `neolink/e1/control/ptz`, `neolink/e1/control/ptz/preset`, `neolink/e1/query/ptz/preset` - - read: `neolink/e1/status/#`, `neolink/status` + - read: `neolink/e1/status`, `neolink/e1/status/ptz`, `neolink/status` (not `status/#`: preview flood) - **not** `neolink/config`, which echoes the camera password and can rewrite the live config. - Authentik forward_auth on the `/mqtt` path is the browser-side gate. diff --git a/stacks/cameras/mosquitto/acl b/stacks/cameras/mosquitto/acl index cd80892..dba0a5c 100644 --- a/stacks/cameras/mosquitto/acl +++ b/stacks/cameras/mosquitto/acl @@ -1,10 +1,13 @@ # Seeded to /config/mosquitto/acl on valhalla. # Lines before the first `user` apply to anonymous clients (the browser PTZ page). -topic write neolink/e1/control/ptz +# Never grant anonymous neolink/config — it echoes the camera password and rewrites +# neolink's live config. No status/# either: status/preview is a base64 JPEG flood. +topic readwrite neolink/e1/control/ptz topic write neolink/e1/control/ptz/preset topic write neolink/e1/control/ptz/assign topic write neolink/e1/query/ptz/preset -topic read neolink/e1/status/# +topic read neolink/e1/status +topic read neolink/e1/status/ptz topic read neolink/status user neolink diff --git a/stacks/cameras/ptz/index.html b/stacks/cameras/ptz/index.html index 01551e5..986d7fe 100644 --- a/stacks/cameras/ptz/index.html +++ b/stacks/cameras/ptz/index.html @@ -44,8 +44,6 @@ } button:active, button.held { background: var(--btn-active); color: var(--btn-active-text); border-color: var(--btn-active); } .pad button { font-size: 22px; } - .zoom { display: flex; gap: 8px; justify-content: center; } - .zoom button { width: 100px; height: 44px; } label { font-size: 13px; color: var(--muted); display: grid; gap: 6px; } input[type=range] { width: 100%; } h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; } @@ -72,11 +70,7 @@ -
- - -
- +

Presets

loading…
@@ -114,7 +108,8 @@ function setStatus() { state.textContent = !client.connected ? 'broker offline' : camOnline ? 'ready' : 'camera offline'; } client.on('connect', () => { - client.subscribe([`neolink/status`, `${BASE}/status/#`]); + // Not status/# — neolink 0.6.2 floods status/preview with base64 JPEGs. + client.subscribe([`neolink/status`, `${BASE}/status`, `${BASE}/status/ptz`, `${BASE}/control/ptz`]); client.publish(`${BASE}/query/ptz/preset`, ''); setStatus(); }); @@ -124,33 +119,49 @@ client.on('message', (topic, payload) => { if (topic === 'neolink/status' || topic === `${BASE}/status`) { camOnline = msg.trim() !== 'offline' && msg.trim() !== 'disconnected'; setStatus(); - } else if (topic === `${BASE}/status/ptz/preset`) { + } else if (topic === `${BASE}/status/ptz`) { renderPresets(msg); + } else if (topic === `${BASE}/control/ptz` && (msg === 'OK' || msg === 'FAIL')) { + // neolink echoes our command on this topic too; only replies settle the step + if (pendingReply) { pendingReply(); pendingReply = null; } } }); -// --- Move: tap = one step, hold = repeat while pressed --- -const speed = document.getElementById('speed'); -const REPEAT_MS = 350; -function move(dir) { - if (client.connected) client.publish(`${BASE}/control/ptz`, `${dir} ${speed.value}`); +// --- Move --- +// neolink 0.6.2: payload " " moves at fixed speed 32 for amount/32 seconds, +// then sends stop. Commands queue camera-side, so never send the next step until the +// previous one replied OK/FAIL — otherwise the camera keeps moving after release. +// (in/out are todo!() in 0.6.2 and would panic neolink; the E1 has no zoom anyway.) +const step = document.getElementById('step'); +const stepLabel = document.getElementById('stepLabel'); +const showStep = () => stepLabel.textContent = `(${(step.value / 32).toFixed(2)} s)`; +step.addEventListener('input', showStep); showStep(); +let pendingReply = null, busy = false; +function moveOnce(dir) { + if (!client.connected || busy) return Promise.resolve(); + busy = true; + return new Promise(resolve => { + const done = () => { busy = false; resolve(); }; + pendingReply = done; + setTimeout(() => { if (pendingReply === done) { pendingReply = null; done(); } }, 3000); + client.publish(`${BASE}/control/ptz`, `${dir} ${step.value}`); + }); } document.querySelectorAll('button[data-dir]').forEach(btn => { - let timer = null; - const stop = () => { clearInterval(timer); timer = null; btn.classList.remove('held'); }; - btn.addEventListener('pointerdown', e => { + let held = false; + const release = () => { held = false; btn.classList.remove('held'); }; + btn.addEventListener('pointerdown', async e => { e.preventDefault(); btn.setPointerCapture(e.pointerId); - btn.classList.add('held'); - move(btn.dataset.dir); - timer = setInterval(() => move(btn.dataset.dir), REPEAT_MS); + held = true; btn.classList.add('held'); + do { await moveOnce(btn.dataset.dir); } while (held); }); - ['pointerup', 'pointercancel', 'lostpointercapture'].forEach(ev => btn.addEventListener(ev, stop)); + ['pointerup', 'pointercancel', 'lostpointercapture'].forEach(ev => btn.addEventListener(ev, release)); }); -const keys = {ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'left', ArrowRight: 'right', '+': 'in', '=': 'in', '-': 'out'}; +const keys = {ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'left', ArrowRight: 'right'}; document.addEventListener('keydown', e => { - if (e.target.tagName === 'INPUT') return; - if (keys[e.key]) { e.preventDefault(); move(keys[e.key]); } + if (e.target.tagName === 'INPUT' || e.repeat) return; + if (keys[e.key]) { e.preventDefault(); moveOnce(keys[e.key]); } }); // --- Presets (neolink returns the camera's XML preset list) ---