Example for LoRa Communication-Two-to-One Communication

Last revision 2026/01/24

This article explains a two-to-one communication setup using LoRa technology with FireBeetle ESP32 and LoRaWAN modules, including preparation, wiring, coding, and results.

This example demonstrates the second type of one-to-many communication mode: setting nodes with addresses 1 and 2 as transmitters, and the node with address 3 as the receiver, achieving a "two-to-one" communication scenario.

Hardware Preparation

Software Preparation

Wiring Diagram

  • Transmitter:

DFR1115-868-Transmitter wiring diagram

  • Receiver:

DFR1115-868-Receiver wiring diagram

Sample Code

Transmitter Group 1 Program: Sets the node address to 1 and sends temperature and humidity data to the node with address 3.

#include <DFRobot_LWNode.h>
#define FREQ  868100000 
DFRobot_LWNode_UART node(2); // Set node address to 2

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); // Note: Set different UART ports
    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);
}

Transmitter Group 2 Program: Sets the node address to 2 and sends UV sensor data to the node with address 3.

#include <DFRobot_LWNode.h>
#define FREQ  868100000  

// Initialize LoRa and UV sensor
#include "DFRobot_LTR390UV.h"
DFRobot_LTR390UV ltr390(/*addr = */LTR390UV_DEVICE_ADDR, /*pWire = */&Wire);
DFRobot_LWNode_UART node(2); // Set node address to 2

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}; // 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, retrying...");
        delay(2000);
    }

    // Initialize UV sensor
    while (ltr390.begin() != 0) {
        Serial.println("UV sensor initialization failed, retrying...");
        delay(1000);
    }
    Serial.println("UV sensor initialization successful.");

    // Configure UV sensor
    ltr390.setALSOrUVSMeasRate(ltr390.e18bit, ltr390.e100ms); // 18-bit data, 100ms sampling
    ltr390.setALSOrUVSGain(ltr390.eGain3);                    // 3x gain
    ltr390.setMode(ltr390.eUVSMode);                          // Set to UV measurement mode
}

void loop(void) {
    // Read UV sensor data
    uint32_t uv = ltr390.readOriginalData(); // Get raw UV sensor data
    Serial.print("UV data: ");
    Serial.println(uv);

    // Prepare and send UV data to node with address 3
    String ltr390_DATE = String(uv);
    node.sendPacket(3, ltr390_DATE); 

    // Sleep to conserve power (adjust if needed)
    node.sleep(5000);
}

Receiver Program: Set the receiver node address to 3 and keep it in message receiving mode.

#include <DFRobot_LWNode.h>
#define FREQ  868100000  
DFRobot_LWNode_UART node(3); // Set 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.println("Text:");
    Serial.println((char *)buffer);
    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 transmitter Group 1:

DFR1115-868-Two-to-One Communication result1

Serial Output of Transmitter Group 2:

DFR1115-868-Two-to-One Communication result2

Serial Output of Receiver: Data received from Transmitter Group 1 and Group 2.

DFR1115-868-Two-to-One Communication result3

Was this article helpful?

TOP