From 4f45e13937c2ac786b32ba1cc74c20d6c9b48ce2 Mon Sep 17 00:00:00 2001 From: Nickie Deuxyeux Date: Wed, 18 Mar 2026 16:52:41 +0300 Subject: [PATCH] Added additional settings (Wi-Fi, screen blanking, etc.) --- js/rnode.js | 84 +++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/js/rnode.js b/js/rnode.js index f49c9df..be0db4b 100644 --- a/js/rnode.js +++ b/js/rnode.js @@ -710,55 +710,49 @@ class RNode { } async setWiFiIP(wifiIP) { - if (wifiIP == null) { - // Clear IP → 0.0.0.0 + // If null → clear IP to 0.0.0.0 + if (wifiIP == null) { + await this.sendKissCommand([ + this.CMD_WIFI_IP, + 0x00, 0x00, 0x00, 0x00 + ]); + return; + } + + // Ensure it's a string + if (typeof wifiIP !== "string") { + throw new TypeError("Invalid IP address (not a string)"); + } + + // Split into octets + const parts = wifiIP.trim().split("."); + if (parts.length !== 4) { + throw new Error("Invalid IP address format"); + } + + // Convert to byte array + const ipBytes = new Uint8Array(4); + + for (let i = 0; i < 4; i++) { + const value = Number(parts[i]); + + if (!Number.isInteger(value) || value < 0 || value > 255) { + throw new Error(`Invalid IP octet: ${parts[i]}`); + } + + ipBytes[i] = value; + } + + // Optional debug check + console.log("Setting WiFi IP bytes:", [...ipBytes]); + + // Send command (no manual escaping) await this.sendKissCommand([ this.CMD_WIFI_IP, - 0x00, 0x00, 0x00, 0x00 - ]); - return; - } - - if (typeof wifiIP !== "string") { - throw new TypeError("Invalid IP address (not a string)"); - } - - const octets = wifiIP.split("."); - if (octets.length !== 4) { - throw new Error("Invalid IP address length"); - } - - const ipBytes = new Uint8Array(4); - - for (let i = 0; i < 4; i++) { - const octet = Number(octets[i]); - - if (!Number.isInteger(octet) || octet < 0 || octet > 255) { - throw new Error("Invalid IP octet value"); - } - - ipBytes[i] = octet; - } - - // KISS escape (same as PSK logic) - const escaped = []; - for (const byte of ipBytes) { - if (byte === this.KISS_FEND) { - escaped.push(this.KISS_FESC, this.KISS_TFEND); - } else if (byte === this.KISS_FESC) { - escaped.push(this.KISS_FESC, this.KISS_TFESC); - } else { - escaped.push(byte); - } - } - - // Send command exactly like PSK does - await this.sendKissCommand([ - this.CMD_WIFI_IP, - ...escaped, + ...ipBytes ]); } - + async setWiFiNM(wifiNM) { if (wifiNM == null) { // Clear netmask → 0.0.0.0