Send more than 1 message before sleep

I’m using Wireless Stick Lite V3 board and Heltec ESP32 library v2.1.2
I’m not able to send 2 messages before going into sleep, only 1st message is sent to lorawan server.
I have tried LoRaWan Example code, which is working good with single message.

What changes have you made to allow this 2 message send then sleep to happen - if you post code please use the </> tool to quote it.

#include "LoRaWan_APP.h"

/* OTAA para*/
uint8_t devEui[] = { 0x00, 0x00, 0xDC, 0x54, 0x75, 0xCF, 0x0B, 0x2C };
uint8_t appEui[] = { 0x00, 0x00, 0xDC, 0x54, 0x75, 0xCF, 0x0B, 0x2C };
uint8_t appKey[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x54, 0x75, 0xCF, 0x0B, 0x2C };

/* ABP para*/
uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 };
uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 };
uint32_t devAddr =  ( uint32_t )0x007e6ae1;

/*LoraWan channelsmask, default channels 0-7*/ 
uint16_t userChannelsMask[6]={ 0x00FF,0x0000,0x0000,0x0000,0x0000,0x0000 };

/*LoraWan region, select in arduino IDE tools*/
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;

/*LoraWan Class, Class A and Class C are supported*/
DeviceClass_t  loraWanClass = CLASS_A;

/*the application data transmission duty cycle.  value in [ms].*/
uint32_t appTxDutyCycle = 120000;

/*OTAA or ABP*/
bool overTheAirActivation = true;

/*ADR enable*/
bool loraWanAdr = true;

/* Indicates if the node is sending confirmed or unconfirmed messages */
bool isTxConfirmed = true;

/* Application port */
uint8_t appPort = 5;
/*!
* Number of trials to transmit the frame, if the LoRaMAC layer did not
* receive an acknowledgment. The MAC performs a datarate adaptation,
* according to the LoRaWAN Specification V1.0.2, chapter 18.4, according
* to the following table:
*
* Transmission nb | Data Rate
* ----------------|-----------
* 1 (first)       | DR
* 2               | DR
* 3               | max(DR-1,0)
* 4               | max(DR-1,0)
* 5               | max(DR-2,0)
* 6               | max(DR-2,0)
* 7               | max(DR-3,0)
* 8               | max(DR-3,0)
*
* Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
* the datarate, in case the LoRaMAC layer did not receive an acknowledgment
*/
uint8_t confirmedNbTrials = 4;

uint8_t cnt = 0;
uint32_t lastTicks = 0;

/* Prepares the payload of the frame */
static void prepareTxFrame( uint8_t port )
{
  /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h".
  *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
  *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
  *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
  *for example, if use REGION_CN470, 
  *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h".
  */
    memset(appData, NULL, sizeof(appData));
    appDataSize = 4;
    appData[0] = 0x09;
    appData[1] = 0x08;
    appData[2] = 0x07;
    appData[3] = 0x06;
}

static void prepareTxFrame2( uint8_t port )
{
  /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h".
  *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
  *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
  *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
  *for example, if use REGION_CN470, 
  *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h".
  */
    memset(appData, NULL, sizeof(appData));
    appDataSize = 4;
    appData[0] = 0x04;
    appData[1] = 0x05;
    appData[2] = 0x06;
    appData[3] = 0x07;
    //Serial.println("Inside prepareTxFrame2");
}

//if true, next uplink will add MOTE_MAC_DEVICE_TIME_REQ 


void setup() {
  Serial.begin(115200);
  Serial.println("Started");
  delay(2000);
  Mcu.begin(HELTEC_BOARD,SLOW_CLK_TPYE);
}

void loop()
{
  switch( deviceState )
  {
    case DEVICE_STATE_INIT:
    {
#if(LORAWAN_DEVEUI_AUTO)
      LoRaWAN.generateDeveuiByChipID();
#endif
      LoRaWAN.init(loraWanClass,loraWanRegion);
      //both set join DR and DR when ADR off 
      LoRaWAN.setDefaultDR(3);
      break;
    }
    case DEVICE_STATE_JOIN:
    {
      LoRaWAN.join();
      break;
    }
    case DEVICE_STATE_SEND:
    {
      if(millis() - lastTicks >= 30000)
      {
        lastTicks = millis();
      
        if(!cnt)
        {
          cnt = 1;
          prepareTxFrame( 1 );
          LoRaWAN.send();
          Serial.println("Sent Pkt-1");    
          appPort = 10;  
        }
        else if(cnt)
        {
          cnt = 0;
          prepareTxFrame2( 3 );
          LoRaWAN.send();
          Serial.println("Sent Pkt-2");
          deviceState = DEVICE_STATE_CYCLE;
          appPort = 5;
        }
      }
      
      break;
    }
    case DEVICE_STATE_CYCLE:
    {
      // Schedule next packet transmission
      //txDutyCycleTime = appTxDutyCycle + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
      txDutyCycleTime = appTxDutyCycle;
      LoRaWAN.cycle(txDutyCycleTime);
      //Serial.println("txDutyCycleTime:" + String(txDutyCycleTime));
      deviceState = DEVICE_STATE_SLEEP;
      break;
    }
    case DEVICE_STATE_SLEEP:
    {
      LoRaWAN.sleep(loraWanClass);
      break;
    }
    default:
    {
      deviceState = DEVICE_STATE_INIT;
      break;
    }
  }
}

The under the hood state machine coupled with the automagically updated state machine in the sketch don’t allow for this to work - once a send has occurred, a flag is set in the LW implementation that requires the sleep cycle to run to reset it so another send can happen.

Either you override the appTxDutyCycle so that after the first send it schedules a send in 30 seconds time and then after the second send, returns to your 120 seconds. Or you hack on LoRaWan_APP - which I wouldn’t recommend, to allow you to override the flags.

Or use a different LW implementation.

Can you please explain how to override appTxDutyCycle?
You can suggest any LW implementation which supports sending multiple messages before sleep.

It’s a number you’ve set to 120000. Make it a different number using =

All of them could potentially do it but as I’ve not tried this double send I can’t suggest any particular one and I’m not aware of any that have a bullet point of “supports multiple sends before sleep” - it’s just the wrapper that is LoRaWan_APP happens to assume you will sleep between sends. Most other implementations drop down a level - more Lego like for you to build what you need. The LoRaWan_APP wrapper covers the majority of use cases of read sensor, send it, sleep. It just doesn’t work out for you.