sandeepmistry / arduino-LoRa

An Arduino library for sending and receiving data using LoRa radios.
MIT License
1.61k stars 619 forks source link

Receiving packages stops after first package #385

Closed MasterPuffin closed 3 years ago

MasterPuffin commented 3 years ago

I use the following modified example code:

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

int counter = 0;

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

  Serial.println("LoRa Sender");
  // LoRa.setSpreadingFactor(7);

  if (!LoRa.begin(897.85E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  LoRa.setTxPower(20);
  LoRa.setSyncWord(0xF3);
  Serial.println("Starting LoRa success!");
}

void loop() {
  Serial.print("Sending packet: ");
  Serial.println(counter);

  // send packet
  LoRa.beginPacket();
  LoRa.print("ardude ");
  LoRa.print(counter);
  LoRa.endPacket();

  counter++;

  delay(5000);
}
#include <SPI.h>
#include <LoRa.h>

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

  Serial.println("LoRa Receiver Callback");
  // LoRa.setSpreadingFactor(7);

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

  LoRa.setSyncWord(0xF3);
  Serial.println("Starting LoRa success!");

  // register the receive callback
  LoRa.onReceive(onReceive);

  // put the radio into receive mode
  LoRa.receive();
}

void loop() {
  // do nothing
}

void onReceive(int packetSize) {  
  if (packetSize == 0) return;
  //if (abs(LoRa.packetFrequencyError()) > 5000) return;
  // received a packet
  Serial.print("Received packet ");

  // read packet
  //for (int i = 0; i < packetSize; i++) {
  //  Serial.print((char)LoRa.read());
  //}

  String incoming = "";

  for (int i = 0; i < packetSize; i++) {
    incoming += (char)LoRa.read();
  }

  Serial.print("Message: '" + incoming);

  // print RSSI of packet
  Serial.print("' with RSSI ");
  Serial.print(LoRa.packetRssi());
  Serial.print(" and SNR ");
  Serial.print(LoRa.packetSnr());
  Serial.print(" and PFE ");
  Serial.println(LoRa.packetFrequencyError());
}

I have the following issue: The sender sends the first package and the receiver receives and prints it. However the receiver then stops and does not print / receive any other packages send by the sender. When I restart the receiver, the receiver receives one package again, but and then stops again. If I change receiver and sender physically it all works without any issues.

I'm using two Arduino Nano clones with Dragino Lora Bee Modules (https://wiki.dragino.com/index.php?title=Lora_BEE). The wiring is this which is equal to the one provided in this repo.

MasterPuffin commented 3 years ago

So after a lot more testing I found out that it had to do with power delivery. I hooked the sender and receiver up to an external power supply and it works now. I don't really understand how the receiver can be limited by the arduinos power delivery so if anybody has an idea, please feel free to share it!