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?