Skip to main content

LoraWan

LoraWan Theory

🚧
I'm working on this guide right now, so there are missing chunks, spelling issues, or sections that might not make sense at all. Please check back later, when this note is gone, you know its done πŸ˜‰

Lets get to some explanations and terms that will be used through the LoraWan articles here.

LoRaWAN Overview

LoRaWAN (Long Range Wide Area Network) is a communication protocol designed for wireless, battery-operated devices in a regional, national, or global network. It is built on top of LoRa, which is a long-range, low-power wireless platform.

Key Concepts of LoRaWAN:

  1. End Devices: These are the sensors or devices that send data to the network. They are typically battery-powered and designed for low-power operation.
  2. Gateways: These devices receive LoRa signals from the end devices and forward them to the network server via IP (Internet Protocol).
  3. Network Server: Manages the network and handles the data received from multiple gateways. It is responsible for deduplication, security, and routing the data to the appropriate application server.
  4. Application Server: Processes the data from the end devices and typically provides a user interface or API for accessing the data.

Here's a high-level overview of the LoRaWAN architecture:

graph TD A[End Devices] -->|LoRa| B[Gateways] B -->|IP| C[Network Server] C --> D[Application Server]

ChirpStack Overview

ChirpStack is an open-source LoRaWAN Network Server stack. It provides all the necessary components to set up a complete LoRaWAN network, including the Network Server, Gateway Bridge, Application Server, and more.

Components of ChirpStack:

  1. ChirpStack Gateway Bridge: Sits between the gateway and the network server. It translates the LoRa packet-forwarder protocol into a format understood by the network server.
  2. ChirpStack Network Server: Handles all the network-level tasks like managing the gateways, handling data packets, ensuring security, etc.
  3. ChirpStack Application Server: Manages the applications and devices. It handles device provisioning, data decoding, and provides APIs for integration with external systems.
  4. ChirpStack Geolocation Server: (Optional) Used for geolocating end devices based on the signal data received by multiple gateways.
  5. Database: Stores configuration, device data, and other necessary information.

Here's how the ChirpStack components interact:

graph TD A[End Devices] -->|LoRa| B[Gateways] B -->|LoRa Packet| C[ChirpStack Gateway Bridge] C -->|MQTT| D[ChirpStack Network Server] D -->|API| E[ChirpStack Application Server] D -->|API| F[ChirpStack Geolocation Server] D -->|Database| G[Database] E -->|Database| G

Detailed Interaction Flow

  1. End Devices: Send data via LoRa.
  2. Gateways: Receive the LoRa signals and forward them to the ChirpStack Gateway Bridge.
  3. ChirpStack Gateway Bridge: Converts the LoRa packets to MQTT and sends them to the Network Server.
  4. ChirpStack Network Server:
    • Handles packet deduplication.
    • Manages gateways and device sessions.
    • Ensures security by handling encryption/decryption.
    • Forwards the processed data to the Application Server.
  5. ChirpStack Application Server:
    • Manages devices and applications.
    • Decodes the data payloads.
    • Provides interfaces (APIs) for external systems to access the data.
  6. ChirpStack Geolocation Server (if used): Processes signal data to determine the location of end devices.
  7. Database: Stores all necessary data including device states, application data, and network configurations.

LoRaWAN Packets

LoRaWAN packets are structured to ensure secure and efficient communication over long distances. Each packet includes several key components:

  1. Preamble: Synchronizes the receiver with the incoming data stream.
  2. MAC Header (MHDR): Indicates the message type (join request, join accept, data).
  3. MAC Payload:
    • FHDR (Frame Header): Contains device address, control information, and frame counter.
    • FPort: Optional, indicates the application port.
    • FRMPayload: The actual data payload, encrypted if necessary.
  4. MIC (Message Integrity Code): Ensures data integrity and authenticity.

Communication Protocol

LoRaWAN communication involves three main types of messages: Join Requests, Join Accepts, and Data Messages.

1. Join Request/Accept

When a device wants to join the network, it sends a Join Request.

sequenceDiagram participant Device participant Gateway participant NetworkServer Device->>Gateway: Join Request Gateway->>NetworkServer: Forward Join Request NetworkServer->>Gateway: Join Accept Gateway->>Device: Forward Join Accept
  • Join Request: Contains the device's unique identifier and a random value.
  • Join Accept: Sent by the network server, containing network parameters and security keys.

