Remove CAD from SX127X to fix intermittent reception

This commit is contained in:
Theo Arends 2024-02-29 17:23:37 +01:00
parent ce419cce81
commit adfbf6508a
2 changed files with 12 additions and 7 deletions

View File

@ -27,8 +27,11 @@
* - LoRa_DIO0 * - LoRa_DIO0
\*********************************************************************************************/ \*********************************************************************************************/
//#define USE_LORA_SX127X_CAD
#include <LoRa.h> // extern LoRaClass LoRa; #include <LoRa.h> // extern LoRaClass LoRa;
#ifdef USE_LORA_SX127X_CAD
void LoraOnCadDoneSx127x(boolean signalDetected) { void LoraOnCadDoneSx127x(boolean signalDetected) {
if (signalDetected) { // detect preamble if (signalDetected) { // detect preamble
#ifdef USE_LORA_DEBUG #ifdef USE_LORA_DEBUG
@ -39,6 +42,7 @@ void LoraOnCadDoneSx127x(boolean signalDetected) {
LoRa.channelActivityDetection(); // try next activity dectection LoRa.channelActivityDetection(); // try next activity dectection
} }
} }
#endif // USE_LORA_SX127X_CAD
// this function is called when a complete packet is received by the module // this function is called when a complete packet is received by the module
void LoraOnReceiveSx127x(int packet_size) { void LoraOnReceiveSx127x(int packet_size) {
@ -69,9 +73,9 @@ int LoraReceiveSx127x(char* data) {
Lora.rssi = LoRa.packetRssi(); Lora.rssi = LoRa.packetRssi();
Lora.snr = LoRa.packetSnr(); Lora.snr = LoRa.packetSnr();
#ifdef USE_LORA_SX127X_CAD
LoRa.channelActivityDetection(); // put the radio into CAD mode LoRa.channelActivityDetection(); // put the radio into CAD mode
#endif // USE_LORA_SX127X_CAD
return packet_size; return packet_size;
} }
@ -112,10 +116,13 @@ bool LoraInitSx127x(void) {
LoRa.setPins(Pin(GPIO_LORA_CS), Pin(GPIO_LORA_RST), Pin(GPIO_LORA_DI0)); LoRa.setPins(Pin(GPIO_LORA_CS), Pin(GPIO_LORA_RST), Pin(GPIO_LORA_DI0));
if (LoRa.begin(Lora.frequency * 1000 * 1000)) { if (LoRa.begin(Lora.frequency * 1000 * 1000)) {
LoraConfigSx127x(); LoraConfigSx127x();
LoRa.onCadDone(LoraOnCadDoneSx127x); // register the channel activity dectection callback
LoRa.onReceive(LoraOnReceiveSx127x); LoRa.onReceive(LoraOnReceiveSx127x);
// LoRa.receive(); #ifdef USE_LORA_SX127X_CAD
LoRa.onCadDone(LoraOnCadDoneSx127x); // register the channel activity dectection callback
LoRa.channelActivityDetection(); LoRa.channelActivityDetection();
#else
LoRa.receive();
#endif // USE_LORA_SX127X_CAD
return true; return true;
} }
return false; return false;

View File

@ -76,6 +76,7 @@ void LoraInit(void) {
LoraDefaults(); LoraDefaults();
char hardware[20]; char hardware[20];
strcpy_P(hardware, PSTR("Not"));
if (false) { if (false) {
} }
#ifdef USE_LORA_SX127X #ifdef USE_LORA_SX127X
@ -104,9 +105,6 @@ void LoraInit(void) {
} }
} }
#endif // USE_LORA_SX126X #endif // USE_LORA_SX126X
else {
strcpy_P(hardware, PSTR("Not"));
}
AddLog(LOG_LEVEL_DEBUG, PSTR("LOR: %s initialized"), hardware); AddLog(LOG_LEVEL_DEBUG, PSTR("LOR: %s initialized"), hardware);
} }
} }