Hello guys,
I am trying to build a lora repeater with a ttgo esp32 lora board and I have some problems. So the code should recieve the packet and then send it again, that is basically it. I wrote some code and it works, but only the first time (see screenshot), after that the sending function is repeating it self somehow, and it isnt recieving anything new. I have no idea where i make a mistake, probably a dump one.
So I need some help.
#include <Wire.h>
#include <SFE_BMP180.h>
#include <SPI.h>
#include <LoRa.h>
#include "SSD1306.h"
#include<Arduino.h>
#define SS 18
#define RST 14
#define DI0 26
#define BAND 868E6//915E6
int counter = 0;
String message = "waiting for signal...";
void setup() {
Serial.begin(115200);
LoRa.setPins(SS,RST,DI0);
Serial.println("LoRa Repeater");
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa Initial OK!");
Serial.println(message);
delay(2000);
}
void loop() {
recieve();
delay(100);
if (message != "waiting for signal...") {
sending();
delay(100);
}
}
void recieve() {
//delay(1000);
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packets
Serial.print("Received packet. ");
while (LoRa.available()) {
String data = LoRa.readString();
Serial.print(data);
message = data;
}
// print RSSI of packet
Serial.print("m:");
Serial.println(message);
//Serial.print(" with RSSI ");
//Serial.println(LoRa.packetRssi());
}
}
void sending() {
//Serial.print("Sending packet: ");
//Serial.println(counter);
// send packet
delay(10);
Serial.println("sending:");
Serial.println(message);
LoRa.beginPacket();
LoRa.print(message);
LoRa.endPacket();
delay(200);
}