# Online LoRaWAN packet decoder

**URL:** <https://www.thethingsnetwork.org/forum/t/online-lorawan-packet-decoder/5095>\
**Category:** Gateways\
**Created:** [January 29, 2017, 4:52pm UTC](https://www.thethingsnetwork.org/forum/t/online-lorawan-packet-decoder/5095 "2017-01-29T16:52:43Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [December 22, 2017, 10:25am UTC](https://www.thethingsnetwork.org/forum/t/online-lorawan-packet-decoder/5095/3 "2017-12-22T10:25:53Z")

</div>

The online version ~~does~~ did not check or decrypt anything ~~(right now)~~. So, you’ll need to use the library yourself. Note that the DevAddr is in the non-encrypted part of the message headers.

```auto
mkdir my-decoder-test
cd my-decoder-test
npm install lora-packet

node <<END
const lorapacket = require('lora-packet');
const nwkSKey = new Buffer('99D58493D1205B43EFF938F0F66C339E', 'hex');
const appSKey = new Buffer('0A501524F8EA5FCBF9BDB5AD7D126F75', 'hex');
const data = new Buffer('QK4TBCaAAAABb4ldmIEHFOMmgpU=', 'base64');

const packet = lorapacket.fromWire(data);
console.log(packet.toString());

// When the node's counter has exceeded 65,536, then use a recent FCnt value
// to supply its MSB in the call to verifyMIC:
// const recentFCnt = 476604;
// const msb = new Buffer(2);
// msb.writeUInt16LE(recentFCnt >> 16, 0);
// const valid = lorapacket.verifyMIC(packet, nwkSKey, null, msb);
const valid = lorapacket.verifyMIC(packet, nwkSKey);
console.log('MIC: ' + (valid ? 'OK' : 'FAIL'));

const payload = lorapacket.decrypt(packet, appSKey, nwkSKey);
// Assume plain ASCII text, which is bad, but works for your example...
console.log('Payload: ' + payload.toString());
END

```

…gives you:

```nohighlight
Message Type = Data
            PHYPayload = 40AE130426800000016F895D98810714E3268295

          ( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
                  MHDR = 40
            MACPayload = AE130426800000016F895D98810714
                   MIC = E3268295

          ( MACPayload = FHDR | FPort | FRMPayload )
                  FHDR = AE130426800000
                 FPort = 01
            FRMPayload = 6F895D98810714

                ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
               DevAddr = 260413AE (Big Endian)
                 FCtrl = 80
                  FCnt = 0000 (Big Endian)
                 FOpts = 

          Message Type = Unconfirmed Data Up
             Direction = up
                  FCnt = 0
             FCtrl.ACK = false
             FCtrl.ADR = true
MIC: OK
Payload: abcdefg

```

(You should keep the session keys secret, as anyone can now send data to your application. Also, you [should not send text](https://www.thethingsnetwork.org/forum/t/best-practices-to-limit-application-payloads/1302).)

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/online-lorawan-packet-decoder/5095)._
