Problem with my LoRa module RSSI and Packet Loss reading

Hey guys, I'm about to start my project using LoRa to transfer the data from the transmitter to the receiver. Each of the devices includes an Arduino Uno and a LoRa E220-900T22D module by EByte. But first, I want to make sure that the range between both of them can be analyzed.

So, here's the code for the transmitter.

#include <SoftwareSerial.h>

SoftwareSerial lora(2, 3);
int messageCount = 0;  // Counter to track the number of messages sent

void setup() {
  Serial.begin(9600);
  lora.begin(9600);
}

void loop() {
  // Check if 10 seconds have passed
  static unsigned long lastMillis = 0;
  if (millis() - lastMillis >= 10000) {
    lastMillis = millis();  // Update the lastMillis value
    
    // Increment the message count
    messageCount++;

    // Send the word "hello" over SoftwareSerial
    lora.print("hello");

    // Print the message count
    Serial.print("Message Count: ");
    Serial.println(messageCount);
    lora.println("+" + String(messageCount));
  }

  // Check if there is data available on the Serial monitor
  if (Serial.available()) {
    // Read the data from Serial and send it over SoftwareSerial
    lora.write(Serial.read());
  }
}

And the code for the receiver.

#include "Arduino.h"
#include "LoRa_E220.h"
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>

// Define software serial pins
SoftwareSerial mySerial(2, 3);  // RX on pin 2, TX on pin 3
LoRa_E220 e220ttl(&mySerial);

LiquidCrystal_I2C lcd(0x27, 20, 4);

unsigned long oldTime = 0;
unsigned long totalReceived = 0;
unsigned long failedTransmissions = 0;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  delay(500);
  e220ttl.begin();
  Serial.println("Start receiving!");

  lcd.begin(20, 4);
  lcd.init();
  lcd.backlight();
}

void loop() {
  unsigned long currentTime = millis();
  if (currentTime - oldTime > 10000) {
    oldTime = currentTime;  // Update the oldTime value

    if (e220ttl.available() > 1) {
      totalReceived++;  // Increment total received transmissions
      Serial.println("Message received!");
      ResponseContainer rc = e220ttl.receiveMessage();

      if (rc.status.code != 1) {
        failedTransmissions++;  // Increment failed transmissions
        Serial.println(rc.status.getResponseDescription());
      } else {
        Serial.println("Device: End_Node_1");
        Serial.print("Message: ");
        Serial.println(rc.data);
        Serial.print("Status: ");
        Serial.println(rc.status.getResponseDescription());
        Serial.print("RSSI: ");
        Serial.println(rc.rssi, DEC);
        Serial.println();

        //Calculate Packet Loss Percentage
        float packetLossPercentage = (failedTransmissions / (float)totalReceived) * 100.0;

        Serial.print("Packet Loss: ");
        Serial.print(packetLossPercentage);
        Serial.println("%");

        // Display on LCD
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Device: End_Node_1");

        lcd.setCursor(0, 1);
        lcd.print("Message: ");
        lcd.print(rc.data);

        lcd.setCursor(0, 2);
        lcd.print("Packet Loss: ");
        lcd.print(packetLossPercentage);
        lcd.print(" %");

        lcd.setCursor(0, 3);
        lcd.print("RSSI: ");
        lcd.print(rc.rssi, DEC);
        lcd.print(" dBm");

        // Delay before next readings
        delay(9000);  // Adjusted delay to make it 10 seconds in total (10000 - 1000)
      }
    }
  }
}

The problem is that I can't read the RSSI or the packet loss value. I believe both of the functions have been available in the library of E220 by Renzo Mischianti.

in one of his examples I've seen
https://github.com/xreef/EByte_LoRa_E220_Series_Library/blob/b42c7f088c44928a4fe58fc204d02b731112c186/examples/02_sendTransparentTransmission/02_sendTransparentTransmission.ino#L5-L11

1 Like

Thanks for the help! I already changed the configuration of LoRa module with my usb to ttl driver using the rf setting application from ebyte, especially for changing the channel, enabling the rssi, and other configurations. Probably the reason it failed, is because the library doesn't add compatibility with this application.

be careful the UNO uses 5V logic the E220 communication level is 3.3V

you should use level shifters or potential dividers in any UNO lines which transmit 5V logic levels to the E220

using Transparent transmission as mentioned by @calfuckinzaghe I read RSSI in one of my programs, e.g. using a Ebyte E220 connected to a ESP32

ESP32 > transmit > (14) Success  temperature 26.60  humidity 60.90  pressure 200.00
received length 11  ResponseDescription Success
      seq 132  temperature 158.60  humidity 1380.90  pressure 13400.00 RSSI: 110
