From 35124f2af85e456b767638a91eab61e9f3760099 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 4 Jul 2024 17:09:44 -0500 Subject: [PATCH] [LORA] Fix save function for parameters that are not frequency (#1987) --- main/ZgatewayLORA.ino | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/main/ZgatewayLORA.ino b/main/ZgatewayLORA.ino index 4a1a0e7..f9d6d4f 100644 --- a/main/ZgatewayLORA.ino +++ b/main/ZgatewayLORA.ino @@ -347,6 +347,21 @@ void LORAConfig_fromJson(JsonObject& LORAdata) { StaticJsonDocument jsonBuffer; JsonObject jo = jsonBuffer.to(); jo["frequency"] = LORAConfig.frequency; + jo["txpower"] = LORAConfig.txPower; + jo["spreadingfactor"] = LORAConfig.spreadingFactor; + jo["signalbandwidth"] = LORAConfig.signalBandwidth; + jo["codingrate"] = LORAConfig.codingRateDenominator; + jo["preamblelength"] = LORAConfig.preambleLength; + if (LORAConfig.syncWord < 0 || LORAConfig.syncWord > 255) { + Log.error(F("Invalid syncWord value: %d" CR), LORAConfig.syncWord); + } else { + char syncWordHex[5]; + snprintf(syncWordHex, sizeof(syncWordHex), "0x%02X", LORAConfig.syncWord); + jo["syncword"] = syncWordHex; + } + jo["enablecrc"] = LORAConfig.crc; + jo["invertiq"] = LORAConfig.invertIQ; + jo["onlyknown"] = LORAConfig.onlyKnown; // Save config into NVS (non-volatile storage) String conf = ""; serializeJson(jsonBuffer, conf); @@ -541,10 +556,13 @@ String stateLORAMeasures() { LORAdata["signalbandwidth"] = LORAConfig.signalBandwidth; LORAdata["codingrate"] = LORAConfig.codingRateDenominator; LORAdata["preamblelength"] = LORAConfig.preambleLength; - // Convert syncWord to a hexadecimal string and store it in the JSON - char syncWordHex[5]; // Enough space for 0xXX and null terminator - snprintf(syncWordHex, sizeof(syncWordHex), "0x%02X", LORAConfig.syncWord); - LORAdata["syncword"] = syncWordHex; + if (LORAConfig.syncWord < 0 || LORAConfig.syncWord > 255) { + Log.error(F("Invalid syncWord value: %d" CR), LORAConfig.syncWord); + } else { + char syncWordHex[5]; + snprintf(syncWordHex, sizeof(syncWordHex), "0x%02X", LORAConfig.syncWord); + LORAdata["syncword"] = syncWordHex; + } LORAdata["enablecrc"] = LORAConfig.crc; LORAdata["invertiq"] = LORAConfig.invertIQ; LORAdata["onlyknown"] = LORAConfig.onlyKnown;