Negative RSSI issue with ESP32 and LoRa Ra-02 SX1278 module

Greetings everyone,

I hope you're doing well. Currently, I'm working on a project involving an ESP32 and a LoRa Ra-02 SX1278 module to establish long-range wireless communication. However, I've encountered an unexpected obstacle: regardless of the proximity between the transmitter and the receiver (even just 5 meters apart), I consistently receive negative RSSI values.

I've diligently reviewed my code and checked the module settings, yet I can't seem to pinpoint the root cause of this issue. Would any kind soul here have any ideas why this might be happening? Perhaps there are specific adjustments or considerations I should be aware of to obtain more accurate RSSI values?

Any guidance or advice you could offer would be greatly appreciated. Thank you very much for your time and assistance. Attached are the codes: from E1, I press a button and it sends a 1 to E2, which turns on an LED. The LED lights up and sends a confirmation to E1. This is the code for E1

#include <SPI.h>
#include <LoRa.h>

#define ss 5
#define rst 22
#define dio0 2
const int pinPulsador = 4;
const int ledPin = 15;

byte localAddress = 0xBB;   // Dirección de este dispositivo
byte destination = 0xFF;    // Dirección a la que enviar mensajes


void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  
  pinMode(pinPulsador, INPUT_PULLUP);

  while (!Serial);
  Serial.println("LoRa Duplex");

  LoRa.setPins(ss, rst, dio0);

  while (!LoRa.begin(433E6)) {
    Serial.println(".");
    delay(500);
  }
  
  // LoRa.setTxPower(0); // Ajusta el nivel de potencia de salida (en dBm)

  LoRa.setSyncWord(0xF3);
  Serial.println("LoRa Initializing OK!");
}

void loop() {
  int estadoPulsador = digitalRead(pinPulsador);

  if (estadoPulsador == LOW) {
    int dataToSend = 1; // Aquí puedes cambiar el valor que deseas enviar
    sendMessage(dataToSend);
    delay(500); // Evitar el envío repetido al mantener presionado el pulsador
  }

  // Intenta analizar el paquete
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    onReceive(packetSize);
  }
}

void sendMessage(int outgoing) {
  LoRa.beginPacket();
  LoRa.write(destination);
  LoRa.write(localAddress);
  LoRa.write(sizeof(outgoing)); // Enviar el tamaño del entero
  LoRa.write((uint8_t*)&outgoing, sizeof(outgoing)); // Enviar el entero
  LoRa.endPacket();
}

void onReceive(int packetSize) {
   if (packetSize == 0) return;

  int recipient = LoRa.read();
  byte sender = LoRa.read();
  byte incomingLength = LoRa.read();

  int incoming = 0;
  LoRa.readBytes((uint8_t*)&incoming, sizeof(incoming)); // Leer el entero recibido

  Serial.println("Received from: 0x" + String(sender, HEX));
  Serial.println("Message: " + String(incoming));
  Serial.println("RSSI: " + String(LoRa.packetRssi()));
  Serial.println();
}

and this is for E2.

//Sistema
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"

//Lora
#include <SPI.h>
#include <LoRa.h>

//Mqtt
// #include <WiFi.h>
// #include <PubSubClient.h>

//Pin Lora
#define ss 5
#define rst 22
#define dio0 2
const int ledPin = 15;

byte localAddress = 0xFF;   // Dirección de este dispositivo
byte destination = 0xBB;    // Dirección a la que enviar mensajes

void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  while (!Serial);
  Serial.println("LoRa Duplex");
  LoRa.setPins(ss, rst, dio0);
  while (!LoRa.begin(433E6)) {
    Serial.println(".");
    delay(500);
  }
  
  // LoRa.setTxPower(0); // Ajusta el nivel de potencia de salida (en dBm)
  LoRa.setSyncWord(0xF3);
  Serial.println("LoRa Initializing OK!");
}
void onReceive(int packetSize) {
  if (packetSize == 0) return;
  int recipient = LoRa.read();
  byte sender = LoRa.read();
  byte incomingLength = LoRa.read();
  int incoming = 0;
  LoRa.readBytes((uint8_t*)&incoming, sizeof(incoming)); // Leer el entero recibido
  Serial.println("Received from: 0x" + String(sender, HEX));
  Serial.println("Message: " + String(incoming));
  Serial.println("RSSI: " + String(LoRa.packetRssi()));
  Serial.println();

  // led
  if (incoming == 1) {
    digitalWrite(ledPin, HIGH); // Enciende el LED si el mensaje recibido es 1
  } 
}

void sendMessage(int outgoing) {
  LoRa.beginPacket();
  LoRa.write(destination);
  LoRa.write(localAddress);
  LoRa.write(sizeof(outgoing)); // Enviar el tamaño del entero
  LoRa.write((uint8_t*)&outgoing, sizeof(outgoing)); // Enviar el entero
  delay(500); // Puedes ajustar el tiempo según tus necesidades
  LoRa.endPacket();
}

void loop() {
  // Intenta analizar el paquete
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    onReceive(packetSize);
    int dataToSend = 3; // Aquí puedes cambiar el valor que deseas enviar
    sendMessage(dataToSend);
    delay(500);
    digitalWrite(ledPin, LOW);
  }
}
P.S.: The values I'm getting are  -90 , -80.