*** Sequence number error ! expected 0

ESP32 > transmit > (14) Success  temperature 27.60  humidity 70.90  pressure 300.00
received length 11  ResponseDescription Success
      seq 133  temperature 159.60  humidity 1390.90  pressure 13500.00 RSSI: 110

ESP32 > transmit > (14) Success  temperature 28.60  humidity 80.90  pressure 400.00
received length 11  ResponseDescription Success
      seq 134  temperature 160.60  humidity 1400.90  pressure 13600.00 RSSI: 110

using an ESP32 where logical level is 3.3V saves problems with different logic levels

1 Like

I'm sorry for the late reply. I had considered using the voltage divider for my circuit. But the data transmission wasn't the problem on my Arduino board. I can transmit the DHT22 data from the transmitter to the receiver. But for the RSSI detection, it might have something to do with the coding part. I'd be glad if you shared the code for your program.

some time since I used the E220 but I think this is the program
ESP32_02_sendTransparent_Struct.ino using a pair of ESP32 using Serial2 port

// ESP32_02_sendTransparentTransmission
// Load ESP32_02_sendTransparent_Struct into both ESP32

// both will transmit and display received data, e.g.
// ESP32 > transmit > (14) Success  temperature 26.60  humidity 60.90  pressure 200.00
// received length 11  ResponseDescription Success
//      seq 132  temperature 158.60  humidity 1380.90  pressure 13400.00 RSSI: 110
// *** Sequence number error ! expected 0
//
// ESP32 > transmit > (14) Success  temperature 27.60  humidity 70.90  pressure 300.00
//received length 11  ResponseDescription Success
//      seq 133  temperature 159.60  humidity 1390.90  pressure 13500.00 RSSI: 110

/*
 * EBYTE LoRa E220
 * send a transparent message, you must check that the transmitter and receiver have the same
 * CHANNEL ADDL and ADDH
 *
 * Pay attention e220 support RSSI, if you want use that functionality you must enable RSSI on configuration
 * configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
 *
 * and uncomment #define ENABLE_RSSI true in this sketch
 *
 * You must uncommend the correct constructor.
 *
 * by Renzo Mischianti <https://www.mischianti.org>
 *
 * https://www.mischianti.org
 *
 * E220		  ----- WeMos D1 mini	----- esp32			----- Arduino Nano 33 IoT	----- Arduino MKR	----- Raspberry Pi Pico   ----- stm32               ----- ArduinoUNO
 * M0         ----- D7 (or GND) 	----- 19 (or GND) 	----- 4 (or GND) 			----- 2 (or GND) 	----- 10 (or GND)	      ----- PB0 (or GND)        ----- 7 Volt div (or GND)
 * M1         ----- D6 (or GND) 	----- 21 (or GND) 	----- 6 (or GND) 			----- 4 (or GND) 	----- 11 (or GND)	      ----- PB10 (or GND)       ----- 6 Volt div (or GND)
 * TX         ----- D3 (PullUP)		----- TX2 (PullUP)	----- TX1 (PullUP)			----- 14 (PullUP)	----- 8 (PullUP)	      ----- PA2 TX2 (PullUP)    ----- 4 (PullUP)
 * RX         ----- D4 (PullUP)		----- RX2 (PullUP)	----- RX1 (PullUP)			----- 13 (PullUP)	----- 9 (PullUP)	      ----- PA3 RX2 (PullUP)    ----- 5 Volt div (PullUP)
 * AUX        ----- D5 (PullUP)		----- 18  (PullUP)	----- 2  (PullUP)			----- 0  (PullUP)	----- 2  (PullUP)	      ----- PA0  (PullUP)       ----- 3 (PullUP)
 * VCC        ----- 3.3v/5v			----- 3.3v/5v		----- 3.3v/5v				----- 3.3v/5v		----- 3.3v/5v		      ----- 3.3v/5v             ----- 3.3v/5v
 * GND        ----- GND				----- GND			----- GND					----- GND			----- GND			      ----- GND                 ----- GND
 *
 */
#define ENABLE_RSSI true
#define FREQUENCY_868

#include "Arduino.h"
#include "LoRa_E220.h"

// ---------- esp8266 pins --------------
//LoRa_E220 e220ttl(RX, TX, AUX, M0, M1);  // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(D3, D4, D5, D7, D6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(D2, D3); // Config without connect AUX and M0 M1

//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(D2, D3); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, D5, D7, D6); // AUX M0 M1
// -------------------------------------