2. Data Messages

Once joined, devices send Data Messages to transmit sensor data.

sequenceDiagram participant Device participant Gateway participant NetworkServer participant AppServer Device->>Gateway: Data Message (uplink) Gateway->>NetworkServer: Forward Data NetworkServer->>AppServer: Forward Data to Application Server AppServer->>NetworkServer: (Optional) Downlink Data NetworkServer->>Gateway: Downlink Message Gateway->>Device: Forward Downlink Message
  • Uplink (Device to Server): Devices send data messages containing sensor readings.
  • Downlink (Server to Device): The network or application server can send messages back to the device for control commands or configuration.

Packet Details

MHDR | FHDR | FPort | FRMPayload | MIC
  • MHDR: 1 byte, message type.
  • FHDR: Contains the device address, frame control, and frame counter.
  • FPort: 1 byte, optional, indicates the application layer port.
  • FRMPayload: Variable length, the actual data.
  • MIC: 4 bytes, ensures message integrity.

Security

LoRaWAN uses AES encryption to secure the payload. Each message is encrypted and includes a MIC to ensure authenticity and integrity.

By understanding these components and the flow of communication, you can grasp how LoRaWAN ensures efficient and secure data transmission over long distances.

Device Classes

LoRaWAN defines three classes of end devices to accommodate different use cases and power requirements:

Class A (Bi-directional end-devices):

    • Uplink: Devices can transmit data to the server at any time.
    • Downlink: The server can only send data to the device immediately after an uplink transmission.
    • Power Consumption: Lowest, ideal for battery-powered sensors.
sequenceDiagram participant Device participant Gateway participant Server Device->>Gateway: Uplink Data Gateway->>Server: Forward Data Server->>Gateway: Immediate Downlink Response Gateway->>Device: Forward Downlink

Class B (Bi-directional end-devices with scheduled receive slots):

  • Uplink: Same as Class A.
  • Downlink: The server can send messages at scheduled times synchronized with the device’s beacon.
  • Power Consumption: Higher than Class A, suitable for devices that need more frequent communication.
sequenceDiagram participant Device participant Gateway participant Server Device->>Gateway: Uplink Data Gateway->>Server: Forward Data Server->>Gateway: Scheduled Downlink Gateway->>Device: Forward Downlink at Scheduled Time

Class C (Bi-directional end-devices with maximal receive slots):

  • Uplink: Same as Class A.
  • Downlink: The server can send messages to the device at any time as the device continuously listens when not transmitting.
  • Power Consumption: Highest, suitable for mains-powered devices.
sequenceDiagram participant Device participant Gateway participant Server Device->>Gateway: Uplink Data Gateway->>Server: Forward Data Server->>Gateway: Any-time Downlink Gateway->>Device: Forward Downlink

Adaptive Data Rate (ADR)

Adaptive Data Rate (ADR) is a mechanism to optimize the data rate, airtime, and energy consumption of end devices:

  • Dynamic Adjustment: The network server can adjust the data rate and transmission power based on the network conditions and device's location.
  • Benefits: Helps in improving network capacity and battery life of the devices.

Frequency Bands

LoRaWAN operates in different frequency bands depending on the region:

  • Europe: 868 MHz
  • North America: 915 MHz
  • Asia: Various sub-GHz frequencies

Each region has specific regulations on duty cycle, power limits, and channel frequencies.

Security Mechanisms

LoRaWAN implements several security mechanisms:

  1. AES-128 Encryption: Ensures data confidentiality.
  2. Message Integrity Code (MIC): Validates the authenticity and integrity of messages.
  3. Network and Application Keys: Separates network and application layer security to enhance overall security.

Network Architecture and Scalability

LoRaWAN supports scalable network architecture:

  • Star-of-stars topology: Gateways act as transparent bridges relaying messages between end devices and the central network server.
  • Scalability: Can support millions of devices by utilizing multiple gateways and efficient use of spectrum.

Use Cases

LoRaWAN is used in various applications due to its long-range and low-power capabilities:

  1. Smart Agriculture: Soil moisture sensors, weather stations.
  2. Smart Cities: Parking sensors, waste management, street lighting.
  3. Industrial IoT: Asset tracking, predictive maintenance.
  4. Environmental Monitoring: Air quality sensors, flood detection.