Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home IoT & Smart Home

ESP32 LoRa Gateway: Packet Forwarding to The Things Network

ESP32 LoRa Gateway: Packet Forwarding to The Things Network

March 11, 2026 /Posted byJayesh Jain / 0

Building an ESP32 LoRa gateway packet forwarding TTN solution is the bridge between low-power field sensors and the internet. LoRa (Long Range) radio technology can carry sensor data over 5-15 km in open terrain, making it ideal for Indian agricultural applications, smart city deployments, and remote industrial monitoring. The Things Network (TTN) is a global, community-driven LoRaWAN network server that is free to use. In this tutorial, you’ll learn how to build a working LoRa gateway using an ESP32 and a LoRa radio module that forwards received packets to TTN over the internet.

Table of Contents

  1. LoRa vs LoRaWAN: Understanding the Difference
  2. Hardware Requirements
  3. Setting Up The Things Network Console
  4. Wiring the ESP32 and LoRa Module
  5. Gateway Firmware: Single-Channel Packet Forwarder
  6. Setting Up an End Device Node
  7. Real-World Applications in India
  8. Frequently Asked Questions

LoRa vs LoRaWAN: Understanding the Difference

LoRa and LoRaWAN are related but distinct technologies. Understanding this distinction is crucial before building your gateway.

LoRa (Long Range) is the physical radio modulation technique developed by Semtech. It uses Chirp Spread Spectrum (CSS) modulation to achieve extraordinary range and obstacle penetration at very low data rates (250 bps to 50 kbps). LoRa defines how bits are transmitted over the air — it’s the physical (PHY) layer.

LoRaWAN is the network protocol built on top of LoRa. It defines how devices are authenticated, how data is routed through gateways to a network server, how encryption works, and how acknowledgements are handled. The Things Network is a LoRaWAN network server.

An ESP32 with a LoRa module can act as a single-channel gateway — it listens on one frequency and one spreading factor and forwards received packets to TTN. This is simpler than a full multi-channel gateway (which requires 8-channel hardware like the RAK7258) but is excellent for learning and for covering a small area with your own end devices.

Important note: TTN’s fair use policy limits each application to 30 seconds of downlink airtime per day and 10 messages per device per day. For commercial deployments in India, consider TTN Cloud (paid) or a private network server like ChirpStack.

Hardware Requirements

For this project you need:

  • ESP32 development board (any standard board works)
  • SX1276 or SX1278 LoRa module (Ra-02 is the most common in India)
  • Antenna appropriate for your frequency band (865-867 MHz for India)
  • Jumper wires and breadboard
  • Stable internet connection (wired Ethernet via an Ethernet shield is preferred for gateways)

India uses the IN865 frequency plan for LoRaWAN, which operates in the 865-867 MHz band. Make sure your LoRa module and antenna are rated for this band. The Ra-02 module (based on SX1278) is rated for 433 MHz and can also operate at 868 MHz. For Indian deployments, configure the frequency to 865.0625 MHz, 865.4025 MHz, or 865.9850 MHz — the three channels defined in the IN865 plan.

Ai Thinker NodeMCU-32S ESP32 Development Board

Ai Thinker NodeMCU-32S-ESP32 Development Board – IPEX Version

This ESP32 board with IPEX antenna connector provides excellent WiFi range for reliable gateway connectivity — perfect for remote LoRa gateway deployments.

View on Zbotic

Setting Up The Things Network Console

Before writing any code, register your gateway on TTN. Here’s the process:

Step 1: Create a TTN Account

Go to thethingsnetwork.org and create a free account. During registration, select your region. For India, choose the Community Edition under the eu1, au1, or nam1 cluster — TTN does not yet have a dedicated Indian cluster, but au1 (Australia) typically provides the lowest latency from India.

Step 2: Register the Gateway

In the TTN console, go to Gateways → Register Gateway. You need to provide:

  • Gateway EUI: An 8-byte unique identifier. Use your ESP32’s MAC address with FF:FE inserted in the middle to create a proper EUI-64. Example: if MAC is 24:6F:28:AA:BB:CC, the EUI is 24:6F:28:FF:FE:AA:BB:CC.
  • Frequency Plan: Select India 865-867 MHz (IN865).
  • Gateway Server Address: This will be shown after registration.

Step 3: Note the Gateway Credentials

After registration, TTN generates the gateway server address. For the au1 cluster, it is typically au1.cloud.thethings.network. Note this down — you’ll need it in the firmware.

