FORUM

Hobby Project - Lasertag ESPNOW - Lora Translator

I bought several of these modules for a hobby project:

The goal is to implement the following scenario with an ESP32 D1 Mini NodeMCU and a LoRa module (https://www.amazon.com/RYLR896-Module-SX1276-Antenna-Command/dp/B07NB3BK5H):

The devices “tagger-a” and “tagger-b” can only communicate over espnow. When “tagger-a” sends data over espnow in the range of “rep-a”, these data are received by “rep-a”, converted to LoRa data, and sent to “rep-b”. “rep-b” converts the information back to espnow data, so that “tagger-b” receives the same information that it would receive if it were in the immediate range of “tagger-a”. In this way, a seamless, bidirectional data exchange is to take place.

Unfortunately, I can see in the serial monitor of the Arduino IDE that the initialization of the LoRa module always fails.

Can you tell me if it is my code that is causing this error? I am at the end of my rope and would be very grateful for your support. No matter if I use the native RXD/TXD pins or how I turn the assignment around, it just seems that there is no communication between the “repeaters” (ESP32 D1 Mini NodeMCU + Reyax RYLR890/RYLR896 module).

In the meantime, I even asked a KI, which tells me that I should make a new “pin assignment”, which is not possible at all, since the LoRa module only has the pins RXD, TXD, GND, VDD, NRST, and “NULL”.

To see if it is possibly due to the libraries used, I have attached my source code.

It would be great if you could help me, … I have been working on it for a long time… :-/

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

// Netzwerkinformationen
const char* ssid = “JEDGE-CONTROLLER”;
const char* password = “123456789”;

// Datenstruktur für die zu sendenden Daten
struct struct_message {
int recipient; // INTENDED RECIPIENT - 99 ist all - 0-63 für player id - 100-199 für bases - 200 - 203 für teams 0-3
int command; // FUNCTION/COMMAND - range from 0 to 32,767 - 327 different settings - 99 verschiedene Optionen
int deviceID; // From - device ID
char score[200]; // used for score reporting
} DataToBroadcast;

// LoRa settings
#define LORA_FREQUENCY 915E6 // LoRa module frequency
#define LORA_BANDWIDTH 0x02 // LoRa module bandwidth
#define LORA_SPREADING_FACTOR 0x07 // LoRa module spreading factor
#define LORA_CODING_RATE 0x02 // LoRa module coding rate
#define LORA_TX_POWER 27 // LoRa module transmit power

// Global variable for the ESP-Now channel
int espNowChannel;

// Callback wenn Daten empfangen werden
void OnDataRecv(const uint8_t* mac, const uint8_t* incomingData, int len) {
// Hier können Sie die empfangenen Daten weiterverarbeiten
// Zum Beispiel, senden Sie die Daten über LoRa oder führen Sie andere Aktionen aus

// Speichere den Kanal des ESP-Now-Signals
espNowChannel = incomingData[0];

// Überprüfe, ob der Empfänger ein Repeater ist
if (espNowChannel == 99) {
    // Sende die empfangenen Daten an alle anderen Repeater
    esp_now_send(NULL, (uint8_t*)incomingData, len);
}

}

// Initialisierung des ESP32
bool initializeESP32() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

// Überprüfen, ob die Verbindung erfolgreich hergestellt wurde
if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Fehler beim Verbinden mit dem WLAN");
    return false;
}

return true;

}

// Initialisierung der ESP-Now-Funktionalität
bool initializeESPNow() {
if (esp_now_init() != ESP_OK) {
Serial.println(“Fehler beim Initialisieren von ESP-Now”);
return false;
}
esp_now_register_recv_cb(OnDataRecv);

// Setzen der MAC-Adresse des Controllers
// Ihre bestehende MAC-Adressenkonfiguration bleibt unverändert

// Hinzufügen des Controllers als Peer
esp_now_peer_info_t peerInfo;
memset(&peerInfo, 0, sizeof(peerInfo));
peerInfo.channel = 0;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Fehler beim Hinzufügen des Peers");
    return false;
}
return true;

}

void setup() {
// Initialisierung der seriellen Schnittstelle
Serial.begin(115200);
while (!Serial);

// Initialisierung des ESP32
if (!initializeESP32()) {
    while (1);
}

// Initialisierung der ESP-Now-Funktionalität
if (!initializeESPNow()) {
    while (1);
}

// Konfiguration des LoRa-Moduls
LoRa.setPins(16, 17); // RXD = GPIO16, TXD = GPIO17
if (!LoRa.begin(LORA_FREQUENCY)) {
    Serial.println("Fehler beim Initialisieren von LoRa");
    while (1);
}
LoRa.setSpreadingFactor(LORA_SPREADING_FACTOR);
LoRa.setCodingRate4(LORA_CODING_RATE);
LoRa.setSignalBandwidth(LORA_BANDWIDTH);
LoRa.setTxPower(LORA_TX_POWER); // Festlegen der Sendeleistung auf 27 dBm

// Konfiguration des Reyax RYLR890/RYLR896-Moduls
Serial2.begin(115200);

}

void loop() {
// Empfange LoRa-Daten
int packetSize = LoRa.parsePacket();
if (packetSize) {
byte loraData[packetSize];
for (int i = 0; i < packetSize; i++) {
loraData[i] = LoRa.read();
}
// Hier können Sie die empfangenen LoRa-Daten an ESP-NOW senden
esp_now_send(NULL, loraData, packetSize);
}
}

That appears to be a module with a UART serial interface that requires AT commands to configure.

The LoRa library you appear to be using is designed for SPI interface LoRa devices.

Did you contact REYAX for advice on a suitable library ?