LoRaWan_APP Transmit Time

I am using the CubeCell Dev Board (V1) by Heltec for LoRa transmission.

I have 1 board setup as a transmitter, and 1 board setup as a receiver.

The code is based on the LoRa examples from Heltec.

The aim is to have the receiver turn on a relay while the transmitter is transmitting, and as soon as the receiver doesn't receive a valid code from the transmitter, it switches off the relay.
I would like to have the delay between switching off the transmitter, and the relay switching off, to be no more than 500ms

I have setup the sender to transmit at a random time, anywhere up to 250ms. This all appears to be working, however, the receiver is only receiving about 1 packet per second, so misses anywhere from 6 to 9 packets each time.

Is there a way I can get the receiver to receive more packets, or is this a limitation of the LoRaWan_APP library?

I have previously setup something similar using a Dragino Lora Shield, and LoRa.h, which worked well, but LoRa.h doesn't seem to be compatible with the CubeCell

I am fairly new to LoRa and arduino, so stumbling my way through everything

Transmitter Code:


#include "LoRaWan_APP.h"
#include "Arduino.h"

/*
 * set LoraWan_RGB to 1,the RGB active in loraWan
 * RGB red means sending;
 * RGB green means received done;
 */
#ifndef LoraWan_RGB
#define LoraWan_RGB 0
#endif

#define RF_FREQUENCY                                433000000 // Hz

#define TX_OUTPUT_POWER                             21        // dBm

#define LORA_BANDWIDTH                              0         // [0: 125 kHz,
                                                              //  1: 250 kHz,
                                                              //  2: 500 kHz,
                                                              //  3: Reserved]
#define LORA_SPREADING_FACTOR                       LoRaSF         // [SF7..SF12]
#define LORA_CODINGRATE                             1         // [1: 4/5,
                                                              //  2: 4/6,
                                                              //  3: 4/7,
                                                              //  4: 4/8]
#define LORA_PREAMBLE_LENGTH                        8         // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT                         0         // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON                  false
#define LORA_IQ_INVERSION_ON                        false


#define RX_TIMEOUT_VALUE                            1000
#define BUFFER_SIZE                                 16 // Define the payload size here

char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents;

float txNumber;
bool lora_idle=true;
int LoRaSF = 8;
int Transmitter_ID = 100; // Set to 100 so if something is wrong with jumpers, nothing will happen.

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

    txNumber=0;



#define J1 GPIO1  // Jumper 1 for remote coding
#define J2 GPIO2  // Jumper 2 for remote coding
#define J3 GPIO3  // Jumper 3 for LoRa Spreading Factor

#define J4 GPIO4  // Jumper 4 for Remote Function
#define J5 GPIO5  // Jumper 5 for Remote Function

#define RB GPIO0  // Input for remote button - may not be needed
#define LED 0 // Output for LED

  int counter = 0;
  int delay_time = 0;


  pinMode(J1, INPUT);
  pinMode(J2, INPUT);
  pinMode(J3, INPUT);
  pinMode(J4, INPUT);
  pinMode(J5, INPUT);
  pinMode(RB, INPUT);
  pinMode(LED, OUTPUT);  // Not doing anything with this yet, but should turn on when button pressed, and flash if voltage low.




  // calculate Transmitter number based on J1, J2, J3
  Trans_ID(); // Call the Trans_ID function - calculates the transmitter ID based on jumpers

// Set LoRa Spreading Factor
  if (digitalRead(J3) == HIGH) {
   LoRaSF =  11;           // ranges from 6-12,default 7 see API docs
  }
  if (digitalRead(J3) == LOW) {
   LoRaSF = 12;           // ranges from 6-12,default 7 see API docs
  }


    RadioEvents.TxDone = OnTxDone;
    RadioEvents.TxTimeout = OnTxTimeout;
    Radio.Init( &RadioEvents );
    Radio.SetChannel( RF_FREQUENCY );
    Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                                   LORA_SPREADING_FACTOR, LORA_CODINGRATE,
                                   LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
                                   true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); 
}




void loop() {
  Transmitter_ID ++;
  Serial.print("Sending packet: ");
  Serial.println(Transmitter_ID);
  Serial.print("SF");
  Serial.println(LORA_SPREADING_FACTOR);

 
sprintf(txpacket,"%u",Transmitter_ID);  //start a package
Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out 
  int  delay_time = random(250); // set random delay to prevent interferring with other transmitters
  delay(delay_time);
}





