Back to IoT Blog
Protocols 20 min read

LoRaWAN Network Setup Guide

Build your own LoRaWAN network from scratch. Learn gateway setup, network server configuration, and node integration for long-range IoT applications.

What is LoRaWAN?

LoRaWAN (Long Range Wide Area Network) is a low-power, wide-area networking protocol designed for wireless battery-operated devices. It enables long-range communication (up to 10km rural, 2-5km urban) with minimal power consumption.

Why LoRaWAN?
  • Long range: 10+ km in rural areas
  • Low power: Battery life of 5-10 years
  • Low cost: Inexpensive hardware and no licensing fees
  • Secure: End-to-end AES-128 encryption
  • Scalable: Millions of messages per gateway

Network Architecture

A typical LoRaWAN network consists of four main components:

1. End Devices (Nodes)

Sensors and actuators that collect data and transmit via LoRa. Examples include temperature sensors, soil moisture sensors, and GPS trackers.

2. Gateways

Receive LoRa messages from end devices and forward them to the network server via backhaul (Ethernet, WiFi, or cellular).

3. Network Server

Manages the network, handles security, deduplication, and routing. Popular options include ChirpStack, The Things Network, and Lorawan-server.

4. Application Server

Processes the actual application data and provides user interfaces or APIs.

Gateway Setup

Setting up a LoRaWAN gateway involves hardware assembly and software configuration.

Hardware Requirements

Software Installation

Using ChirpStack Gateway Bridge:

# Install dependencies
sudo apt-get update
sudo apt-get install -y git build-essential

# Clone ChirpStack repository
git clone https://github.com/chirpstack/chirpstack-gateway-bridge.git
cd chirpstack-gateway-bridge

# Configure for your region
sudo nano /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml
Regional Frequency Plans:
  • EU868: Europe (868 MHz)
  • US915: North America (915 MHz)
  • AU915: Australia (921 MHz)
  • AS923: Asia (923 MHz)

Network Server Configuration

ChirpStack is a popular open-source LoRaWAN network server.

Docker Installation

# Create docker-compose.yml
version: '3'
services:
  chirpstack:
    image: chirpstack/chirpstack:4
    command: -c /etc/chirpstack
    ports:
      - "8080:8080"
    volumes:
      - ./chirpstack:/etc/chirpstack
    depends_on:
      - postgresql
      - redis
  
  postgresql:
    image: postgres:14-alpine
  
  redis:
    image: redis:7-alpine

Creating Application and Devices

  1. Access web interface at http://localhost:8080
  2. Login with default credentials (admin/admin)
  3. Create Organization → Application → Device Profile
  4. Add end devices with their DevEUI and AppKey

Node Integration

Configuring an Arduino-based LoRa node:

#include <LoRaWan.h>

// Device credentials
static const char *DEV_EUI = "YOUR_DEV_EUI";
static const char *APP_EUI = "YOUR_APP_EUI";
static const char *APP_KEY = "YOUR_APP_KEY";

void setup() {
  Serial.begin(115200);
  LoRa.begin();
  
  // Join network (OTAA)
  LoRa.joinOTAA(APP_EUI, APP_KEY, DEV_EUI);
  delay(5000);
}

void loop() {
  if (LoRa.joined()) {
    // Send sensor data
    float temperature = readTemperature();
    LoRa.sendUplink(&temperature, sizeof(temperature), 0, 1);
  }
  delay(60000); // Send every minute
}
Security Best Practices:
  • Never hardcode keys in production firmware
  • Use secure element chips for key storage
  • Enable frame counter validation
  • Rotate keys periodically

Troubleshooting

Common Issues

Device Not Joining Network

Packets Not Received

Poor Signal Quality

Next Steps

Expand your LoRaWAN network with these projects:

  • Deploy outdoor gateway with proper enclosure
  • Build solar-powered sensor nodes
  • Integrate with cloud platforms (AWS IoT, Azure IoT)
  • Create custom dashboard for data visualization
  • Join The Things Network community