From 140e4791aac0fd6d6c2f72964c0966bdcd06a686 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Tue, 21 May 2024 17:10:19 +0200
Subject: [PATCH] nicer solution skipping loracommand header

---
 tasmota/tasmota_xdrv_driver/xdrv_73_9_lora.ino | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/tasmota/tasmota_xdrv_driver/xdrv_73_9_lora.ino b/tasmota/tasmota_xdrv_driver/xdrv_73_9_lora.ino
index 6c3d5015f..f7eacc83a 100644
--- a/tasmota/tasmota_xdrv_driver/xdrv_73_9_lora.ino
+++ b/tasmota/tasmota_xdrv_driver/xdrv_73_9_lora.ino
@@ -200,6 +200,7 @@ void LoraInput(void) {
 #endif  // USE_LORAWAN_BRIDGE
   Lora->receive_time = 0;
 
+  char *rcvd_data = data;
   if (TAS_LORA_REMOTE_COMMAND == data[0]) {
     char *payload = data +1;             // Skip TAS_LORA_REMOTE_COMMAND
     char *command_part;
@@ -212,7 +213,8 @@ void LoraInput(void) {
         }
       } else {
         *--command_part = ' ';           // Restore strtok_r '/0'
-        data[0] = ' ';                   // Remove TAS_LORA_REMOTE_COMMAND header
+        rcvd_data++;                     // Remove TAS_LORA_REMOTE_COMMAND header
+        packet_size--;
       }
     }
   }
@@ -220,21 +222,21 @@ void LoraInput(void) {
   bool raw = Lora->raw;
   // Set raw mode if zeroes within data
   for (uint32_t i = 0; i < packet_size; i++) {
-    if (0 == data[i]) {
+    if (0 == rcvd_data[i]) {
       raw = true;
       break;
     }
   }
-  bool assume_json = (!raw && (data[0] == '{'));
+  bool assume_json = (!raw && (rcvd_data[0] == '{'));
   Response_P(PSTR("{\"LoRaReceived\":"));
   if (assume_json) {
-    ResponseAppend_P(data);
+    ResponseAppend_P(rcvd_data);
   } else {
     ResponseAppend_P(PSTR("\""));
     if (raw) {
-      ResponseAppend_P(PSTR("%*_H"), packet_size, data);
+      ResponseAppend_P(PSTR("%*_H"), packet_size, rcvd_data);
     } else {
-      ResponseAppend_P(EscapeJSONString(data).c_str());
+      ResponseAppend_P(EscapeJSONString(rcvd_data).c_str());
     }
     ResponseAppend_P(PSTR("\""));
   }