Example for LoRa Communication-Data Relay Application
Last revision 2026/01/24
The article offers a comprehensive guide on implementing data relay in LoRa communication using three nodes A, B, and C to extend the communication range beyond direct data transmission.
In addition to direct data transmission and reception, nodes also support data relay to extend communication range.
In this example, three nodes (A, B, and C) with addresses 1, 2, and 3 are used to demonstrate the A→B→C data relay process. Node A sends data to Node B, which then forwards it to Node C. This allows Node C, which is outside the direct communication range of Node A, to receive data from Node A.
Hardware Preparation
- FireBeetle 2 ESP32-E (SKU: DFR0654) ×3
- Gravity: LoRaWAN Node Module(EU868)(DFR1115-868) ×3
- Gravity: DHT11 Temperature and Humidity Sensor (SKU: DFR0067) ×1
- PH2.0-4P Cable ×3
- PH2.0-3P Cable ×1
- USB Data Cable ×3
Software Preparation
- Download Arduino IDE: Click to Download Arduino IDE
- Install SDK: Visit the FireBeetle 2 ESP32-E WIKI page for SDK installation instructions
- Download and install the DFRobot_DHT11
- Download Arduino Library: Click to download DFRobot_LWNode Library and refer to the guide: How to Install a Library?
Wiring Diagram
- Node A:

- Both Node B and Node C use the following connection method:

Sample Code
Node A Program: Set the node address to 1 and send temperature and humidity sensor data to Node B with address 2.
#include <DFRobot_LWNode.h>
#include <dht11.h>
dht11 DHT;
#define DHT11_PIN 4
#define FREQ 868100000
DFRobot_LWNode_UART node(1); // Set node address to 1
void setup( void ) {
Serial.begin(115200);
Serial1.begin(9600, SERIAL_8N1, /*rx =*/D6, /*tx =*/D7);
delay(5000);
node.begin(/*communication UART*/&Serial1,/*debug UART*/&Serial);
const uint32_t loraConfig[] = {FREQ, DBM16, 125000, 12}; // Configure LoRa communication parameters
while(!node.setFreq(loraConfig[0]) ||
!node.setEIRP(loraConfig[1]) ||
!node.setBW(loraConfig[2]) ||
!node.setSF(loraConfig[3]) ||
!node.start()) {
Serial.println("LoRa init failed");
delay(2000);
}
}
void loop( void ){
DHT.read(DHT11_PIN); // Read temperature and humidity data from the DHT11 sensor
Serial.print(DHT.humidity,1);
Serial.print(",\t");
Serial.println(DHT.temperature,1);
String DHT11_DATE = String(DHT.humidity) + "%" + " " + String(DHT.temperature) + "℃";
delay(2000);
node.sendPacket(2, DHT11_DATE); // Send temperature and humidity data to Node B with address 2
node.sleep(1000);
}
Node B Program: Set the node address to 2, receive data from Node A, and forward it to Node C with address 3.
#include <DFRobot_LWNode.h>
#define FREQ 868100000
DFRobot_LWNode_UART node(2); // Set node address to 2
char p[36];
void rxCBFunc(uint8_t from, void *buffer, uint16_t size, int8_t rssi, int8_t snr) {
memcpy(p, buffer, size); // Memory copy, copy the data from buffer to the p array
Serial.print("recv from: ");
Serial.println(from, HEX);
Serial.print("recv data: ");
for(uint8_t i = 0; i < size; i++) {
Serial.print(p[i]);
}
Serial.println();
Serial.print("rssi="); Serial.println(rssi);
Serial.print("snr="); Serial.println(snr);
}
void setup(void) {
Serial.begin(115200);
Serial1.begin(9600, SERIAL_8N1, /*rx =*/D6, /*tx =*/D7);
delay(5000);
node.begin(/*communication UART*/&Serial1, /*debug UART*/&Serial);
const uint32_t loraConfig[] = {FREQ, DBM16, 125000, 12}; // Configure LoRa communication parameters
while (!node.setFreq(loraConfig[0]) ||
!node.setEIRP(loraConfig[1]) ||
!node.setBW(loraConfig[2]) ||
!node.setSF(loraConfig[3]) ||
!node.start()) {
Serial.println("LoRa init failed");
delay(2000);
}
node.setRxCB(rxCBFunc);
}
void loop(void) {
node.sleep(5000);
node.sendPacket(3, p); // Forward the received message to the node with address 3
}
Node C Program: Set the node address to 3 and keep it in message receiving mode to receive data from Node B.
#include <DFRobot_LWNode.h>
#define FREQ 868100000
DFRobot_LWNode_UART node(3); // Set the node address to 3
void rxCBFunc(uint8_t from, void *buffer, uint16_t size, int8_t rssi, int8_t snr){
char *p = (char *)buffer;
Serial.print("recv from: ");
Serial.println(from, HEX);
Serial.print("recv data: ");
for(uint8_t i = 0; i < size; i++){
Serial.print(p[i]);
}
Serial.println();
Serial.print("rssi="); Serial.println(rssi);
Serial.print("snr="); Serial.println(snr);
}
void setup( void ){
Serial.begin(115200);
Serial1.begin(9600, SERIAL_8N1, /*rx =*/D6, /*tx =*/D7);
delay(5000);
node.begin(/*communication UART*/&Serial1,/*debug UART*/&Serial);
const uint32_t loraConfig[] = {FREQ, DBM16, 125000, 12}; // Configure LoRa communication parameters
while(!node.setFreq(loraConfig[0]) ||
!node.setEIRP(loraConfig[1]) ||
!node.setBW(loraConfig[2]) ||
!node.setSF(loraConfig[3]) ||
!node.start()) {
Serial.println("LoRa init failed");
delay(2000);
}
node.setRxCB(rxCBFunc);
}
void loop( void ){
node.sleep(5000);
}
Results
Serial Output of Node A:

Serial Output of Node B: Received data from Node A and forwarded it.

Serial Output of Node C: Received data from Node B.

Was this article helpful?
