LoRa (Long Range) radio technology enables IoT sensors to communicate over distances of 2–15 km on battery power that lasts for years. A Raspberry Pi with a LoRa HAT can act as a full LoRaWAN gateway, bridging dozens of remote sensor nodes to the internet via TheThingsNetwork (TTN) or a private MQTT broker. This tutorial shows you how to build, configure, and deploy a production-quality LoRa IoT gateway from scratch.
Whether you are monitoring soil moisture across a farm, tracking assets in a warehouse, or collecting environmental data from a remote station, a Pi-based LoRa gateway gives you wide-area wireless coverage at a fraction of the cost of cellular IoT.
LoRa vs LoRaWAN Explained
These terms are often confused, but they refer to different layers of the technology stack:
- LoRa — The physical radio modulation technique (Chirp Spread Spectrum). Developed by Semtech. Enables long-range, low-power communication. LoRa operates in ISM bands (865–867 MHz in India).
- LoRaWAN — The MAC-layer protocol built on top of LoRa. Defines how end nodes join a network, how uplink/downlink messages are formatted, and how gateways connect to a Network Server (like TTN).
- Gateway — A device that receives LoRa radio packets from end nodes and forwards them to the Network Server over the internet (Ethernet or Wi-Fi). One gateway can serve hundreds of end nodes simultaneously.
- End Node — A small, battery-powered sensor device that periodically transmits LoRa packets. Examples: a soil moisture sensor, a GPS tracker, a temperature logger.
In India, LoRa operates in the 865–867 MHz band (IN865 plan). Make sure your hardware and software configuration uses these frequencies to comply with WPC regulations.
Gateway Hardware Setup
You need three things for the gateway: a Raspberry Pi, a LoRa concentrator HAT, and an antenna.
Recommended Gateway Hardware
- Raspberry Pi 4B or Pi 5 — the gateway software is lightweight; even 2 GB RAM is sufficient
- RAK2245 Pi HAT or Dragino PG1301 — 8-channel SX1301/SX1303-based concentrators
- 868 MHz/865 MHz antenna — fiberglass omnidirectional, 3 dBi minimum
- Pigtail SMA connector — to connect HAT u.FL to external antenna
- Weatherproof enclosure — for outdoor deployment
The concentrator chip (SX1301 or SX1303) is what distinguishes a real gateway from a single-channel “gateway” — it can listen on 8 channels simultaneously, dramatically increasing capacity and reliability.
Assembly
- Stack the LoRa HAT on the Pi’s 40-pin GPIO header
- Connect the antenna via pigtail to the HAT’s u.FL connector
- Never power on without antenna connected — the RF amplifier can be damaged by the reflected power
- Flash Raspberry Pi OS Lite (64-bit) for minimal overhead
Installing the LoRa Packet Forwarder
The packet forwarder is the software that reads LoRa packets from the concentrator chip and forwards them to a Network Server over UDP. We’ll use the Semtech UDP Packet Forwarder, the de facto standard for LoRaWAN gateways.
Enable SPI
sudo raspi-config
# Interface Options → SPI → Enable
sudo reboot
Install Dependencies
sudo apt update
sudo apt install -y git build-essential libssl-dev
Clone and Build the Packet Forwarder
# Clone RAK's modified forwarder for Pi HAT
git clone https://github.com/RAKWireless/RAK2245-RAK831-LoRaGateway-RPi-Raspbian-OS.git
cd RAK2245-RAK831-LoRaGateway-RPi-Raspbian-OS
sudo chmod +x install.sh
sudo ./install.sh
For other concentrators, use the appropriate chipset-specific forwarder. The SX1303-based boards use the newer sx1302_hal library:
git clone https://github.com/Lora-net/sx1302_hal.git
cd sx1302_hal
make
Configure global_conf.json
The gateway configuration file lives at /opt/ttn-gateway/packet_forwarder/lora_pkt_fwd/global_conf.json. Set the correct frequency plan and your TTN server address:
{
"SX1301_conf": {
"lorawan_public": true,
"clksrc": 1,
"chan_multiSF_0": {"enable": true, "radio": 0, "if": -400000},
"chan_multiSF_1": {"enable": true, "radio": 0, "if": -200000},
"chan_multiSF_2": {"enable": true, "radio": 0, "if": 0},
"chan_multiSF_3": {"enable": true, "radio": 0, "if": 200000},
"chan_multiSF_4": {"enable": true, "radio": 1, "if": -300000},
"chan_multiSF_5": {"enable": true, "radio": 1, "if": -100000},
"chan_multiSF_6": {"enable": true, "radio": 1, "if": 100000},
"chan_multiSF_7": {"enable": true, "radio": 1, "if": 300000}
},
"gateway_conf": {
"gateway_ID": "AA555A0000000000",
"server_address": "au1.cloud.thethings.network",
"serv_port_up": 1700,
"serv_port_down": 1700,
"keepalive_interval": 10,
"stat_interval": 30,
"push_timeout_ms": 100,
"forward_crc_valid": true,
"forward_crc_error": false,
"forward_crc_disabled": false
}
}
Replace gateway_ID with your gateway’s EUI (derived from Ethernet MAC: ip link show eth0 | awk '/ether/{print $2}' | sed 's/://g' → insert FFFE at position 6).
For India, set radio frequencies to IN865: radio_0 at 865.0625 MHz, radio_1 at 865.9625 MHz.
Registering on TheThingsNetwork
TheThingsNetwork (TTN) V3 (now called The Things Stack) is the most popular free LoRaWAN network server.
- Sign up at thethingsnetwork.org
- Go to Console → Gateways → Register Gateway
- Enter your Gateway EUI (same as
gateway_IDin config) - Select frequency plan: India 865-867 MHz (IN865)
- Select cluster: au1.cloud.thethings.network (closest to India)
- Click Register Gateway
Once the packet forwarder is running, your gateway appears as Connected (green dot) in the TTN console within 30 seconds.
Setting Up LoRa End Nodes
An end node is a microcontroller + LoRa module combination that periodically sends sensor readings. Popular choices in India:
- Arduino Nano + RFM95W module — affordable, uses LMIC library
- STM32WL (Nucleo-WL55JC) — built-in LoRa transceiver, ultra-low-power
- Heltec WiFi LoRa 32 V3 — ESP32 + LoRa, Arduino IDE compatible
- RAK4631 — nRF52840 + LoRa, excellent power management
OTAA Join (Over-the-Air Activation)
In TTN console, go to Applications → Add Application → Add End Device. Select your device type and note the DevEUI, AppEUI, and AppKey. Enter these in your Arduino sketch:
// LMIC library sketch for IN865
#include
#include
#include
static const u1_t PROGMEM APPEUI[8] = { /* LSB first */ };
static const u1_t PROGMEM DEVEUI[8] = { /* LSB first */ };
static const u1_t PROGMEM APPKEY[16] = { /* MSB first */ };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8); }
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8); }
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16); }
Once joined, the node sends temperature/humidity readings uplink every 10 minutes — ideal for battery-powered deployments where Class A LoRaWAN’s 1–10 µA sleep current extends battery life to years.
Sensor Data Pipeline: MQTT to Dashboard
TTN delivers decoded payload data to your application via MQTT, webhooks, or direct API. The MQTT integration is the most flexible for custom dashboards.
TTN MQTT Setup
# Install Mosquitto MQTT client
sudo apt install -y mosquitto-clients
# Subscribe to all uplink messages from your application
mosquitto_sub
-h au1.cloud.thethings.network
-p 8883
--capath /etc/ssl/certs/
-u "YOUR-APP-ID@ttn"
-P "YOUR-API-KEY"
-t "v3/YOUR-APP-ID@ttn/devices/+/up"
Node-RED Dashboard
Install Node-RED on the Pi for a visual dashboard with zero frontend code:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
sudo systemctl enable nodered.service
sudo systemctl start nodered.service
In Node-RED, use the node-red-contrib-ttn package to connect directly to TTN and visualise sensor data on a dashboard — temperature graphs, humidity gauges, GPS map for trackers.
InfluxDB + Grafana (Production Stack)
For a production installation with historical data retention and professional charts:
# Install InfluxDB 2.x
curl https://repos.influxdata.com/influxdata-archive.key | gpg --dearmor > /etc/apt/trusted.gpg.d/influxdata.gpg
echo 'deb https://repos.influxdata.com/debian stable main' > /etc/apt/sources.list.d/influxdata.list
sudo apt update && sudo apt install influxdb2
# Grafana
sudo apt install -y grafana
sudo systemctl enable grafana-server && sudo systemctl start grafana-server
Range Optimisation and Antenna Tips
LoRa range is dramatically affected by antenna placement, obstacles, and spreading factor (SF) settings.
Spreading Factor vs Data Rate Trade-off
| SF | Data Rate | Range | Time on Air |
|---|---|---|---|
| SF7 | 5.5 kbps | ~2 km urban | 56 ms (10B) |
| SF9 | 1.37 kbps | ~5 km | 226 ms |
| SF12 | 0.25 kbps | ~15 km rural | 1.98 s |
Use Adaptive Data Rate (ADR) in TTN — the network automatically selects the optimal SF for each end node based on observed SNR.
Gateway Placement
- Mount the gateway as high as possible — rooftop mounting increases range 3–5×
- Use a quality N-type fiberglass antenna (3–6 dBi gain)
- Keep coaxial cable runs short — every 3 dB of cable loss halves effective range
- Avoid metal enclosures around the antenna
Frequently Asked Questions
Is LoRa legal to use in India?
Yes. LoRa operates in the 865–867 MHz ISM band in India, which is unlicensed for short-range devices under WPC (Wireless Planning and Coordination Wing) regulations. No license is needed for personal or commercial IoT deployments using compliant hardware at the allowed power levels (up to 1W ERP).
How many end nodes can one Raspberry Pi gateway support?
An 8-channel LoRaWAN gateway can theoretically handle thousands of end nodes, since each transmission is very short (56 ms to 2 s). In practice, capacity depends on how frequently nodes transmit. With Class A nodes sending every 10 minutes, a single gateway comfortably supports 500–1000 devices. TTN also enforces a 1% duty cycle per node, which naturally limits channel congestion.
What is the maximum range achievable with a Pi LoRa gateway?
In line-of-sight rural conditions with a good rooftop antenna, 10–15 km is achievable at SF12. In urban India, expect 1–3 km due to buildings and interference. The world record for LoRa range (using a balloon) is over 700 km, demonstrating the technology’s theoretical ceiling under ideal conditions.
Can I build a private LoRaWAN network without TheThingsNetwork?
Yes. ChirpStack is an open-source LoRaWAN Network Server that runs entirely on-premise. Install it on the same Pi as the packet forwarder (for small deployments) or on a dedicated server. ChirpStack gives you full control over data routing, device management, and integrations, with no dependency on TTN’s cloud infrastructure.
How long does a battery-powered LoRa end node last?
A properly configured Class A node (sleep between transmissions) with two AA batteries can last 2–5 years sending one packet every 15 minutes at SF9. The key is minimising radio-on time and using a microcontroller with deep sleep (like STM32WL or SAMD21 with sleep current under 5 µA).
Ready to build your IoT network? Zbotic.in stocks Raspberry Pi boards, sensors, and accessories to get your LoRa gateway project off the ground. Explore the full Raspberry Pi and IoT collection at Zbotic.in.
Add comment