LoRaWAN IoT Gateway: ESP32 and Raspberry Pi Setup Tutorial

LoRaWAN (Long RangeLoRa Sensor Nodes: Sending Data to The Things Network (TTN)LoRa Sensor Nodes: Sending Data to The Things Network (TTN)Discover how to deploy ESP32 with LoRa and TTN for long-range IoT sensor networks. Our comprehensive guide covers hardware, configuration, and troubleshooting. Wide Area Network) is a powerful protocol designed for low-power, long-range communication in IoT applications. By combining the ESP32 microcontrollerArquitetura ESP32: SoC dual-core, subsistemas RF integradosArquitetura ESP32: SoC dual-core, subsistemas RF integradosDiscover the ESP32’s dual-core prowess and integrated RF subsystems for efficient, innovative IoT applications—from smart homes to industrial sensors. with a Raspberry Pi, you can create a scalable, cost-effective LoRaWAN gateway that bridges local LoRa networks to cloud servers. This guide will walk you through the process, from hardware setup to software configuration, ensuring you can build a robust gateway for your IoT projects.

Table of Contents🔗

1. Understanding LoRa and LoRaWANESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry.

2. Hardware Requirements

3. WiringUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityExplore our detailed tutorial on integrating Quectel BC66/BG96 with ESP32 for low-power, reliable NB-IoT connectivity. Learn hardware setup and AT commands. the LoRa Module to ESP32

4. Setting Up the Raspberry Pi as a GatewayESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry. Backend

5. Programming the ESP32Setting Up ESP32 as a Wi-Fi Access PointSetting Up ESP32 as a Wi-Fi Access PointMaster ESP32 AP configuration with our step-by-step guide. Set up a secure, local IoT network using practical code examples and optimization tips. as a LoRa Node

6. Integrating with ChirpStack for Network Management

7. Testing and Optimizing Your LoRaWAN GatewayESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry.

8. Deployment Considerations

9. Practical ApplicationsZigbee Green Power: Ultra-Low-Power Energy Harvesting SolutionsZigbee Green Power: Ultra-Low-Power Energy Harvesting SolutionsDiscover how ZGP enables battery-free IoT devices through energy harvesting with ESP32 integrations, supporting smart home and industrial applications. and Use Cases

Understanding LoRa and LoRaWAN🔗

LoRa (Long RangeLoRa Sensor Nodes: Sending Data to The Things Network (TTN)LoRa Sensor Nodes: Sending Data to The Things Network (TTN)Discover how to deploy ESP32 with LoRa and TTN for long-range IoT sensor networks. Our comprehensive guide covers hardware, configuration, and troubleshooting.) is a wireless communication technology that operates in the sub-GHz ISM bands (e.g., 868 MHz in Europe, 915 MHz in North America). It uses spread spectrum modulation to achieve impressive rangeQuick Comparison: Range, power consumption, costs, and complexity of each technologyQuick Comparison: Range, power consumption, costs, and complexity of each technologyDiscover the ideal wireless solution for your ESP32 IoT project by analyzing range, power, cost, and complexity. Optimize connectivity now. (up to 10 km in rural areas) while consuming minimal power.

LoRaWANESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry. is a protocol built on top of LoRa, defining the network architecture and communication rules. It enables devices (nodes) to communicate with gateways, which forward data to a network server. LoRaWAN is ideal for IoT applicationsConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies. like smart agriculture, asset tracking, and environmental monitoringConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies. due to its scalability and energy efficiency.

Hardware Requirements🔗

To build a LoRaWAN gatewayESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry., you’ll need the following components:

ComponentDescriptionExample Model
ESP32 BoardActs as the LoRa node or packet forwarder.ESP32 DevKit v1
Raspberry PiRuns the LoRaWAN network server (e.g., ChirpStack).Raspberry Pi 4B
LoRa ModuleEnables LoRa communication.SX1276 (LoRa) or SX1301 (Gateway)
Antenna868/915 MHz antenna for LoRa frequency.SMA Antenna (3dBi)
Jumper WiresFor SPI/UART connections.-
Power SupplyStable power for both ESP32 and Raspberry Pi.5V/2A Adapter

Wiring the LoRa Module to ESP32🔗

