Added additional settings (Wi-Fi, screen blanking, etc.)

This commit is contained in:
2026-03-18 16:52:41 +03:00
parent 4c1beb7383
commit 4f45e13937

View File

@@ -710,8 +710,8 @@ class RNode {
} }
async setWiFiIP(wifiIP) { async setWiFiIP(wifiIP) {
// If null → clear IP to 0.0.0.0
if (wifiIP == null) { if (wifiIP == null) {
// Clear IP → 0.0.0.0
await this.sendKissCommand([ await this.sendKissCommand([
this.CMD_WIFI_IP, this.CMD_WIFI_IP,
0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00
@@ -719,43 +719,37 @@ class RNode {
return; return;
} }
// Ensure it's a string
if (typeof wifiIP !== "string") { if (typeof wifiIP !== "string") {
throw new TypeError("Invalid IP address (not a string)"); throw new TypeError("Invalid IP address (not a string)");
} }
const octets = wifiIP.split("."); // Split into octets
if (octets.length !== 4) { const parts = wifiIP.trim().split(".");
throw new Error("Invalid IP address length"); if (parts.length !== 4) {
throw new Error("Invalid IP address format");
} }
// Convert to byte array
const ipBytes = new Uint8Array(4); const ipBytes = new Uint8Array(4);
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
const octet = Number(octets[i]); const value = Number(parts[i]);
if (!Number.isInteger(octet) || octet < 0 || octet > 255) { if (!Number.isInteger(value) || value < 0 || value > 255) {
throw new Error("Invalid IP octet value"); throw new Error(`Invalid IP octet: ${parts[i]}`);
} }
ipBytes[i] = octet; ipBytes[i] = value;
} }
// KISS escape (same as PSK logic) // Optional debug check
const escaped = []; console.log("Setting WiFi IP bytes:", [...ipBytes]);
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 // Send command (no manual escaping)
await this.sendKissCommand([ await this.sendKissCommand([
this.CMD_WIFI_IP, this.CMD_WIFI_IP,
...escaped, ...ipBytes
]); ]);
} }