Xenon Lamp Aging Test Chamber,Xenon Lamp Aging Light Tester,Photovoltaic Module Test Box,Xenon Lamp Aging Testing Machine Wuxi Juxingyao Trading Co., Ltd , https://www.juxingyao.com
Several common network access methods based on lorawan protocol
OTAA (Over-The-Air Activation) is a network joining method used in LoRaWAN. When a device starts up and is not already connected to a network, it must go through an activation process to communicate with the server. This process begins when the node sends a **Join Request** message to the network. The server then responds with a **Join Accept** message if it approves the connection. Once the node receives and decrypts this message, it can obtain the necessary communication keys and parameters to start sending data.
By the way, here are some useful online tools that might help you during development:
- **HEX/String Converter**
- **JSON Validator**
- **Base64 Encoder/Decoder**
### OTAA Mode Setup
Before a device can join the network using OTAA, it needs three essential parameters:
1. **AppEUI**: A 8-byte unique identifier assigned to the node.
2. **AppKey**: A 16-byte key shared between the node and the server for encryption/decryption of the Join Accept message.
3. **DevNonce**: A 2-byte random number used to generate the session keys (NwkSKey and AppSKey).
These values can be hardcoded into the firmware or configured via serial interface or other means before the device goes live.
### Step-by-Step OTAA Process
#### Step 1: Node Sends Join Request
The node initiates the process by sending a **Join Request** message. This message is unencrypted and contains information such as the DevEUI, AppEUI, and DevNonce.
#### Step 2: Gateway Forwards the Message
The gateway (GW) receives the message, encodes it in Base64, and sends it to the Network Server (NS) in a JSON format. The raw MAC layer data is found in `rxpk.data`.
Example base64 string:
`0AQAAAAAIAAAjQYwLgEAAJcG`
Decoding this gives:
`\x00\x01\x00\x00\x20\x00\xc5\x26\x2c\x16\x10\x16\x20\x00\x77\x4a\x00\x54\x7b\x40\x2d\xe1\x9a`
This represents the raw MAC payload of the Join Request.
#### Step 3: NS Passes to Application Server (AS)
The Network Server forwards the Join Request to the Application Server (AS). The AS verifies the request and prepares to generate session keys.
#### Step 4: AS Approves the Join
If the AS approves the join, it sends a response back to the NS, confirming the device’s access to the network.
#### Step 5: NS Generates Mote Address
The NS generates a unique **Mote Address (DevAddr)** and sends it back to the AS for further processing.
#### Step 6: AS Generates Keys
The AS generates the **NwkSKey** and **AppSKey**, which are used for encrypting and decrypting traffic. The NwkSKey is sent directly to the NS, as it's needed for verifying incoming and outgoing packets.
#### Step 7: NS Sends Join Accept to the Node
The NS sends the encrypted **Join Accept** message back to the GW, which then transmits it to the node in a MAC frame.
The `txpk.data` field contains the encrypted Join Accept message. It is encoded in Base64 and requires decryption using the **AppKey**.
Example:
`IPqAKXQ7LS/CmYVCDy8K3k4`
After decoding and decrypting with the AppKey, the message reveals the **DevAddr**, **NwkSKey**, and **AppSKey**.
#### Step 8: Node Parses Join Accept
Once the node successfully decrypts the Join Accept message, it extracts the session keys and uses them for secure communication with the server.
The structure of the Join Accept message includes:
- **DevAddr**: The device’s address on the network.
- **AppSKey & NwkSKey**: Used for encrypting and decrypting application and network data.
To derive these keys, the following formula is used:
- **NwkSKey = AES128_Encrypt(AppKey, 0x01 | AppNonce | NetID | DevNonce | pad16)**
- **AppSKey = AES128_Encrypt(AppKey, 0x02 | AppNonce | NetID | DevNonce | pad16)**
This completes the OTAA process, allowing the node to securely communicate with the LoRaWAN network.