Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just a clarification regarding the decrypt node #3

Open
luca-ferrari-roma opened this issue Mar 22, 2021 · 7 comments
Open

Just a clarification regarding the decrypt node #3

luca-ferrari-roma opened this issue Mar 22, 2021 · 7 comments

Comments

@luca-ferrari-roma
Copy link

Hi again Markus.
I have created this simple decrypting node, but, a cannot more be able to decrypt any simple payload message.

image

The output message is:
Network Key issue! Raw packet: Message Type = Data
PHYPayload = 4010190126006B0003DCB3C9BA1C8B494D0207EB837C2128F565E988
( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
MHDR = 40
MACPayload = 10190126006B0003DCB3C9BA1C8B494D0207EB837C2128
MIC = F565E988

( MACPayload = FHDR | FPort | FRMPayload )
FHDR = 10190126006B00
FPort = 03
FRMPayload = DCB3C9BA1C8B494D0207EB837C2128

( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
DevAddr = 26011910 (Big Endian)
FCtrl = 00
FCnt = 006B (Big Endian)
FOpts =
Message Type = Unconfirmed Data Up
Direction = up
FCnt = 107
FCtrl.ACK = false
FCtrl.ADR = false
FCtrl.ADRACKReq = false

Some ideas?
Thank you
Luca

Here the simple flow.
[{"id":"4a73d0d8.89431","type":"tab","label":"LoraWAN Decrypt","disabled":false,"info":""},{"id":"34a6ef3f.aaf37","type":"debug","z":"4a73d0d8.89431","name":"Decrypted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":480,"wires":[]},{"id":"3ca8a885.bea768","type":"function","z":"4a73d0d8.89431","name":"Extract Packet","func":"devid="12345678901 "\n\n// the lora lora-packet-converter package expect device id (12) as a string before the Lora wan Packet\nmvk=msg.payload.rxpk[0].data // from the injection \nnode.warn(mvk)\n//test={"rxpk":[{"data":"QIoaASYAYAABTqf1tMolR+Q=","time":"2019-10-16T02:43:52.558399Z","chan":0,"tmst":110465012,"stat":1,"modu":"LORA","lsnr":1,"rssi":-113,"rfch":0,"codr":"4/5","freq":903.9,"datr":"SF7BW125","size":17}]}\n//msg={}\nmsg.payload=mvk\n\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":320,"wires":[["8ad92548.375908","89b28976.c54888"]]},{"id":"81099f12.8eafa","type":"inject","z":"4a73d0d8.89431","name":"LoraWAN message form pi with CPU load","props":[{"p":"payload","v":"{"rxpk":[{"tmst":361263036,"time":"2020-11-15T14:17:19.861818Z","chan":1,"rfch":0,"freq":868.300000,"stat":1,"modu":"LORA","datr":"SF9BW125","codr":"4/5","lsnr":10.0,"rssi":-49,"size":28,"data":"QBAZASYAawAD3LPJuhyLSU0CB+uDfCEo9WXpiA=="}]}","vt":"json"},{"p":"topic","v":"test message","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test message","payload":"{"rxpk":[{"tmst":361263036,"time":"2020-11-15T14:17:19.861818Z","chan":1,"rfch":0,"freq":868.300000,"stat":1,"modu":"LORA","datr":"SF9BW125","codr":"4/5","lsnr":10.0,"rssi":-49,"size":28,"data":"QBAZASYAawAD3LPJuhyLSU0CB+uDfCEo9WXpiA=="}]}","payloadType":"json","x":320,"y":180,"wires":[["3ca8a885.bea768"]]},{"id":"6af837af.47c558","type":"function","z":"4a73d0d8.89431","name":"Sensor data to hex/decode","func":"\nbytes=msg.payload.out // sensor/LoraWAN data playload\n\nnewbytes=Buffer.from(bytes, 'hex')\nnode.warn(newbytes) ///yeah\n\n//decode ...payload\n//https://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython?view=all\n\nCPU_Load = (newbytes[0] << 8) | newbytes[1];\noTemperature = (newbytes[2] << 8) | newbytes[1];\n \nmsg.payload.CPU_Load = CPU_Load / 100;\nmsg.payload.oTemperature = oTemperature / 100;\n \nreturn msg;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","outputs":1,"noerr":0,"x":700,"y":380,"wires":[["fea8e687.81dab8"]]},{"id":"d790ce78.ea957","type":"comment","z":"4a73d0d8.89431","name":"Example of Decryptin and decoding LoraWAN message","info":"Note:\nI use the APP & network key form TheThinkNetwork\n\nmy Hardware was a pycom LoPY as Single Channel Gateway\nand a Lora PI Bonnet using python\nhttps://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython?view=all\n\nI want to send the Lora Message directly via mqtt to node-red and process\nthem there with out the need of a loraWAN server\n\n\nhere a good link for testing\nhttps://lorawan-packet-decoder-0ta6puiniaut.runkit.sh\nhere more infos\nhttps://github.com/anthonykirby/lora-packet/blob/master/demo/demo1.js\nmore infos\nhttps://forum.pycom.io/topic/3958/how-decrypt-lora-data/3\nhttps://codebeautify.org/string-hex-converter","x":520,"y":40,"wires":[]},{"id":"fea8e687.81dab8","type":"debug","z":"4a73d0d8.89431","name":"Sensor Data Decoded","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":980,"y":380,"wires":[]},{"id":"8ad92548.375908","type":"debug","z":"4a73d0d8.89431","name":"InComing LoraWAN","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":480,"y":320,"wires":[]},{"id":"e9b2f33b.9c62d","type":"comment","z":"4a73d0d8.89431","name":"Example payload with CPU and temp","info":"{\n "value": "hello",\n "type": "dev",\n "msgid": 0,\n "data": {\n "rxpk": [\n {\n "data": "QIoaASYAYAABTqf1tMolR+Q=",\n "time": "2019-10-16T02:43:52.558399Z",\n "chan": 0,\n "tmst": 110465012,\n "stat": 1,\n "modu": "LORA",\n "lsnr": 1,\n "rssi": -113,\n "rfch": 0,\n "codr": "4/5",\n "freq": 903.9,\n "datr": "SF7BW125",\n "size": 17\n }\n ]\n }\n}","x":470,"y":80,"wires":[]},{"id":"2f0f1699.9ad3ba","type":"comment","z":"4a73d0d8.89431","name":"Network Key","info":"27E87B6710ACC5FB9098F19AE77DC62B","x":710,"y":80,"wires":[]},{"id":"d8b1e23c.4017b","type":"comment","z":"4a73d0d8.89431","name":"App Key","info":"B887FD00569BE0746E8020746EFC9BA8","x":700,"y":120,"wires":[]},{"id":"89b28976.c54888","type":"lorawan-packet-decrypt-nwkey-appkey","z":"4a73d0d8.89431","name":"","nsw":"27E87B6710ACC5FB9098F19AE77DC62B","asw":"B887FD00569BE0746E8020746EFC9BA8","x":410,"y":380,"wires":[["6af837af.47c558","34a6ef3f.aaf37"]]}]

@lorenzozaccomer
Copy link

I have the same issue, @luca-ferrari-roma have you solved?

@markusvankempen
Copy link
Owner

Hello @luca-ferrari-roma @lorenzozaccomer

i could not import your flow. If you use your own payload make sure to update the nwkey and appkey.
Also the message maybe still encrypted with cayennelpp and you need run it thru cayennelpp decypter?
hope that helps
Cheers

example flow

[{"id":"a74db0e0.91ab1","type":"debug","z":"ec5503c5.67d66","name":"Decrypted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":310,"y":460,"wires":[]},{"id":"c5c58eb3.53e3e","type":"function","z":"ec5503c5.67d66","name":"Extract Packet","func":"devid="12345678901 "\n\n// the lora lora-packet-converter package expect device id (12) as a string before the Lora wan Packet\nmvk=msg.payload.data.rxpk[0].data // from the injection \nnode.warn(mvk)\n//test={"rxpk":[{"data":"QIoaASYAYAABTqf1tMolR+Q=","time":"2019-10-16T02:43:52.558399Z","chan":0,"tmst":110465012,"stat":1,"modu":"LORA","lsnr":1,"rssi":-113,"rfch":0,"codr":"4/5","freq":903.9,"datr":"SF7BW125","size":17}]}\n//msg={}\nmsg.payload=mvk\n\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":320,"wires":[["cc7f2fac.17caa","7bd0e5e1.8efacc"]]},{"id":"beec1fb9.09351","type":"inject","z":"ec5503c5.67d66","name":"LoraWAN message form pi with CPU load","topic":"test message","payload":"{"value":"hello","type":"dev","msgid":0,"data":{"rxpk":[{"data":"QIoaASYAYAABTqf1tMolR+Q=","time":"2019-10-16T02:43:52.558399Z","chan":0,"tmst":110465012,"stat":1,"modu":"LORA","lsnr":1,"rssi":-113,"rfch":0,"codr":"4/5","freq":903.9,"datr":"SF7BW125","size":17}]}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":260,"wires":[["c5c58eb3.53e3e"]]},{"id":"dcee074f.b269e8","type":"function","z":"ec5503c5.67d66","name":"Sensor data to hex/decode","func":"\nbytes=msg.payload.out // sensor/LoraWAN data playload\n\nnewbytes=Buffer.from(bytes, 'hex')\nnode.warn(newbytes) ///yeah\n\n//decode ...payload\n//https://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython?view=all\n\nCPU_Load = (newbytes[0] << 8) | newbytes[1];\noTemperature = (newbytes[2] << 8) | newbytes[1];\n \nmsg.payload.CPU_Load = CPU_Load / 100;\nmsg.payload.oTemperature = oTemperature / 100;\n \nreturn msg;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","outputs":1,"noerr":0,"x":500,"y":380,"wires":[["7217258b.549fbc"]]},{"id":"6b9a2213.c47d7c","type":"comment","z":"ec5503c5.67d66","name":"Example of Decryptin and decoding LoraWAN message","info":"Note:\nI use the APP & network key form TheThinkNetwork\n\nmy Hardware was a pycom LoPY as Single Channel Gateway\nand a Lora PI Bonnet using python\nhttps://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython?view=all\n\nI want to send the Lora Message directly via mqtt to node-red and process\nthem there with out the need of a loraWAN server\n\n\nhere a good link for testing\nhttps://lorawan-packet-decoder-0ta6puiniaut.runkit.sh\nhere more infos\nhttps://github.com/anthonykirby/lora-packet/blob/master/demo/demo1.js\nmore infos\nhttps://forum.pycom.io/topic/3958/how-decrypt-lora-data/3\nhttps://codebeautify.org/string-hex-converter","x":320,"y":200,"wires":[]},{"id":"7217258b.549fbc","type":"debug","z":"ec5503c5.67d66","name":"Sensor Data Decoded","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":780,"y":380,"wires":[]},{"id":"cc7f2fac.17caa","type":"debug","z":"ec5503c5.67d66","name":"InComing LoraWAN","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":480,"y":320,"wires":[]},{"id":"da7046c8.55b788","type":"comment","z":"ec5503c5.67d66","name":"Example payload with CPU and temp","info":"{\n "value": "hello",\n "type": "dev",\n "msgid": 0,\n "data": {\n "rxpk": [\n {\n "data": "QIoaASYAYAABTqf1tMolR+Q=",\n "time": "2019-10-16T02:43:52.558399Z",\n "chan": 0,\n "tmst": 110465012,\n "stat": 1,\n "modu": "LORA",\n "lsnr": 1,\n "rssi": -113,\n "rfch": 0,\n "codr": "4/5",\n "freq": 903.9,\n "datr": "SF7BW125",\n "size": 17\n }\n ]\n }\n}","x":830,"y":200,"wires":[]},{"id":"8fc08934.101638","type":"comment","z":"ec5503c5.67d66","name":"Network Key","info":"27E87B6710ACC5FB9098F19AE77DC62B","x":750,"y":240,"wires":[]},{"id":"4954ca3.46bdf34","type":"comment","z":"ec5503c5.67d66","name":"App Key","info":"B887FD00569BE0746E8020746EFC9BA8","x":740,"y":280,"wires":[]},{"id":"7bd0e5e1.8efacc","type":"lorawan-packet-decrypt-nwkey-appkey","z":"ec5503c5.67d66","name":"Decrypt LoRaWAN","nsw":"27E87B6710ACC5FB9098F19AE77DC62B","asw":"B887FD00569BE0746E8020746EFC9BA8","x":210,"y":380,"wires":[["a74db0e0.91ab1","dcee074f.b269e8"]]},{"id":"c19d4d58.67d4c","type":"cayennelpp-decoder","z":"ec5503c5.67d66","name":"","x":480,"y":580,"wires":[["8a34ab1f.0facf8"]]},{"id":"b78dae98.1744","type":"inject","z":"ec5503c5.67d66","name":"","topic":"","payload":"016700f6017300aa01020000020200640103020402030064","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":580,"wires":[["c19d4d58.67d4c"]]},{"id":"8a34ab1f.0facf8","type":"debug","z":"ec5503c5.67d66","name":"Decrypted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":730,"y":580,"wires":[]}]

@lorenzozaccomer
Copy link

@markusvankempen I copied your new flow but I can't, there are some errors ...

In your original flow I use my own payload and my appkey and nwkey and I obtain the error that @luca-ferrari-roma have posted.

On the website the same datas that I used on Node-RED work perfectly.

@markusvankempen
Copy link
Owner

@lorenzozaccomer try this flow which is the org. (in the once above i added lpp decrypt https://flows.nodered.org/node/node-red-contrib-cayennelpp-extended)

here the org flow maybe use this add your payload and keys and post back here if you can

[{"id":"a74db0e0.91ab1","type":"debug","z":"ec5503c5.67d66","name":"Decrypted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":310,"y":460,"wires":[]},{"id":"c5c58eb3.53e3e","type":"function","z":"ec5503c5.67d66","name":"Extract Packet","func":"devid="12345678901 "\n\n// the lora lora-packet-converter package expect device id (12) as a string before the Lora wan Packet\nmvk=msg.payload.data.rxpk[0].data // from the injection \nnode.warn(mvk)\n//test={"rxpk":[{"data":"QIoaASYAYAABTqf1tMolR+Q=","time":"2019-10-16T02:43:52.558399Z","chan":0,"tmst":110465012,"stat":1,"modu":"LORA","lsnr":1,"rssi":-113,"rfch":0,"codr":"4/5","freq":903.9,"datr":"SF7BW125","size":17}]}\n//msg={}\nmsg.payload=mvk\n\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":320,"wires":[["cc7f2fac.17caa","7bd0e5e1.8efacc"]]},{"id":"beec1fb9.09351","type":"inject","z":"ec5503c5.67d66","name":"LoraWAN message form pi with CPU load","topic":"test message","payload":"{"value":"hello","type":"dev","msgid":0,"data":{"rxpk":[{"data":"QIoaASYAYAABTqf1tMolR+Q=","time":"2019-10-16T02:43:52.558399Z","chan":0,"tmst":110465012,"stat":1,"modu":"LORA","lsnr":1,"rssi":-113,"rfch":0,"codr":"4/5","freq":903.9,"datr":"SF7BW125","size":17}]}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":260,"wires":[["c5c58eb3.53e3e"]]},{"id":"dcee074f.b269e8","type":"function","z":"ec5503c5.67d66","name":"Sensor data to hex/decode","func":"\nbytes=msg.payload.out // sensor/LoraWAN data playload\n\nnewbytes=Buffer.from(bytes, 'hex')\nnode.warn(newbytes) ///yeah\n\n//decode ...payload\n//https://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython?view=all\n\nCPU_Load = (newbytes[0] << 8) | newbytes[1];\noTemperature = (newbytes[2] << 8) | newbytes[1];\n \nmsg.payload.CPU_Load = CPU_Load / 100;\nmsg.payload.oTemperature = oTemperature / 100;\n \nreturn msg;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","outputs":1,"noerr":0,"x":500,"y":380,"wires":[["7217258b.549fbc"]]},{"id":"6b9a2213.c47d7c","type":"comment","z":"ec5503c5.67d66","name":"Example of Decryptin and decoding LoraWAN message","info":"Note:\nI use the APP & network key form TheThinkNetwork\n\nmy Hardware was a pycom LoPY as Single Channel Gateway\nand a Lora PI Bonnet using python\nhttps://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython?view=all\n\nI want to send the Lora Message directly via mqtt to node-red and process\nthem there with out the need of a loraWAN server\n\n\nhere a good link for testing\nhttps://lorawan-packet-decoder-0ta6puiniaut.runkit.sh\nhere more infos\nhttps://github.com/anthonykirby/lora-packet/blob/master/demo/demo1.js\nmore infos\nhttps://forum.pycom.io/topic/3958/how-decrypt-lora-data/3\nhttps://codebeautify.org/string-hex-converter","x":320,"y":200,"wires":[]},{"id":"7217258b.549fbc","type":"debug","z":"ec5503c5.67d66","name":"Sensor Data Decoded","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":780,"y":380,"wires":[]},{"id":"cc7f2fac.17caa","type":"debug","z":"ec5503c5.67d66","name":"InComing LoraWAN","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":480,"y":320,"wires":[]},{"id":"da7046c8.55b788","type":"comment","z":"ec5503c5.67d66","name":"Example payload with CPU and temp","info":"{\n "value": "hello",\n "type": "dev",\n "msgid": 0,\n "data": {\n "rxpk": [\n {\n "data": "QIoaASYAYAABTqf1tMolR+Q=",\n "time": "2019-10-16T02:43:52.558399Z",\n "chan": 0,\n "tmst": 110465012,\n "stat": 1,\n "modu": "LORA",\n "lsnr": 1,\n "rssi": -113,\n "rfch": 0,\n "codr": "4/5",\n "freq": 903.9,\n "datr": "SF7BW125",\n "size": 17\n }\n ]\n }\n}","x":830,"y":200,"wires":[]},{"id":"8fc08934.101638","type":"comment","z":"ec5503c5.67d66","name":"Network Key","info":"27E87B6710ACC5FB9098F19AE77DC62B","x":750,"y":240,"wires":[]},{"id":"4954ca3.46bdf34","type":"comment","z":"ec5503c5.67d66","name":"App Key","info":"B887FD00569BE0746E8020746EFC9BA8","x":740,"y":280,"wires":[]},{"id":"7bd0e5e1.8efacc","type":"lorawan-packet-decrypt-nwkey-appkey","z":"ec5503c5.67d66","name":"Decrypt LoRaWAN","nsw":"27E87B6710ACC5FB9098F19AE77DC62B","asw":"B887FD00569BE0746E8020746EFC9BA8","x":210,"y":380,"wires":[["a74db0e0.91ab1","dcee074f.b269e8"]]}]

@lorenzozaccomer
Copy link

lorenzozaccomer commented Oct 27, 2021

@markusvankempen what do you mean with .org.?
I copied that but there are some errors, I cannot import it ...

This is my version, I put my payload on data field (inject node) and my nwkey,appkey on Decrypt node.

Payload: 404A23C1AB0085010174F2F25959595D2BAC0E5D7F8B4DCFF7463930682D
Appkey: 744826b8703e23a2e6cb8d79eed484bb
Nwkey: 238792b74801de223b50ddd309b8f139

The decrypted message is: T:25:U:1566:X:111

On the bottom there's the flow, if you want to test it, the error is:
Error: Expected DevAddr to be defined

[
    {
        "id": "e3322e49.7b59f",
        "type": "tab",
        "label": "LoraWAN Decrypt",
        "disabled": false,
        "info": ""
    },
    {
        "id": "cd91624b.2fa5c",
        "type": "debug",
        "z": "e3322e49.7b59f",
        "name": "Decrypted",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 310,
        "y": 460,
        "wires": []
    },
    {
        "id": "b449b928.92c388",
        "type": "function",
        "z": "e3322e49.7b59f",
        "name": "Extract Packet",
        "func": "devid=\"12345678901 \"\n\n// the lora lora-packet-converter package expect device id (12) as a string before the Lora wan Packet\nmvk=msg.payload.data.rxpk[0].data // from the injection \nnode.warn(mvk)\n//test={\"rxpk\":[{\"data\":\"QIoaASYAYAABTqf1tMolR+Q=\",\"time\":\"2019-10-16T02:43:52.558399Z\",\"chan\":0,\"tmst\":110465012,\"stat\":1,\"modu\":\"LORA\",\"lsnr\":1,\"rssi\":-113,\"rfch\":0,\"codr\":\"4/5\",\"freq\":903.9,\"datr\":\"SF7BW125\",\"size\":17}]}\n//msg={}\nmsg.payload=mvk\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 220,
        "y": 320,
        "wires": [
            [
                "a0b02dbe.69862",
                "b34f45d7.9b6328"
            ]
        ]
    },
    {
        "id": "d9a7e541.245dd8",
        "type": "inject",
        "z": "e3322e49.7b59f",
        "name": "LoraWAN message form pi  with CPU load",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "test message",
        "payload": "{\"value\":\"hello\",\"type\":\"dev\",\"msgid\":0,\"data\":{\"rxpk\":[{\"data\":\"404A23C1AB0085010174F2F25959595D2BAC0E5D7F8B4DCFF7463930682D\",\"time\":\"2019-10-16T02:43:52.558399Z\",\"chan\":0,\"tmst\":110465012,\"stat\":1,\"modu\":\"LORA\",\"lsnr\":1,\"rssi\":-113,\"rfch\":0,\"codr\":\"4/5\",\"freq\":903.9,\"datr\":\"SF7BW125\",\"size\":17}]}}",
        "payloadType": "json",
        "x": 300,
        "y": 260,
        "wires": [
            [
                "b449b928.92c388"
            ]
        ]
    },
    {
        "id": "7055b83c.074f68",
        "type": "function",
        "z": "e3322e49.7b59f",
        "name": "Sensor data to hex/decode",
        "func": "\nbytes=msg.payload.out // sensor/LoraWAN data playload\n\nnewbytes=Buffer.from(bytes, 'hex')\nnode.warn(newbytes) ///yeah\n\n//decode ...payload\n//https://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython?view=all\n\nCPU_Load = (newbytes[0] << 8) | newbytes[1];\noTemperature = (newbytes[2] << 8) | newbytes[1];\n   \nmsg.payload.CPU_Load = CPU_Load / 100;\nmsg.payload.oTemperature = oTemperature / 100;\n  \nreturn msg;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
        "outputs": 1,
        "noerr": 0,
        "x": 500,
        "y": 380,
        "wires": [
            [
                "71678020.4fb4d"
            ]
        ]
    },
    {
        "id": "ed2894f.322f168",
        "type": "comment",
        "z": "e3322e49.7b59f",
        "name": "Example of Decryptin and decoding LoraWAN message",
        "info": "Note:\nI use the APP & network key form TheThinkNetwork\n\nmy Hardware was a pycom LoPY as Single Channel Gateway\nand a Lora PI Bonnet using python\nhttps://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython?view=all\n\nI want to send the Lora Message directly via mqtt to node-red and process\nthem there with out the need of a loraWAN server\n\n\nhere a good link for testing\nhttps://lorawan-packet-decoder-0ta6puiniaut.runkit.sh\nhere more infos\nhttps://github.com/anthonykirby/lora-packet/blob/master/demo/demo1.js\nmore infos\nhttps://forum.pycom.io/topic/3958/how-decrypt-lora-data/3\nhttps://codebeautify.org/string-hex-converter",
        "x": 320,
        "y": 200,
        "wires": []
    },
    {
        "id": "71678020.4fb4d",
        "type": "debug",
        "z": "e3322e49.7b59f",
        "name": "Sensor Data Decoded",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 780,
        "y": 380,
        "wires": []
    },
    {
        "id": "a0b02dbe.69862",
        "type": "debug",
        "z": "e3322e49.7b59f",
        "name": "InComing LoraWAN",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 480,
        "y": 320,
        "wires": []
    },
    {
        "id": "7a41cd57.b1ce94",
        "type": "comment",
        "z": "e3322e49.7b59f",
        "name": "Example payload with CPU and temp",
        "info": "{\n    \"value\": \"hello\",\n    \"type\": \"dev\",\n    \"msgid\": 0,\n    \"data\": {\n        \"rxpk\": [\n            {\n                \"data\": \"QIoaASYAYAABTqf1tMolR+Q=\",\n                \"time\": \"2019-10-16T02:43:52.558399Z\",\n                \"chan\": 0,\n                \"tmst\": 110465012,\n                \"stat\": 1,\n                \"modu\": \"LORA\",\n                \"lsnr\": 1,\n                \"rssi\": -113,\n                \"rfch\": 0,\n                \"codr\": \"4/5\",\n                \"freq\": 903.9,\n                \"datr\": \"SF7BW125\",\n                \"size\": 17\n            }\n        ]\n    }\n}",
        "x": 830,
        "y": 200,
        "wires": []
    },
    {
        "id": "a819c4e6.287908",
        "type": "comment",
        "z": "e3322e49.7b59f",
        "name": "Network Key",
        "info": "27E87B6710ACC5FB9098F19AE77DC62B",
        "x": 750,
        "y": 240,
        "wires": []
    },
    {
        "id": "f0f1f445.6237e8",
        "type": "comment",
        "z": "e3322e49.7b59f",
        "name": "App Key",
        "info": "B887FD00569BE0746E8020746EFC9BA8",
        "x": 740,
        "y": 280,
        "wires": []
    },
    {
        "id": "b34f45d7.9b6328",
        "type": "lorawan-packet-decrypt-nwkey-appkey",
        "z": "e3322e49.7b59f",
        "name": "Decrypt LoRaWAN",
        "nsw": "238792b74801de223b50ddd309b8f139",
        "asw": "744826b8703e23a2e6cb8d79eed484bb",
        "x": 210,
        "y": 380,
        "wires": [
            [
                "cd91624b.2fa5c",
                "7055b83c.074f68"
            ]
        ]
    },
    {
        "id": "798d38ee4bc21107",
        "type": "cayennelpp-decoder",
        "z": "e3322e49.7b59f",
        "name": "",
        "x": 190,
        "y": 540,
        "wires": [
            []
        ]
    }
]

@markusvankempen
Copy link
Owner

markusvankempen commented Oct 27, 2021

Hello @lorenzozaccomer
I found the issue - your payload needs to be in base64

404A23C1AB0085010174F2F25959595D2BAC0E5D7F8B4DCFF7463930682D (hex)
QEojwasAhQEBdPLyWVlZXSusDl1/i03P90Y5MGgt (base64)

you can convert it like
node.warn(Buffer.from("404A23C1AB0085010174F2F25959595D2BAC0E5D7F8B4DCFF7463930682D", 'hex').toString('base64'))

incoming message example with your payload

{
"value": "hello",
"type": "dev",
"msgid": 0,
"data": {
"rxpk": [
{
"data": "QEojwasAhQEBdPLyWVlZXSusDl1/i03P90Y5MGgt",
"time": "2019-10-16T02:43:52.558399Z",
"chan": 0,
"tmst": 110465012,
"stat": 1,
"modu": "LORA",
"lsnr": 1,
"rssi": -113,
"rfch": 0,
"codr": "4/5",
"freq": 903.9,
"datr": "SF7BW125",
"size": 17
}
]
}
}

and than just do a

bytes=msg.payload.out // sensor/LoraWAN data playload
newbytes=Buffer.from(bytes, 'hex') // detcrypted payload in hex
node.warn(newbytes.toString() ) /// detcrypted payload in ascii

That should do the trick ...
decode payload = "T:25:U:1566:X:111"

here the output ...

{"_msgid":"4066ca3a.d39ea4","topic":"test message","payload":{"in":"QEojwasAhQEBdPLyWVlZXSusDl1/i03P90Y5MGgt","out":"543a32353a553a313536363a583a313131","buffers":{"PHYPayload":[64,74,35,193,171,0,133,1,1,116,242,242,89,89,89,93,43,172,14,93,127,139,77,207,247,70,57,48,104,45],"MHDR":[64],"MACPayload":[74,35,193,171,0,133,1,1,116,242,242,89,89,89,93,43,172,14,93,127,139,77,207,247,70],"MACPayloadWithMIC":[74,35,193,171,0,133,1,1,116,242,242,89,89,89,93,43,172,14,93,127,139,77,207,247,70,57,48,104,45],"MIC":[57,48,104,45],"FCtrl":[0],"FOpts":[],"FHDR":[74,35,193,171,0,133,1],"DevAddr":[171,193,35,74],"FCnt":[1,133],"FPort":[1],"FRMPayload":[116,242,242,89,89,89,93,43,172,14,93,127,139,77,207,247,70]},"assci":"T:25:U:1566:X:111"}}

@lorenzozaccomer
Copy link

Thank you @markusvankempen for your replies, I solved my problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants