LoraLib receiver delay

Hello Forum,

I just converted a remote sensor frpm HC-11 to a Ra-02 with SX1278 chip. Very impressed with increased functionality so far.

I have the two examples loaded on two UNO's, "transmit" in the sensing unit and "receive" in the other. Working fine.

I do however find that there is a delay worked in somewhere in the receive example, not in the code of the sketch, but must be somewhere in the library. This is causing a problem in the sketch I am incorporating it into, which I have taken great care not to use any delays in. I make use of touch screen in my final sketch and with this delay I'm finding that the tuoch screen does not react while these delays are active. There's also a few other side effects of the delays which is messing up my main sketch.

The question - does anyone know where to find this delay hidden in the library? Is it possible to have the Loralib work without this delay?

Thanks,
Hein

Here's the code for the receive sketch. It looks like the delay is 1000ms because "timeout!" pops up on the serial monitor every second or so as long as no packets are received.

// include the library
#include <LoRaLib.h>

// create instance of LoRa class with default settings
// chip:                SX1278
// NSS pin:             7
// carrier frequency:   434.0 MHz
// bandwidth:           125 kHz
// spreading factor:    10
// coding rate:         4/7
// DIO0 pin:            2
// DIO1 pin:            3
LoRa lora;

// create empty instance of Packet class
Packet pack;

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

  // initialize the LoRa module with default settings
  uint8_t state = lora.begin();
  if(state != ERR_NONE) {
    Serial.print("Initialization failed, code 0x");
    Serial.println(state, HEX);
    while(true);
  }
}

void loop() {
  Serial.print("Waiting for incoming transmission ... ");

  // wait for single packet
  uint8_t state = lora.receive(pack);

  if(state == ERR_NONE) {
    // packet was successfully received
    Serial.println("success!");

    // create a string to store the packet information
    char str[24];

    // print the source of the packet
    pack.getSourceStr(str);
    Serial.print("Source:\t\t");
    Serial.println(str);

    // print the destination of the packet
    pack.getDestinationStr(str);
    Serial.print("Destination:\t");
    Serial.println(str);

    // print the length of the packet
    Serial.print("Length:\t\t");
    Serial.println(pack.length);

    // print the data of the packet
    Serial.print("Data:\t\t");
    Serial.println(pack.data);

    //print the measured data rate
    Serial.print("Datarate:\t");
    Serial.print(lora.dataRate);
    Serial.println(" bps");

    //print the RSSI (Received Signal Strength Indicator) of the last received packet
    Serial.print("RSSI:\t\t");
    Serial.print(lora.lastPacketRSSI);
    Serial.println(" dBm");

    //print the SNR (Signal-to-Noise Ratio) of the last received packet
    Serial.print("SNR:\t\t");
    Serial.print(lora.lastPacketSNR);
    Serial.println(" dBm");
    
  } else if(state == ERR_RX_TIMEOUT) {
    // timeout occurred while waiting for a packet
    Serial.println("timeout!");
    
  } else if(state == ERR_CRC_MISMATCH) {
    // packet was received, but is malformed
    Serial.println("CRC error!");
    
  }
  
}

Your code is actually asking the LoRa device to wait for an incoming packet ?

void loop() {
Serial.print("Waiting for incoming transmission ... ");

// wait for single packet
uint8_t state = lora.receive(pack);

So it does just that, it waits.

There appears to be a timeout so it does not wait forever, but if you ask it to wait, there is going to be a delay.

The receive code you posted is presumably heavily readacted, not very helpful, better to post the full code.

And provide a referance to the LoRa library you are using, we cannot tell.

srnet:
The receive code you posted is presumably heavily readacted, not very helpful, better to post the full code.

Not at all, that's it. The example is asking it to wait yes, but since there is no delay in this sketch it must be somewhere in the library. I've looked in each file in this library, and not one mention of delays in any of the files contained in the library folder. I'm convinced it uses delay because the UNO seems to be dedicated to do nothing during that second or so. So yes, it's asked to wait, but where is this request to wait and how do we bypass it? Ideally I'd like the program to loop through and process the packet as soon as it was successfully received. I don't need to know there was a timeout every (arbitrary) 1000ms.

The library is the one by Sandeep Mistry version 0.5.0 as found in the IDE library manager. Also found on github:

The code you posted is doing exactly as it should from what I can see.

My previous post got sent before I finished, did an edit.

Dont know the library specificallt but you coould try polling DIO0, if the default reception settings are in use, that goes high when a packet has been received.

Thanks @srnet.

When I put this into loop Serial.print(digitalRead(2)); it always prints zero, it only shows high immediately after reboot.

I suspect it may make D2 pin high after having "waited" and then received the packet, which doesn't help in this case.

What other libraries do you guys use that does not have this delay?

Hein

PS - digital pin 2 being connected to DIO0.

I am not familiar with that library, suggest you delve around in the source code or maybe ask the author.

I'm terribly sorry - I identified the wrong library. I'm using the loralib library by jgromes

Left a message on a discussion board where he hangs out sometimes.