About LoRa Multiple Reception

Hello.
I am using MKWAN1310 and receiving data via LoRa,
In rare cases, multiple receive messages are output.

The receiver program is as follows.It is the same as the sample.

// try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '"); // read packet
    // read packet
    while (LoRa.available()) {  
      contents += (char)LoRa.read(); }
    }
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
    Serial.println(contents); Serial.println(contents);

The received LOG at that time shows

20230801_155211 : b "Received packet '' with RSSI -123\r\n"
20230801_155211 : b'Lora SEnd:241\r\n
20230801_155211 : b "Received packet '' with RSSI -123\r\n"
20230801_155211 : b'Lora SEnd:241\r\n'

The form will be something like this. (date and time, b"" is given by python for serial reception)

The sender is sending while incrementing Lora SEnd:XXX and the timestamps are the same time, so I think the receiver is receiving more than one message.
The LoRa setting is SF12/Band125kHz.

Is there any problem?

You would need to show your full sketch to understand what's going on.

eg, you haven't showed how you recognise that a new packet has been received...

Thanks for the reply.
It is a program, but I don't think it makes much sense as it is mostly a sample.

receiving

#include <SPI.h>
#include <LoRa.h>
String contents = "";


void setup() {

  Serial.begin(9600);
  while (!Serial);
  //Wire.begin();
  Serial.println("LoRa Receiver");
  if (!LoRa.begin(923E6)) { 
    Serial.println("Starting LoRa failed!");
    while (1);
  }

   LoRa.setSignalBandwidth(125E3);  // Signal Bandwidth: defaults to 125kHz
  LoRa.setSpreadingFactor(12);     // Spreading Factor: defaults to 7, 6 to 12

  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
}

bool ledout=false;
void loop() {
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");
    // read packet
    while (LoRa.available()) {  
      contents += (char)LoRa.read();
    }
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
    Serial.println(contents);

    contents = "";

    if( ledout == true ){
      digitalWrite(LED_BUILTIN, HIGH);
      //Serial.println("LED ON");
    }else{
      digitalWrite(LED_BUILTIN, LOW);
      //Serial.println("LED OFF");
    }
  ledout = not(ledout);
  }
}

sender

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

int counter = 0;

int led = 2;
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);

//  while (!Serial);
//  Serial.println("LoRa Sender");




  if (!LoRa.begin(923E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  
  LoRa.setTxPower(13);             // TX Power: 13dBm, 20mW, ARIB STD-T108
  LoRa.setSignalBandwidth(125E3);  // Signal Bandwidth: defaults to 125kHz
  //LoRa.setSignalBandwidth(62.5E3);  // Signal Bandwidth: defaults to 62.5kHz
  LoRa.setSpreadingFactor(12);     // Spreading Factor: defaults to 7, 6 to 12


  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);

}

bool ledout=false;
void loop() {

  // send packet
  LoRa.beginPacket();
  LoRa.print("Lora SEnd:");
  LoRa.print(counter);
  LoRa.endPacket();
  counter++;
  Serial.print("Sending packet: ");
  Serial.println(counter);
  delay(10000);

  if( ledout == true ){
    digitalWrite(LED_BUILTIN, HIGH);
    //Serial.println("LED ON");
  }else{
    digitalWrite(LED_BUILTIN, LOW);
    //Serial.println("LED OFF");
  }
  ledout = not(ledout);
}

You mean MKR WAN 1310 ?

https://docs.arduino.cc/hardware/mkr-wan-1310

Your code looks like just plain point-to-point LoRa - not LoRaWAN - yes?

So this?

https://docs.arduino.cc/tutorials/mkr-wan-1300/lora-button-press

Have you tried that sketch - unmodified?

Have you studied the documentation for the library:
https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md ?

eg, with an "on-receive" callback ?

Sorry for the error, it is MKR WAN 1310.
It does not use LoRaWAN for communication, it is intended to work over P2P.

When I ran the sample, there was no button, so I inserted a delay in the transmission and changed it to send periodically.

The basic problem is in the response to LoRa.parsePacket(),
Why do I get a signal that is done reading?

Well LoRa.parsePacket(); should return 0 if there is no packet ready, there should be no need to use interrupts. If there was an inherrent problem here you would not expect the apparent double receipt of packets to be just 'rare'.

I would add a print of millis() just before the print of "Received packet" this would tell you the time gap between these apparent duplicate packets.

You have marked the issue as solved, did the solution suggested in post #5 solve the 'rare' double receipt of packets ?

It's unclear whether the LoRa.read should "consume" the packet?

probably unrelated to the issue, but:

Note that this will say, "Sending packet X" when you are actually sending packet (X-1)

Better:

  // send packet
  LoRa.beginPacket();
  LoRa.print("Lora SEnd:");
  LoRa.print(counter);
  LoRa.endPacket();

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

  counter++;

If it did not, then you would you not expect the duplicate packet read to happen all the time and not be 'rare'

And the simple LoRaReceiver example would be no good either ..............

This is true.

With READ using callback, for now, we no longer get duplicate receipts (although it's only a few dozen or so communications).

Thank you very much.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.