Building a LoRaWAN gateway for India and connecting it to The Things Network (TTN) is one of the most impactful IoT projects you can undertake. A single gateway can cover 5-15 km in rural areas, enabling hundreds of sensors to send data to the cloud without WiFi or cellular connectivity. This guide walks you through building a TTN-compatible LoRaWAN gateway using a Raspberry Pi, configuring it for the IN865 frequency plan, and expanding IoT coverage across India.
Table of Contents
- What is LoRaWAN and TTN?
- Gateway Architecture: How It Works
- Hardware Selection for India
- Raspberry Pi Gateway Setup
- Registering on The Things Network
- Building Your First LoRaWAN Node
- Antenna Placement for Maximum Range
- Frequently Asked Questions
What is LoRaWAN and TTN?
LoRaWAN (Long Range Wide Area Network) is a network protocol built on top of LoRa physical layer. While LoRa handles the radio modulation, LoRaWAN adds device addressing, security (AES-128 encryption), adaptive data rate, and multi-gateway support. Think of LoRa as the radio and LoRaWAN as the complete networking stack.
The Things Network (TTN) is a free, community-driven LoRaWAN network server. When you set up a gateway and connect it to TTN, your sensor nodes can send data to the cloud through the TTN infrastructure at zero cost. TTN handles device management, data routing, and integration with platforms like MQTT, HTTP webhooks, and cloud services.
The key components of a LoRaWAN network are:
- End Devices (Nodes): Sensors with LoRa radios that collect and transmit data
- Gateways: Receive LoRa packets and forward them to the network server over the internet
- Network Server (TTN): Manages devices, deduplicates data, handles security
- Application Server: Your backend that processes and visualises the sensor data
Gateway Architecture: How It Works
A LoRaWAN gateway is fundamentally a bridge between the LoRa radio world and the internet. It listens on multiple LoRa channels simultaneously and forwards all received packets to TTN’s network server. Unlike point-to-point LoRa, the gateway does not need to know which devices are transmitting — it simply captures everything and lets the network server sort it out.
A single-channel gateway (using one SX1278 module) can only listen on one frequency at a time. A proper 8-channel gateway (using a SX1301/SX1302 concentrator) can listen on 8 frequencies simultaneously, which is the TTN-recommended minimum for reliable operation.
For India (IN865 band):
- Default channels: 865.0625 MHz, 865.4025 MHz, 865.985 MHz
- Additional channels configurable between 865-867 MHz
- An 8-channel gateway covers all default channels plus 5 custom channels
Hardware Selection for India
Option 1: Single-Channel Packet Forwarder (Budget: ₹3,000-5,000)
A Raspberry Pi with a single LoRa module. Affordable but can only listen on one channel at a time. Suitable for learning, testing, and small private networks.
- Raspberry Pi 4 (4GB recommended)
- Waveshare SX1262 LoRa HAT (868 MHz band)
- External antenna with SMA connector
- 5V 3A USB-C power supply
- MicroSD card (32GB+)
Option 2: 8-Channel Concentrator Gateway (Budget: ₹15,000-30,000)
Uses a RAK2245/RAK2287 concentrator module with SX1302 chip. This is the recommended configuration for TTN community gateways and commercial deployments.
Antenna Selection
The antenna is the most important factor in gateway range. Options for Indian deployments:
- Small whip antenna (3 dBi): Included with most modules. Range: 1-3 km. Good for indoor testing.
- Fibreglass omnidirectional (5-8 dBi): Outdoor-rated. Range: 5-10 km. Best for rooftop mounting.
- High-gain omnidirectional (10-12 dBi): Range: 10-15+ km. Requires proper mast mounting.
Raspberry Pi Gateway Setup
Here is how to set up a single-channel packet forwarder on a Raspberry Pi with the Waveshare SX1262 LoRa HAT:
Step 1: Install Raspberry Pi OS
# Flash Raspberry Pi OS Lite (64-bit) to SD card
# Enable SSH: create empty file named 'ssh' in boot partition
# Configure WiFi: create wpa_supplicant.conf in boot partition
Step 2: Enable SPI Interface
sudo raspi-config
# Navigate to: Interface Options → SPI → Enable
# Reboot after enabling
Step 3: Install Dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3-pip python3-spidev git
pip3 install RPi.GPIO spidev
Step 4: Configure Packet Forwarder
# Clone the single-channel packet forwarder
git clone https://github.com/tftelkamp/single_chan_pkt_fwd.git
cd single_chan_pkt_fwd
# Edit main.cpp - set frequency for IN865
# Change freq to 865062500 (865.0625 MHz)
# Set server to the nearest TTN router:
# router.in1.thethings.network
make
sudo ./single_chan_pkt_fwd
Step 5: Create System Service
# /etc/systemd/system/lora-gateway.service
[Unit]
Description=LoRa Single Channel Gateway
After=network.target
[Service]
ExecStart=/home/pi/single_chan_pkt_fwd/single_chan_pkt_fwd
WorkingDirectory=/home/pi/single_chan_pkt_fwd
Restart=always
User=root
[Install]
WantedBy=multi-user.target
sudo systemctl enable lora-gateway
sudo systemctl start lora-gateway
Registering on The Things Network
- Create an account at console.thethingsnetwork.org
- Click Gateways → Register Gateway
- Enter your Gateway EUI (8-byte unique identifier — use the Pi’s Ethernet MAC address with FFFE inserted in the middle)
- Select frequency plan: India 865-867 MHz (IN865)
- Set the gateway location on the map for coverage visualisation
- Note down the Gateway Key for authentication
After registration, your gateway should appear as “Connected” on the TTN console within a few minutes. You can monitor incoming packets, signal strength, and uptime from the dashboard.
Building Your First LoRaWAN Node
With the gateway running, build a simple LoRaWAN sensor node using an Arduino and LoRa module:
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
// TTN device credentials (OTAA)
static const u1_t PROGMEM APPEUI[8] = { /* from TTN console */ };
void os_getArtEui(u1_t* buf) { memcpy_P(buf, APPEUI, 8); }
static const u1_t PROGMEM DEVEUI[8] = { /* from TTN console */ };
void os_getDevEui(u1_t* buf) { memcpy_P(buf, DEVEUI, 8); }
static const u1_t PROGMEM APPKEY[16] = { /* from TTN console */ };
void os_getDevKey(u1_t* buf) { memcpy_P(buf, APPKEY, 16); }
static uint8_t payload[4];
static osjob_t sendjob;
const unsigned TX_INTERVAL = 300; // Send every 5 minutes
// Pin mapping for SX1278
const lmic_pinmap lmic_pins = {
.nss = 10,
.rxtx = LMIC_UNUSED_PIN,
.rst = 9,
.dio = {2, 6, 7},
};
void do_send(osjob_t* j) {
if (LMIC.opmode & OP_TXRXPEND) return;
// Read temperature sensor (LM35 on A0)
int rawTemp = analogRead(A0);
int temperature = (rawTemp * 500) / 1024; // Celsius x10
// Read humidity (analog sensor on A1)
int humidity = map(analogRead(A1), 0, 1023, 0, 100);
// Pack into payload (2 bytes each)
payload[0] = highByte(temperature);
payload[1] = lowByte(temperature);
payload[2] = highByte(humidity);
payload[3] = lowByte(humidity);
LMIC_setTxData2(1, payload, sizeof(payload), 0);
}
void onEvent(ev_t ev) {
switch (ev) {
case EV_JOINED:
LMIC_setLinkCheckMode(0);
break;
case EV_TXCOMPLETE:
os_setTimedCallback(&sendjob, os_getTime() +
sec2osticks(TX_INTERVAL), do_send);
break;
}
}
void setup() {
Serial.begin(9600);
os_init();
LMIC_reset();
// Set IN865 channels
LMIC_setupChannel(0, 865062500, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI);
LMIC_setupChannel(1, 865402500, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI);
LMIC_setupChannel(2, 865985000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_MILLI);
LMIC_setLinkCheckMode(0);
LMIC.dn2Dr = DR_SF9;
LMIC_setDrTxpow(DR_SF7, 14);
do_send(&sendjob);
}
void loop() {
os_runloop_once();
}
Register this device on TTN console under Applications → Add Device. Use OTAA (Over-The-Air Activation) for better security. The device will automatically join the network through your gateway.
Antenna Placement for Maximum Range
The antenna is the single most important factor in gateway coverage. Here are tips specifically for Indian rooftop installations:
- Height is everything: Every 1 metre of additional height adds roughly 1 km of range. Mount the antenna on a rooftop mast, water tank support, or the highest point of your building.
- Clear line of sight: The 865 MHz signal can penetrate walls and trees but is significantly attenuated. For best range, ensure the antenna has an unobstructed 360-degree view of the horizon.
- Lightning protection: India’s monsoon season brings heavy lightning. Install a lightning arrestor on the antenna cable and ground the mast properly. A direct lightning strike will destroy the gateway.
- Weatherproofing: Use IP67-rated enclosures for the Raspberry Pi and LoRa HAT. Seal all cable entry points with silicone. Indian monsoons will find every gap.
- Cable length: Keep the coaxial cable between antenna and gateway as short as possible. Every 10 metres of RG-58 cable at 868 MHz loses about 3 dB (half the signal power).
Frequently Asked Questions
Is The Things Network free to use in India?
Yes. TTN is completely free for community use. There is a Fair Use Policy that limits each device to 30 seconds of airtime per day (approximately 10-20 uplinks depending on spreading factor). For commercial use with higher throughput, consider The Things Industries (paid) or ChirpStack (self-hosted, free).
How many devices can my gateway support?
An 8-channel gateway can theoretically support thousands of devices. Practically, with sensors reporting every 15 minutes at SF7, a single gateway handles 500-2000 nodes. A single-channel gateway is limited to about 50-100 nodes.
What frequency plan should I use in India?
Use IN865-867 for all LoRaWAN deployments in India. This is the only official LoRaWAN frequency plan approved by the Indian DoT. Do not use EU868 or US915 plans even if they seem similar.
Can I see my gateway on the TTN map?
Yes. After registration, your gateway appears on the TTN global coverage map at ttnmapper.org. This helps the community see LoRaWAN coverage across India. Currently, cities like Bangalore, Pune, Hyderabad, and Delhi have the most community gateways.
Do I need internet connectivity for the gateway?
Yes. The gateway needs a reliable internet connection (WiFi or Ethernet) to forward packets to the TTN server. The bandwidth requirement is minimal — even a slow 256 kbps connection is sufficient for hundreds of sensor nodes.
Conclusion
Building a LoRaWAN gateway and connecting it to The Things Network is a powerful way to enable IoT coverage in your area. Whether you are a student expanding TTN coverage on your college campus, a farmer deploying sensors across fields, or a startup building an IoT product, the gateway is the foundation of your LoRaWAN network. Start with a single-channel Raspberry Pi gateway for learning, and upgrade to an 8-channel concentrator for production use.
Get started with LoRaWAN in India today. Browse our complete collection of LoRa modules, HATs, and antennas at Zbotic.in for everything you need to build your gateway and sensor nodes.
Add comment