// ---------- Arduino pins --------------
//LoRa_E220 e220ttl(4, 5, 3, 7, 6); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
//LoRa_E220 e220ttl(4, 5); // Config without connect AUX and M0 M1

//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(4, 5); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX
//LoRa_E220 e220ttl(&mySerial, 3, 7, 6); // AUX M0 M1
// -------------------------------------

// ------------- Arduino Nano 33 IoT -------------
// LoRa_E220 e220ttl(&Serial1, 2, 4, 6); //  RX AUX M0 M1
// -------------------------------------------------

// ------------- Arduino MKR WiFi 1010 -------------
// LoRa_E220 e220ttl(&Serial1, 0, 2, 4); //  RX AUX M0 M1
// -------------------------------------------------

// ---------- esp32 pins --------------
// LoRa_E220 e220ttl(&Serial2, 15, 21, 19); //  RX AUX M0 M1
//  ESP32
#define RXD1 16
#define TXD1 17

// ---------- esp32 pins --------------
LoRa_E220 e220ttl(&Serial2, 18, 21, 19);  //  RX AUX M0 M1
// CHECK WIRING!  using GetConfiguration

//LoRa_E220 e220ttl(&Serial2, 22, 4, 18, 21, 19, UART_BPS_RATE_9600); //  esp32 RX <-- e220 TX, esp32 TX --> e220 RX AUX M0 M1
// -------------------------------------

// ---------- Raspberry PI Pico pins --------------
// LoRa_E220 e220ttl(&Serial2, 2, 10, 11); //  RX AUX M0 M1
// -------------------------------------

// ---------------- STM32 --------------------
//HardwareSerial Serial2(USART2);   // PA3  (RX)  PA2  (TX)
//LoRa_E220 e220ttl(&Serial2, PA0, PB0, PB10); //  RX AUX M0 M1
// -------------------------------------------------

// test structure
struct __attribute__((packed)) Struct1 {
  int16_t seq;  // sequence number
  float temperature;
  float humidity;
  float pressure;
};

Struct1 struct1 = { 0, 25.6f, 50.9f, 100.0f };  // test values

void setup() {
  Serial.begin(115200);
  //Serial2.begin(9600, SERIAL_8N1, RXD1, TXD1);  // NOT REQUIRE!!!!

  // Startup all pins and UART
  e220ttl.begin();
  sendData();
}

void sendData(void) {
  // update data ready for next transmissiom - replace with code to read sensor
  struct1.temperature += 1.0f;
  struct1.humidity += 10.0f;
  struct1.pressure += 100.0f;
  Serial.printf("\nESP32 > transmit > (%d) ", sizeof(struct1));
  ResponseStatus rs = e220ttl.sendMessage(&struct1, sizeof(struct1));
  // Check If there is some problem of succesfully send
  Serial.print(rs.getResponseDescription());  // transmit structure and print vales transmitted
  Serial.print("    seq ");
  Serial.print(struct1.seq);
  Serial.print("  temperature ");
  Serial.print(struct1.temperature);
  Serial.print("  humidity ");
  Serial.print(struct1.humidity);
  Serial.print("  pressure ");
  Serial.println(struct1.pressure);
  struct1.seq++;
}

void loop() {
  static long timer = millis();
  static int seqExpected = 0;
  // If something available
  if (e220ttl.available() > 1) {
    delay(10);
    Serial.printf("received length %d ", e220ttl.available());
    // read the structure message
    ResponseStructContainer rc = e220ttl.receiveMessageRSSI(sizeof(Struct1));
    // Is something goes wrong print error
    if (rc.status.code != 1) {
      Serial.print("  ResponseDescription ");
      Serial.println(rc.status.getResponseDescription());
    } else {
      // Print the data received
      Serial.print(" ResponseDescription ");
      Serial.println(rc.status.getResponseDescription());
      Serial.print("      seq ");
      Serial.print(((Struct1*)rc.data)->seq);
      Serial.print("  temperature ");
      Serial.print(((Struct1*)rc.data)->temperature);
      Serial.print("  humidity ");
      Serial.print(((Struct1*)rc.data)->humidity);
      Serial.print("  pressure ");
      Serial.print(((Struct1*)rc.data)->pressure);
      Serial.print(" RSSI: ");
      Serial.println(rc.rssi, DEC);
      // check for sequence error
      if (struct1.seq != seqExpected) {
        Serial.print("*** Sequence number error ! expected ");
        Serial.println(seqExpected);
      }
      seqExpected = struct1.seq + 1;  // set up next sequence number
    }
  }
  if (millis() - timer > 5000) {
    timer = millis();
    sendData();
  }
}

1 Like

Thanks, you’re a lifesaver!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.