Wiring the ESP32 and LoRa Module

The LoRa Ra-02 module communicates with the ESP32 via SPI. Connect the pins as follows:

LoRa Ra-02 Pin ESP32 Pin Notes
3.3V 3.3V Do NOT use 5V — will damage the module
GND GND Common ground
SCK GPIO18 SPI clock
MISO GPIO19 SPI MISO
MOSI GPIO23 SPI MOSI
NSS (CS) GPIO5 Chip select
RESET GPIO14 LoRa reset pin
DIO0 GPIO26 Interrupt for RX done

Always connect an antenna before powering the LoRa module. Transmitting without an antenna can damage the SX1278 chip. For indoor testing, even a 17.3 cm wire antenna cut for 865 MHz works. For outdoor deployments, use a proper 865 MHz omni-directional antenna.

Gateway Firmware: Single-Channel Packet Forwarder

The single-channel packet forwarder (SCPF) is a well-established open-source firmware for ESP32-based LoRa gateways. The most popular implementation is by Thomas Telkamp and Matthijs Kooijman, with ESP32 adaptations available on GitHub.

The key configuration parameters you need to set:

// WiFi credentials
#define SSID "YOUR_WIFI_SSID"
#define PASS "YOUR_WIFI_PASSWORD"

// TTN Gateway server
#define SERVER "au1.cloud.thethings.network"
#define PORT 1700

// Gateway EUI (your ESP32 MAC with FFFE inserted)
uint8_t GatewayEUI[] = { 0x24, 0x6F, 0x28, 0xFF, 0xFE, 0xAA, 0xBB, 0xCC };

// LoRa frequency for India (IN865 channel 1)
#define FREQ 865062500  // 865.0625 MHz in Hz

// Spreading factor (SF7 = fastest, SF12 = longest range)
#define SF_CHECK SF7

// LoRa module SPI pins
#define SCK  18
#define MISO 19
#define MOSI 23
#define SS   5
#define RST  14
#define DI0  26

The SCPF listens on one frequency and spreading factor. When a LoRa packet is received, it wraps the payload in the UDP Semtech packet forwarder protocol and sends it to the TTN server over UDP. TTN then routes the data to the appropriate application based on the device EUI in the packet header.

The firmware handles NTP time synchronization (required by TTN for packet timestamps), LED status indication, and automatic reconnection to WiFi if the connection drops. Download the complete firmware from the GitHub repository and configure the settings file before compiling.

18650 Battery Shield V8

2 x 18650 Lithium Battery Shield V8 – 5V/3A for ESP32

Deploy your ESP32 LoRa gateway in locations without wall power — this battery shield provides hours of reliable operation from two 18650 cells.

View on Zbotic

Setting Up an End Device Node

Your gateway needs at least one end device (sensor node) to forward packets for. The end device is a second ESP32 (or Arduino) with a LoRa module that sends sensor data. Here is a minimal end device sketch using the LMIC library:

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>

// Device credentials from TTN console (ABP activation)
static const PROGMEM u1_t NWKSKEY[16] = { /* Network Session Key */ };
static const PROGMEM u1_t APPSKEY[16] = { /* App Session Key */ };
static const u4_t DEVADDR = 0x260BXXXX; // Device address from TTN

const lmic_pinmap lmic_pins = {
  .nss = 5,
  .rxtx = LMIC_UNUSED_PIN,
  .rst = 14,
  .dio = {26, 25, LMIC_UNUSED_PIN}
};

void do_send(osjob_t* j) {
  if (LMIC.opmode & OP_TXRXPEND) return;
  uint8_t payload[2];
  float temp = 28.5; // Replace with actual sensor reading
  int16_t t = (int16_t)(temp * 10);
  payload[0] = t >> 8;
  payload[1] = t & 0xFF;
  LMIC_setTxData2(1, payload, sizeof(payload), 0);
}

Register this device in TTN under Applications → Add Application → Add End Device. Use ABP (Activation By Personalisation) for simplicity, which gives you the Device Address, Network Session Key, and Application Session Key directly without an OTAA join procedure.

Real-World Applications in India

The ESP32 LoRa gateway + TTN combination is being used across India for innovative projects:

Precision Agriculture

Farmers in Maharashtra and Punjab use LoRa sensor nodes measuring soil moisture, temperature, and pH across large fields. A single gateway on a water tower or elevated building can cover an entire 100-acre farm. Data flows to TTN and then to a farmer’s smartphone app, enabling irrigation decisions based on real data rather than guesswork.

