From 0abe70816b8d9cc5badb03af84e9a51b458e60e2 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 15 May 2025 13:38:19 +0200 Subject: [PATCH] Fix LoRaWan Decoding when SO147 is enabled --- tasmota/berry/lorawan/decoders/LwDecode.be | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tasmota/berry/lorawan/decoders/LwDecode.be b/tasmota/berry/lorawan/decoders/LwDecode.be index 80fa46792..741639a61 100644 --- a/tasmota/berry/lorawan/decoders/LwDecode.be +++ b/tasmota/berry/lorawan/decoders/LwDecode.be @@ -4,19 +4,19 @@ var LwRegions = ["EU868", "US915", "IN865","AU915","KZ865","RU864","AS923", "AS923-1","AS923-2","AS923-3"] import mqtt -tasmota.cmd('SetOption100 off') -tasmota.cmd('SetOption118 off') -tasmota.cmd('SetOption119 off') +tasmota.cmd('SetOption100 off') # Keep LwReceived in JSON message +tasmota.cmd('SetOption118 off') # Keep SENSOR as subtopic name +tasmota.cmd('SetOption119 off') # Keep device address in JSON message +tasmota.cmd('SetOption147 on') # Hide LwReceived MQTT message but keep rule processing tasmota.cmd('LoRaWanBridge on') var thisDevice = tasmota.cmd('Status',true)['Status']['Topic'] var LwDecoders = {} var LwDeco -def LwDecode(topic, idx, data, databytes) +def LwDecode(data) import json - var LwData = json.load(data) - if !LwData.contains('LwReceived') return true end # Processed + var LwData = type(data)=='string' ? json.load(data) : data var deviceData = LwData['LwReceived'] var deviceName = deviceData.keys()() var Payload = deviceData[deviceName]['Payload'] @@ -31,6 +31,7 @@ def LwDecode(topic, idx, data, databytes) end if Payload.size() && LwDecoders.find(decoder) + var topic = "tele/" + thisDevice + "/SENSOR" var decoded = LwDecoders[decoder].decodeUplink(FPort, Payload) var mqttData = {"LwDecoded":{deviceName:decoded}} mqtt.publish (topic, json.dump(mqttData)) @@ -39,4 +40,4 @@ def LwDecode(topic, idx, data, databytes) return true #processed end -mqtt.subscribe("tele/" + thisDevice + "/SENSOR",LwDecode) \ No newline at end of file +tasmota.add_rule("LwReceived", /value, trigger, payload -> LwDecode(payload)) \ No newline at end of file