cc263c1ecf7b6025f800aa305872e00961daebee
Tech-dat/Network-dat/RF-dat/LORA-DAT/Lora-SDK-dat/Lora-SDK-dat.md
| ... | ... | @@ -1,5 +1,14 @@ |
| 1 | 1 | # Lora-SDK-dat |
| 2 | 2 | |
| 3 | +## network ID and address |
|
| 4 | + |
|
| 5 | +For LoRa coding, the network ID and address (often called device address or node address) are typically set in the software/firmware of the device, not in the data payload or by hardware switches. |
|
| 6 | + |
|
| 7 | +**LoRaWAN**: The device address (DevAddr), network session keys, and other identifiers are set in the device firmware and used by the LoRaWAN protocol stack. These are not sent in the application data payload; instead, they are part of the protocol headers. |
|
| 8 | + |
|
| 9 | +**Raw LoRa (non-LoRaWAN)**: If you are implementing your own protocol, you can choose to include a node address or network ID in the data payload, or you can set it in the firmware and use it as part of your packet structure. |
|
| 10 | + |
|
| 11 | + |
|
| 3 | 12 | ## stm32 code |
| 4 | 13 | |
| 5 | 14 |  |
| ... | ... | @@ -22,13 +31,58 @@ Path: The UserConfig.c file in LR_driver is a common file generated when adaptin |
| 22 | 31 | |
| 23 | 32 | |
| 24 | 33 | |
| 25 | -## code |
|
| 34 | +## code repro |
|
| 26 | 35 | |
| 27 | 36 | - info for EE22, EE32, EE2 == https://github.com/Edragon/lora |
| 28 | 37 | - lora2 designs == https://github.com/Edragon/Lora2 |
| 29 | 38 | - https://github.com/Edragon/alios-asr-lora |
| 30 | 39 | - E:\Git-category\git-lora |
| 31 | 40 | |
| 41 | +## lora encrpytion |
|
| 42 | + |
|
| 43 | +To encrypt data for LoRa by coding, you typically use a symmetric encryption algorithm like AES before sending the data. Here’s a general approach: |
|
| 44 | + |
|
| 45 | +1. Choose an Encryption Library |
|
| 46 | +Most platforms (Arduino, STM32, Raspberry Pi, etc.) have AES libraries available. For example, on Arduino you can use [AESLib](https://github.com/DavyLandman/AESLib). |
|
| 47 | + |
|
| 48 | +2. Encrypt Data Before Sending |
|
| 49 | +Encrypt your payload before passing it to the LoRa send function. |
|
| 50 | + |
|
| 51 | +Example (Arduino, using AESLib): |
|
| 52 | + |
|
| 53 | + #include <AESLib.h> |
|
| 54 | + |
|
| 55 | + AESLib aesLib; |
|
| 56 | + |
|
| 57 | + byte aes_key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
|
| 58 | + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; // 16 bytes key |
|
| 59 | + |
|
| 60 | + char plainText[] = "Hello, LoRa!"; |
|
| 61 | + byte encrypted[32]; |
|
| 62 | + |
|
| 63 | + int dataLen = strlen(plainText); |
|
| 64 | + int encLen = aesLib.encrypt((byte*)plainText, dataLen, encrypted, aes_key, 128); |
|
| 65 | + |
|
| 66 | + LoRa.beginPacket(); |
|
| 67 | + LoRa.write(encrypted, encLen); |
|
| 68 | + LoRa.endPacket(); |
|
| 69 | + |
|
| 70 | +3. Decrypt on Receiver Side |
|
| 71 | +On the receiver, use the same key to decrypt the received data. |
|
| 72 | + |
|
| 73 | +Example (Arduino, using AESLib): |
|
| 74 | + |
|
| 75 | + byte decrypted[32]; |
|
| 76 | + int decLen = aesLib.decrypt(receivedData, receivedLen, decrypted, aes_key, 128); |
|
| 77 | + // Now 'decrypted' contains your original message |
|
| 78 | + |
|
| 79 | + |
|
| 80 | +### Notes |
|
| 81 | + |
|
| 82 | +- Key Management: Both sender and receiver must use the same key. |
|
| 83 | +- LoRaWAN: If you use LoRaWAN, encryption is handled by the protocol stack automatically. |
|
| 84 | +- Raw LoRa: You must implement encryption/decryption yourself as shown above. |
|
| 85 | + |
|
| 32 | 86 | ## ref |
| 33 | 87 | |
| 34 | 88 | - [[lora-dat]] |
| ... | ... | \ No newline at end of file |