Smart City Waste Management

Municipal corporations in cities like Surat and Bengaluru are piloting LoRa-based bin fill level sensors. Each dustbin has an ultrasonic sensor and a LoRa node. The gateway forwards fill-level data to TTN, and a dashboard routes garbage collection trucks only to full bins, reducing fuel consumption by 30-40%.

Water Level Monitoring

With India’s monsoon floods affecting millions annually, LoRa-based water level sensors on rivers and reservoirs provide early warning. The gateway at a local utility office forwards readings to TTN, which triggers SMS alerts through a connected service when water levels reach danger thresholds.

JSN-SR04T Waterproof Ultrasonic Rangefinder Module

A86 JSN-SR04T Waterproof Ultrasonic Rangefinder Module Version 3.0

A weatherproof ultrasonic sensor for water level or distance measurement — perfect for LoRa end devices deployed outdoors in Indian weather conditions.

View on Zbotic

Frequently Asked Questions

Is LoRa legal to use in India?

Yes. The WPC (Wireless Planning and Coordination Wing) under India’s Department of Telecommunications has allocated the 865-867 MHz band for short range devices without a license, subject to a maximum transmit power of 1 Watt ERP and a duty cycle limit. LoRaWAN end devices typically transmit at 14-20 dBm (25-100 mW), well within this limit. Commercial LoRaWAN network operators still require WPC authorization for their gateway infrastructure, but individual experimenter use falls under the de-licensed category.

How far can a single-channel ESP32 gateway reach?

In open terrain with a proper rooftop antenna, an ESP32 SCPF gateway can receive LoRa packets from 3-8 km away. In dense urban areas with buildings, the range drops to 500 metres to 2 km. Using a higher gain directional antenna or installing the gateway at an elevated location significantly improves coverage.

Can the ESP32 gateway handle multiple end devices simultaneously?

A single-channel gateway can receive one packet at a time. If two end devices transmit simultaneously on the same channel and spreading factor, there will be a collision and one or both packets will be lost. In practice, since LoRa devices transmit infrequently (every few minutes), collisions are rare for small networks of up to 10-15 devices.

What is the difference between a single-channel gateway and a multi-channel gateway?

A single-channel gateway listens on one frequency at one spreading factor. A commercial multi-channel gateway (8 channels) listens on 8 frequencies simultaneously and can handle all spreading factors. Commercial gateways are required for production LoRaWAN deployments. The ESP32 SCPF is suitable for learning, prototyping, and small private networks.

Build Your LoRa Gateway Today

Get genuine ESP32 boards, sensors, and accessories for your LoRa gateway project from Zbotic — trusted by Indian makers and engineers nationwide.

Shop ESP32 & LoRa Components on Zbotic

Tags: ESP32, gateway, LoRa, LPWAN, TTN
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
MQTT vs HTTP: Best Protocol fo...
blog mqtt vs http best protocol for iot data transfer 595477
blog esp32 i2c scanner find unknown sensor addresses fast 595481
ESP32 I2C Scanner: Find Unknow...

Related posts

Svg%3E
Read more

IoT Home Insurance Sensor Kit: Leak, Smoke, and Motion

April 1, 2026 0
Table of Contents IoT and Home Insurance Water Leak Detection Smoke and Fire Detection Motion and Intrusion Sensing Building the... Continue reading
Svg%3E
Read more

IoT Pet Tracker: GPS Collar with Geofencing Alerts

April 1, 2026 0
Table of Contents Introduction and Overview Hardware Components Required GPS Module Integration with ESP32 Cloud Platform Setup Real-Time Tracking Dashboard... Continue reading
Svg%3E
Read more

IoT Aquaponics Controller: Fish and Plant Automation

April 1, 2026 0
Table of Contents The Water Monitoring Challenge in India Sensor Technologies for Water Building the Sensor Node Data Transmission and... Continue reading
Svg%3E
Read more

IoT Composting Monitor: Temperature and Moisture Tracking

April 1, 2026 0
Table of Contents Why Temperature Monitoring Matters Sensor Selection Guide Hardware Assembly and Wiring Firmware Development Cloud Data Logging Alert... Continue reading
Svg%3E
Read more

IoT Beehive Monitor: Weight, Temperature, and Humidity

April 1, 2026 0
Table of Contents Why Monitor Beehives Weight Measurement System Temperature and Humidity Sensing Building the Monitor Data Analysis for Bee... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now