Lora can't receive after 1 hour

hi guys. I fixed the problem and it work, as a reminder; node1 send hi to node2 and node2 answer it. it work now but take a look at my code please and tell me why ir stop working after 60 minutes? I Send 300 times at 1 hour. after around 300 times sending, the Node2 cant receive message. why?
A
Node1(Sender):

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

unsigned char Hi[] = "Hi I'm Node1";
String inString = "";

void setup(){
  Serial.begin(9600);
  while (!Serial);
  Serial.println("LoRa gateway");
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {

  if(runEvery(10000))
  Send(Hi);

   int packetSize = LoRa.parsePacket();
  if (packetSize){
  Receive();
  }
}


void  Send(String Byte){
 ‚ÄčLoRa.beginPacket();
 ‚ÄčLoRa.print(Byte);
 ‚ÄčLoRa.endPacket();
 ‚ÄčSerial.println(Byte);
 ‚Äč}

void Receive(){
    Serial.print("received:  ");
    String incoming = "";
  while (LoRa.available()) {
    incoming += (char)LoRa.read();
               }
Serial.println(incoming);             ‚Äč
        }  

  
  boolean runEvery(unsigned long interval){
  static unsigned long previousMillis = 0;
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval){
    previousMillis = currentMillis;
    return true;
  }
  return false;
} 

Node2(Receiver):

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

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("LoRa Sender");
  if (!LoRa.begin(433E6)){
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
    int packetSize = LoRa.parsePacket();
  if(packetSize){
  Receive();
  Answer();
  }
}

void Send(String Byte){
  LoRa.beginPacket();
  LoRa.print(Byte);
  LoRa.endPacket();
  }

void Receive(){
  String incoming = "";
  while (LoRa.available()) {
    incoming += (char)LoRa.read();
  }
  Serial.print("Received: " + incoming);
  }


void Answer(){
    String sendANswer = "I got it";
     Serial.print("   Send: ");
               Serial.println(sendANswer);  
                Send(sendANswer);
}

after around 300 times sending, the Node2 cant receive message. why?

1 Like

Hey Hossein,

I had a look through the repo for the library and it mentions that all of the duty cycles are managed by the user so I’m not too sure if its due to the library.

There seem to be some good discussions over in the issues on the Git( looks like someone got back to you there :slight_smile: )

I would insert some strategic print statements to try and debug exactly where the receiver hangs, I have a feeling there is a link to this post here: While loop, sometimes takes long or never ends · Issue #378 · sandeepmistry/arduino-LoRa · GitHub

Keen to see where you go with this!!
Liam.

4 Likes