image

Warm regards,

Alexander ~~

As they should be. Understanding RSSI Levels | MetaGeek

Please could you explain to me, I have a problem similar to that of my colleague, but according to the link you share, 80 is not good, it seems curious to me because the same thing happens to me at 5 meters it is negative and at 12 or 15 it decreases even more

An RSSI of -80 dBm is OK for LoRa radios, but suggests that you don't have the required antennas.

According to the RA-02 product description, the receiver can receive data at RSSI values as low as -140 dBm, which I do not believe. This suggests that they define the RSSI based on some different measure (not dBm) and should not be taken seriously.

Post the details of your setup, including a photo.

at 5 meters it is negative

In the convention you are using, RSSI should always be negative.

I am very interested in the topic, @jremington it seems that he has an idea of ​​how it works, in my case I have the same problem as Alexander, in my case I used antennas of this type, with frequencies of 433 MHz, at first I had the device without antenna later I used these antennas and they gave me the values ​​from -80 to 6mst - 8mts, I don't understand why, I also used an ESP32, it could be some problem with the Lora library.

I even tried other frequencies, then I realized that they only work at 433Mhz, and I tried 2.5ghz antennas from the esp wifi but it gave the same value

With short stubby UHF antennas on RX and TX. With TX at 10dBm power level, and the RX 1metre away, you should get an RSSI of around -40dBm @ 434Mhz. At 6metres you would expect RSSI to drop to circa -56dBm.

If you get substantially lesss than that, then it suggests a problem with the antennas. If you have an antenna problem its possible the module with the problem antenna has already been damadged.

Very unlikely to be a problem with the LoRa library.

Using the wrong frequency antennas has the potential to damage the modules.

You will not get anywhere near the signal levels quoted in the datasheet, I have always assumed they were tests done in a lab in faraday shield.

Typically an antenna at UHF RF is seeing around -105dBm of noise, so if the spreading factor in use has a SNR limit of -10dB, you would expect reception to stop when the signal level falls to -115dB or less.

Years back, in 2015, I did some decending power tests with LoRa over a 40km hilltop to hilltop link. The weakest packets received were 2dBm. Since the transmit power, antenna gain and distance was known, the calculation showed that the weakest signal received was at a level of -114dBm when it got to the receiver. The quoted datasheet sensitivity was -131dBm.

I think there is something wrong with how the manufacturer is measuring or reporting RSSI. It can't be dBm.

The valid test is communications range, so get out in the field and check that instead of worrying about numbers printed on a screen.

Its supposed to be dBm.

However it is true that Semtech did change how RSSI is calculated.

Prior to March 2015 the calculation was;

And was then changed to;

As a general guide the RSSI is a useful indicator that you have failrly strong signals, if you want to know how close a signal is to failing and in very weak, use the SNR for the spreading factor in use.

SF7 SNR limit -5dB
SF7 SNR limit -7.5dB
SF8 SNR limit -10dB
SF9 SNR limit -12.5dB
SF10 SNR limit -15dB
SF11 SNR limit -17.5dB
SF12 SNR limit -20dB

I have this configuration and at half a meter I get a value of -66 at half a meter away.image

and y use this Antenna
image

I would expect an RSSI of maybe -35dBm

LoRa.setCodingRate4(4);

Have you checked the documentation for the LoRa library you are using ?

Coding rate denominators are normally 5,6,7 or 8

Hello, I currently reach +150 meters from the top of a building, passing through parks and so on, using this configuration.

  LoRa.setTxPower(20); 
  LoRa.setSpreadingFactor(10);
  LoRa.setSignalBandwidth(125E3);
  LoRa.setCodingRate4(5);
  LoRa.setPreambleLength(8);

I don't know if it's a good or bad result

The RSSI value should always be negative since it is always LESS that the test signal that is used to calibrate the device. The less negative, the better the received signal is.

That is a good result, if the goal is to communicate over 150 m.

I suggest to get on with the real project.

Thank you very much @jremington, a question that arises for me is if I modify these variables

LoRa.setTxPower(20); 
  LoRa.setSpreadingFactor(10);
  LoRa.setSignalBandwidth(125E3);
  LoRa.setCodingRate4(5);
  LoRa.setPreambleLength(8);

Should I change this delay to allow time for reception?

void sendMessage(int outgoing) {
  LoRa.beginPacket();
  LoRa.write(destination);
  LoRa.write(localAddress);
  LoRa.write(sizeof(outgoing)); // Enviar el tamaño del entero
  LoRa.write((uint8_t*)&outgoing, sizeof(outgoing)); // Enviar el entero
  LoRa.endPacket();
}

or modify the transmission delay?

Delays like the one below accomplish nothing and should be deleted.

  LoRa.write((uint8_t*)&outgoing, sizeof(outgoing)); // Enviar el entero
  delay(500); // Puedes ajustar el tiempo según tus necesidades
  LoRa.endPacket();

A delay like the one below is a major problem, because it prevents the receiver from listening or responding to a transmission for long periods of time.

    onReceive(packetSize);
    int dataToSend = 3; // Aquí puedes cambiar el valor que deseas enviar
    sendMessage(dataToSend);
    delay(500);

You seem to have chosen a rather bad example for a starting project. Do not use delay() unless you understand why it is required, and how long the delay must be.