arduino-LoRa: Delay in loop() stops receive

Hi,

I experience a strange issue with the library: if I put a delay in the loop(), the LoRa module fails to receive almost all packets. I use the delay to simulate some long blocking operations. I send 30 bytes packets every 2 seconds.

From the example LoRaReceiver, just added the delay and I get maybe 1 packet out of 10. Without the delay, I receive every packet. Why is that?

void loop() {
  delay(100);
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");

    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }

    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  }
}

Hardware: LoRa32u4 II board (https://bsfrance.fr/lora-long-range/1345-LoRa32u4-II-Lora-LiPo-Atmega32u4-SX1276-HPD13-868MHZ-EU-Antenna.html)

Thanks, Best regards, Benjamin

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

Just an update, the ISR routine flag messes up with the OLED.display() from SSD1306Wire.h as it is really picky and dos not like to be interrupted or it messes up with the display data, Being so I falled back into a mixed approach of using parsePacket() and when it results in greater than ZERO I read the buffer data and put it back on MODE_RX_CONTINUOUS calling receive();

uint16_t loraRead(uint8_t* data, uint16_t max_len)
{
	if(LoRa.parsePacket() == 0 || max_len == 0)
	{
		return 0;
	}
	
	LoRa.idle();
	
	int16_t rssi = LoRa.packetRssi();
	int16_t snr = LoRa.packetSnr();
	
	// CLEAR BUFFER
	memset(data, 0, max_len);
	
	// LORA RX
	uint16_t count = 0;	
	while(LoRa.available())
	{
		if(count < max_len)
		{
			data[count++] = LoRa.read();
		}
		else
		{
			LoRa.read();
		}
	}	
	LoRa.receive();
	return count;
}