From 9861cb3f7e610a3ed2c1c91d04d291e274a4e85b Mon Sep 17 00:00:00 2001 From: c1328 <112856305+c1328@users.noreply.github.com> Date: Sat, 31 Jan 2026 19:30:34 +0100 Subject: [PATCH] Refactor Meshtastic CLI integration and remove retries Removed retry handling for CLI calls and updated node management logic. --- meshcli_iobroker.js | 84 +++++---------------------------------------- 1 file changed, 8 insertions(+), 76 deletions(-) diff --git a/meshcli_iobroker.js b/meshcli_iobroker.js index 69a1faa..8a67ccd 100644 --- a/meshcli_iobroker.js +++ b/meshcli_iobroker.js @@ -1,12 +1,4 @@ -// Meshtastic ioBroker Integration Kit (FINAL FIXED) -// - execFile statt exec (keine Shell-Injection / Quoting-Probleme) -// - mqttPath Variable wird genutzt -// - robuste senderHex Erzeugung -// - safeCreateObject / safeCreateState Wrapper -// - konstante Pfade / Intervalle -// - alle Funktionen aus deiner letzten Version enthalten -// - History JSON + HTML mit Escape -// - onStop Cleanup +// Meshtastic ioBroker Integration Kit // ====================================================== // CONFIG @@ -32,32 +24,6 @@ const chats = [ // Node.js execFile verfügbar const { execFile } = require("child_process"); -// ====================================================== -// RETRY HANDLING (Node offline / reboot) -// ====================================================== -let retryCount = 0; -const RETRY_MAX = 10; -const RETRY_DELAY = 10000; - -function scheduleRetry(actionName) { - retryCount++; - - if (retryCount > RETRY_MAX) { - log("Meshtastic: Abbruch nach " + RETRY_MAX + - " Fehlversuchen. Aktion fehlgeschlagen: " + actionName, "error"); - retryCount = 0; - return; - } - - log("Meshtastic: Node nicht erreichbar → Retry " + - retryCount + "/" + RETRY_MAX + - " in " + (RETRY_DELAY/1000) + "s (" + actionName + ")", "warn"); - - setTimeout(() => { - if (actionName === "updateNodes") updateNodes(); - }, RETRY_DELAY); -} - // ====================================================== // HELPERS // ====================================================== @@ -101,35 +67,13 @@ function toSenderHex(fromField) { return hex.toLowerCase().padStart(8, "0"); } -// ====================================================== -// CLI CALLS (with retry) -// ====================================================== -function runMeshtastic(args, cb, attempt = 1) { +// Wrapper: meshtastic CLI call +function runMeshtastic(args, cb) { execFile(MESHTASTIC_BIN, args, (err, stdout, stderr) => { - if (err) { - const actionName = args.join(" "); - - if (attempt <= RETRY_MAX) { - log("Meshtastic offline → Retry " + attempt + "/" + RETRY_MAX + - " in 10s: " + actionName, "warn"); - - setTimeout(() => { - runMeshtastic(args, cb, attempt + 1); - }, RETRY_DELAY); - - return; - } - - log("Meshtastic: Abbruch nach " + RETRY_MAX + - " Versuchen. Aktion fehlgeschlagen: " + actionName + - " | Error: " + (stderr || err), "error"); - - if (cb) cb(err, stdout, stderr); - return; + log("Meshtastic CLI error: " + (stderr || err), "error"); } - - if (cb) cb(null, stdout, stderr); + if (cb) cb(err, stdout, stderr); }); } @@ -507,27 +451,15 @@ function updateNode(data) { setState(base + "battery", battVal, true); } -// ====================================================== -// UPDATE NODES (with retry) -// ====================================================== function updateNodes() { runMeshtastic(["--host", deviceIp, "--nodes"], (err, stdout) => { - - // Node offline / reboot → retry - if (err || !stdout) { - scheduleRetry("updateNodes"); - return; - } - - // Erfolg → Retry Counter zurücksetzen - retryCount = 0; + if (err || !stdout) return; + if (!stdout.includes("Connected")) return; const nodes = parseData(stdout); - if (!nodes.length) return; nodes.forEach(n => { - n.ID = normalizeNodeId(n.ID); - + n.ID = String(n.ID).replace(/^!/, ""); if (!nodeIsKnown(n.ID)) createNode(n); updateNode(n); });