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.
Warm regards,
Alexander ~~