void Trans_ID() { // Calculates the transmitter number based on State of jumpers J1, J2, J4 & J5. (J3 is used for spreading factor not ID)

  int Sum = 0;
  if (digitalRead(J1) == HIGH) {
    Sum += 1;
  }
  if (digitalRead(J2) == HIGH) {
    Sum += 2;
  }
  if (digitalRead(J4) == HIGH) {
    Sum += 4;
  }
  if (digitalRead(J5) == HIGH) {
    Sum += 8;
  }
  Transmitter_ID = Sum;
}

void OnTxDone( void )
{
  turnOffRGB();
  Serial.println("TX done......");
  lora_idle = true;
}

void OnTxTimeout( void )
{
  turnOffRGB();
  Radio.Sleep( );
  Serial.println("TX Timeout......");
  lora_idle = true;
}

Receiver Code

/* Heltec Automation Receive communication test example
 *
 * Function:
 * 1. Receive the same frequency band lora signal program
 * 
 * 
 * this project also realess in GitHub:
 * https://github.com/HelTecAutomation/ASR650x-Arduino
 * */

#include "LoRaWan_APP.h"
#include "Arduino.h"

/*
 * set LoraWan_RGB to 1,the RGB active in loraWan
 * RGB red means sending;
 * RGB green means received done;
 */
#ifndef LoraWan_RGB
#define LoraWan_RGB 0
#endif

#define RF_FREQUENCY                                433000000 // Hz

#define TX_OUTPUT_POWER                             21        // dBm

#define LORA_BANDWIDTH                              0         // [0: 125 kHz,
                                                              //  1: 250 kHz,
                                                              //  2: 500 kHz,
                                                              //  3: Reserved]
#define LORA_SPREADING_FACTOR                       12         // [SF7..SF12]
#define LORA_CODINGRATE                             1         // [1: 4/5,
                                                              //  2: 4/6,
                                                              //  3: 4/7,
                                                              //  4: 4/8]
#define LORA_PREAMBLE_LENGTH                        8         // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT                         0         // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON                  false
#define LORA_IQ_INVERSION_ON                        false


#define RX_TIMEOUT_VALUE                            100
#define BUFFER_SIZE                                 16 // Define the payload size here

char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents;

int16_t txNumber;

int16_t rssi,rxSize;

bool lora_idle = true;

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

    txNumber=0;
    rssi=0;
  
    RadioEvents.RxDone = OnRxDone;
    Radio.Init( &RadioEvents );
    Radio.SetChannel( RF_FREQUENCY );
  
    Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
                                   LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
                                   LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
                                   0, true, 0, 0, LORA_IQ_INVERSION_ON, true );

   }



void loop()
{
  if(lora_idle)
  {
    turnOffRGB();
    lora_idle = false;
    Serial.println("into RX mode");
    Radio.Rx(0);
  }
}

void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
    rssi=rssi;
    rxSize=size;
    memcpy(rxpacket, payload, size );
    rxpacket[size]='\0';
    turnOnRGB(COLOR_RECEIVED,0);
    Radio.Sleep( );
    Serial.printf("\r\nreceived packet \"%s\" with rssi %d , length %d\r\n",rxpacket,rssi,rxSize);
    lora_idle = true;
}

The higher the spreading factor, the longer the transmission time.
For example.


taken from

All I need to transmit is the number 15, so not a large data packet. Even on SF 12, I can't see that that is going to take 1 seccond to transmit.

When I had this running with the LoRa.h library on the Dragino boards, it had no trouble transmitting packets at that rate, which makes me think there is some sort of delay built into the LoRaWan_APP library

For small payloads the overhead of the packet wrapper determines the transmission time.

At high SF numbers the resulting long transmission times mean that your keep-alive system with a 500 millisecond timeout is only going to work if the communication is 100% reliable. This is unlikely to work in the real-world using shared spectrum.

If your timeout period is inflexible then your only have two options, use a smaller SF value (shorter range), or use multiple transmitter receiver pairs to provide redundant communication channels using different frequency bands.

An on-air time calculator such as this will give you an idea of the realistic transmission times.
https://avbentem.github.io/airtime-calculator/ttn

Reducing SF sped things up a lot. I would still like to keep SF as high as possible, and BW as low as possible, to allow maximum range.

What settings can I modify to reduce transmission time?

Am I correct in assuming I should set CR to 4/5?
What is the minimum Preamble Length I can get away with?
I only need 1 way communication, and missing the odd packet is not an issue if I can get the transmission time faster

Are there any other settings I can change to speed things up?

Thanks

IIRC there is a duty cycle limitation imposed by the radio regs in the bands that LoRa works in in various countries. Maybe 1%? This may be baked into the code in the modules and might limit the packet transmission rate.

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