|
| 1 | +# LoRaWan Decoders |
| 2 | + |
| 3 | +LoRaWan end devices transmit packets containing raw _Payload Data_. The Tasmota _LoRaWan Bridge_ feature normally passes the raw _Payload Data_ onto an MQTT server. |
| 4 | +``` |
| 5 | +{ |
| 6 | + "LwReceived": { |
| 7 | + "0xAE3D": { |
| 8 | + "Node": 1, |
| 9 | + "Device": "0xAE3D", |
| 10 | + "RSSI": -14, |
| 11 | + "SNR": 8.8, |
| 12 | + "Decoder": "LHT52", |
| 13 | + "DevEUIh": "A840414E", |
| 14 | + "DevEUIl": "4F5CAE3D", |
| 15 | + "FPort": 2, |
| 16 | + "Payload": [9,230,2,48,127,255,1,104,33,178,172] |
| 17 | + } |
| 18 | + } |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +## Adding Payload Data Decoding |
| 23 | +There are no industry standards on the format or content of the raw data send by each sensor; every manufacturer/device is different. There are public databases of decoder scripts for many devices; e.g. [TTN decoder script database](https://github.com/TheThingsNetwork/lorawan-devices/tree/master/vendor) |
| 24 | + |
| 25 | +The _Tasmota LoRaWAN Decoder_ feature: |
| 26 | + - is optional |
| 27 | + - is implemented in [Berry](https://tasmota.github.io/docs/Berry/) |
| 28 | + - does not require any custom builds |
| 29 | + - the elements are: |
| 30 | + - a Berry script `LwDecode.be` that: |
| 31 | + - subscribes to the tele/xxxx/SENSOR MQTT messages, looking for the `LwReceived` packets sent by the _Tasmota LoRaWAN Bridge_. |
| 32 | + - dynamically loads (once only) _Device Decoder Files_ from the Tasmota file system, if they exist. |
| 33 | + - asks a _Device Decoder File_ to decode the raw _Data Payload_ |
| 34 | + - reports the result via MQTT |
| 35 | + - Device Decoder Files: |
| 36 | + - are written in Berry |
| 37 | + - closely modelled on the [TTN decoder script database](https://github.com/TheThingsNetwork/lorawan-devices/tree/master/vendor). |
| 38 | + |
| 39 | +### Example LwDecoded MQTT message |
| 40 | +``` |
| 41 | +{ |
| 42 | + "LwDecoded": { |
| 43 | + "0xAE3D": { |
| 44 | + "TempC_Internal": 25.34, |
| 45 | + "Ext_SensorType": 1, |
| 46 | + "Systimestamp": 1747038892, |
| 47 | + "Device": "Dragino LHT52", |
| 48 | + "Ext_SensorConnected": false, |
| 49 | + "Hum_Internal": 56 |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | + ## Files |
| 56 | + These files are available from the [Tasmota Github Repository]( |
| 57 | +https://github.com/arendst/Tasmota/tree/master/tasmota/berry/lorawan/decoders) |
| 58 | + |
| 59 | +- [LwDecoder.be](https://github.com/arendst/Tasmota/tree/master/tasmota/berrylorawan/decoders/LwDecoder.be) |
| 60 | +- [Device Decoder Files](https://github.com/arendst/Tasmota/tree/master/tasmota/berry/lorawan/decoders/vendors) (indexed by Vendor/Model) |
| 61 | + |
| 62 | + |
| 63 | + ## How to use the Device Decoder feature |
| 64 | + 1. Download to your local PC, then upload to the Tasmota File System |
| 65 | + - [LwDecode.be](https://github.com/arendst/Tasmota/tree/master/tasmota/berry/lorawan/decoders/LwDecode.be) |
| 66 | + - the _Device Decoder File(s)_ for your _End Device(s)_, or write your own (see below) |
| 67 | + 3. Add this line to `autoexec.be` in the Tasmota File System (create if necessary) |
| 68 | + `load("LwDecode.be")` |
| 69 | + 4. Execute these Tasmota Console commands: |
| 70 | + - `LoRaWanAppKey<x> yyyyyyyy` |
| 71 | + where `<x>` is the Tasmota LoRaWAN node number. Joins an End Device to the LoRaWan Bridge. See <a href="https://tasmota.github.io/docs/LoRa-and-LoRaWan-Bridge/#lorawan-commands" target="_blank">LoRaWan Commands</a>. |
| 72 | + - `LoRaWanDecoder<x> <decoderfile>` where `<x>` is the Tasmota LoRaWan node number. Sets the name of the _Decoder File_ for each end device. |
| 73 | + e.g. `LoRaWanDecoder1 LHT52` associates node 1 with the `LHT52.be` decoder file |
| 74 | + - `BrRestart` to restart Berry |
| 75 | + |
| 76 | + ## Write your own Device Decoder file ## |
| 77 | +1. Find the JavaScript (*.js) decoder file for your device from [TTN Device Decoder database](https://github.com/TheThingsNetwork/lorawan-devices/tree/master/vendor) |
| 78 | +Alternatively, find the manufacturer's datasheet/User Guide/User Manual/etc. to learn the syntax of the _Raw Data Payload_ |
| 79 | +2. Edit [LwDecoderSample.be](https://github.com/arendst/Tasmota/tree/master/tasmota/berry/lorawan/decoders/LwDecoderSample.be) to decode the _Raw Data Payload_ |
| 80 | +3. Rename `LwDecoderSample.be` to `<DeviceName>.be` where `<DeviceName>` matches your device name. |
| 81 | +4. Copy `<DeviceName>.be` to the _Tasmota File System_. |
| 82 | +5. Test |
| 83 | + - `load("<DeviceName>.be")` from the Berry Scripting Console, looking for any reported errors. |
| 84 | + - Execute this Tasmota console command: `LoRaWanDecoder<x> <DeviceName>` |
| 85 | + - Wait for your device to send raw Data Payloads to your Tasmota installation, and confirm `LwDecoded` MQTT messages are received, and the values are correct: |
| 86 | + |
| 87 | +6. Submit a [PR](https://github.com/arendst/Tasmota/pulls) to share your new decoder with the Tasmota community. |
| 88 | + |
| 89 | + |
0 commit comments