Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jieter/python-lora

Decrypt LoRa payloads in python.
https://github.com/jieter/python-lora

Last synced: 7 days ago
JSON representation

Decrypt LoRa payloads in python.

Awesome Lists containing this project

README

        

# python-lora

Python wrapper for LoRa payloads from Thingpark/Actility, allowing decryption of the payload.

- Depends on [cryptography]
- Based on crypto code in [Lora-net/LoRaMac-node]
- Tested with python 3.8, 3.9, 3.10, 3.11
- Available on [pypi]

## Usage

`pip install python-lora`

[cryptography] requires [cffi] which in turn requires `libffi-dev` and `python-dev`.

```python
from lora.payload import LoRaPayload

xmlstr = '''
[...]
2[...]
[...][...]
'''

payload = LoRaPayload(xmlstr)

key = 'AABBCCDDEEFFAABBCCDDEEFFAABBCCDD'
dev_addr = '00112233'
plaintext = payload.decrypt(key, dev_addr)
```

You can also use `loramac_decrypt` without the XML wrapper to decode a hex-encoded `FRMPayload`:
```python
>>> from lora.crypto import loramac_decrypt
>>> payload = '11daf7a44d5e2bbe557176e9e6c8da'
>>> sequence_counter = 2
>>> key = 'AABBCCDDEEFFAABBCCDDEEFFAABBCCDD'
>>> dev_addr = '00112233'
>>> loramac_decrypt(payload, sequence_counter, key, dev_addr)
[222, 59, 24, 8, 7, 155, 237, 158, 103, 125, 93, 34, 161, 204, 33]
```

[cryptography]: https://cryptography.io/
[cffi]: https://cffi.readthedocs.org/en/latest/
[pypi]: https://pypi.python.org/pypi/python-lora
[Lora-net/LoRaMac-node]: https://github.com/Lora-net/LoRaMac-node/blob/master/src/mac/LoRaMacCrypto.c#L108