The LoRa module communicates with the ESP32Setting Up ESP32 as a Wi-Fi Access PointSetting Up ESP32 as a Wi-Fi Access PointMaster ESP32 AP configuration with our step-by-step guide. Set up a secure, local IoT network using practical code examples and optimization tips. via SPIInterfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Interfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Unlock seamless smart home integration by following our detailed guide on bridging ESP32 with external Zigbee modules for reliable IoT solutions. or UARTInterfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Interfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Unlock seamless smart home integration by following our detailed guide on bridging ESP32 with external Zigbee modules for reliable IoT solutions.. Here’s how to wire it up:

SPI Connection (SX1276 Example)

LoRa PinESP32 Pin
GNDGND
VCC3.3V
SCKGPIO 18
MISOGPIO 19
MOSIGPIO 23
NSSGPIO 5
RESETGPIO 14
DIO0GPIO 2
Note: Use a logic level converter if your LoRa module operates at 5V.

Setting Up the Raspberry Pi as a Gateway Backend🔗

1. Install Raspbian OS: Download and flash the latest Raspbian OS onto your Raspberry Pi.

2. Install ChirpStack (Open-source LoRaWANESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry. Server):

sudo apt-get update
sudo apt-get install docker-compose
git clone https://github.com/chirpstack/chirpstack-docker.git
cd chirpstack-docker
docker-compose up -d

3. Access the Web Interface at httpUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityExplore our detailed tutorial on integrating Quectel BC66/BG96 with ESP32 for low-power, reliable NB-IoT connectivity. Learn hardware setup and AT commands.://[RPI_IP]:8080 and configure:

Programming the ESP32 as a LoRa Node🔗

Use the arduino-LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry. library to send sensor dataSigfox Message Encoding: Packing Sensor Data into 12-byte PayloadsSigfox Message Encoding: Packing Sensor Data into 12-byte PayloadsLearn efficient data encoding techniques for Sigfox's constrained 12-byte payloads. Discover bitwise operations, structured encoding & CBOR strategies.:

#include <SPI.h>
#include <LoRa.h>
void setup() {
  Serial.begin(115200);
  LoRa.setPins(5, 14, 2); // CS, RST, IRQ
  if (!LoRa.begin(915E6)) {
    Serial.println("LoRa init failed!");
    while (1);
  }
}
void loop() {
  LoRa.beginPacket();
  LoRa.print("Temp:23.5°C");
  LoRa.endPacket();
  delay(15000);
}

Key Parameters:

Integrating with ChirpStack for Network Management🔗

1. Install Docker on Raspberry Pi:

curl -fsSL https://get.docker.com | sh

2. Download ChirpStack:

git clone https://github.com/chirpstack/chirpstack-docker.git

3. Configure and Run ChirpStack:

cd chirpstack-docker
docker-compose up -d

4. Access the Web Interface: Open httpUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityExplore our detailed tutorial on integrating Quectel BC66/BG96 with ESP32 for low-power, reliable NB-IoT connectivity. Learn hardware setup and AT commands.://<Raspberry-Pi-IP>:8080 and configure your gatewayESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry. and devices.

Testing and Optimizing Your LoRaWAN Gateway🔗

  • Check ChirpStack Logs for incoming packets:
docker logs chirpstack-network-server
mosquitto_sub -t "application/+/device/+/event/up"

Common Issues:

Deployment Considerations🔗

Practical Applications and Use Cases🔗

1. Smart Agriculture: Monitor soil moisture, temperature, and humidity across large farms.

2. Asset Tracking: Track vehicles, containers, or wildlife with GPS-enabled LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry. nodes.

3. Environmental MonitoringConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies.: Measure air quality, noise levels, and water conditions in urban areas.

By following this guide, you’ll have a fully functional LoRaWAN gatewayESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaESP32 Multi-Protocol Gateways: Combining Wi-Fi, BLE, and LoRaDiscover how to build a multi-protocol ESP32 gateway integrating Wi-Fi, BLE, and LoRa for scalable IoT deployments in smart cities and industry. that can serve as the backbone of your IoT network. Whether you’re a hobbyist or a professional, this setup provides a cost-effective and scalable solution for long-range, low-power connectivity.

Author: Marcelo V. Souza - Engenheiro de Sistemas e Entusiasta em IoT e Desenvolvimento de Software, com foco em inovação tecnológica.

References🔗

Share article

Related Articles