RFID LoRa Heltec receiver

Hello! I am using a code to sender the RFID informations, but the receiver don't work. I had tested with examples of heltec.h and there were comunication, but just with LoRa.h not.

Sender

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

#define LORA_SCK     5    
#define LORA_MISO    19   
#define LORA_MOSI    27 
#define LORA_SS      18  
#define LORA_RST     14   
#define LORA_DI0     26  
#define LORA_BAND    915E6

#include <SPI.h>
#include <MFRC522.h>

#define RFID_SDA 5 
#define RFID_SCK 18 
#define RFID_MOSI 23
#define RFID_MISO 19
#define RFID_RST 22

MFRC522 mfrc522(RFID_SDA, RFID_RST);  // Create MFRC522 instance

int current_spi = -1; // -1 - NOT STARTED   0 - RFID   1 - LORA

void setup() {
  Serial.begin(9600);   // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  
}

void loop() {
  bool card_present = RFID_check();
  if (card_present) LORA_send();
}

void spi_select(int which) {
     if (which == current_spi) return;
     SPI.end();
     
     switch(which) {
        case 0:
          SPI.begin(RFID_SCK, RFID_MISO, RFID_MOSI);
          mfrc522.PCD_Init();   
        break;
        case 1:
          SPI.begin(LORA_SCK,LORA_MISO,LORA_MOSI,LORA_SS);
          LoRa.setPins(LORA_SS,LORA_RST,LORA_DI0);
        break;
     }

     current_spi = which;
}

int RFID_check() {
  spi_select(0);
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    delay(100);
    return false;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return false;
  }

  // Dump debug info about the card; PICC_HaltA() is automatically called
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
  
  return true;
}

void LORA_send() {
  spi_select(1);
  
  Serial.println("LoRa Sender Test"); 
  
  if (!LoRa.begin(915E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

  Serial.println("init ok");
 
  delay(1500);

  // send packet
  LoRa.beginPacket();
  LoRa.print("hello ");

  LoRa.endPacket();

  Serial.println("sent one");
  delay(2000);                       // wait for a second
 }
  

Receiver

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

#define LORA_SCK 5
#define LORA_MISO 19
#define LORA_MOSI 27
#define LORA_SS 18
#define LORA_RST 14
#define LORA_DI0 26
#define LORA_BAND 915E6

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(LORA_SCK,LORA_MISO,LORA_MOSI,LORA_SS);
LoRa.setPins(LORA_SS,LORA_RST,LORA_DI0);
}

void loop() {

if (!LoRa.begin(915E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}

Serial.println("init ok");

delay(1500);
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");

// read packet
while (LoRa.available()) {
  Serial.print((char)LoRa.read());
}

// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}

I've not checked the code but it would help to tell us what do you see in the Serial monitor?

This problem was resolved with this code!

#include <SPI.h>
#include <LoRa.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <ThingsBoard.h>    // ThingsBoard SDK


char ssid[] = "Mariani";
char pass[] = "yu-gi-oh";
#define TOKEN               "JvkdK5ABO4n2LBQTc4c5"
#define THINGSBOARD_SERVER  "demo.thingsboard.io"

// Initialize ThingsBoard client
WiFiClient espClient;
// Initialize ThingsBoard instance
ThingsBoard tb(espClient);
// the Wifi radio's status
int status = WL_IDLE_STATUS;

char *Bovinos[]= {"Bovino1", "Bovino2"};

void setup() {
  Serial.begin(9600);
  while (!Serial);

  WiFi.begin(ssid, pass);
  InitWiFi();

  Serial.println("LoRa Receiver");
  LoRa.setPins(18, 14, 26);
  if (!LoRa.begin(915E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (WiFi.status() != WL_CONNECTED) {
  reconnect();
  }
   if (!tb.connected()) {
    // Connect to the ThingsBoard
    Serial.print("Connecting to: ");
    Serial.print(THINGSBOARD_SERVER);
    Serial.print(" with token ");
    Serial.println(TOKEN);
    if (!tb.connect(THINGSBOARD_SERVER, TOKEN)) {
      Serial.println("Failed to connect");
      return;
   }
  }
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");

    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }
    tb.sendTelemetryFloat(Bovinos[1], (char)LoRa.read());
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  }
    tb.loop();
}



  void InitWiFi()
{
  Serial.println("Connecting to AP ...");
  // attempt to connect to WiFi network

  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to AP");
}

void reconnect() {
  // Loop until we're reconnected
  status = WiFi.status();
  if ( status != WL_CONNECTED) {
    WiFi.begin(ssid, pass);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("Connected to AP");
  }
}