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?
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!");
}
}
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:
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.