Uplink invoked by downlink

Hello,

I’m a newbie in Lora & LoraWan, so my question is probably stupid.

I have a Heltec Cubecell AB02A node connected to TTN via Dragino LPS8. The connection works fine for both uplink and downlink.

My problem is, that I want to send an uplink based on a downlink.

But my program is still stuck in a sleep state when I comment LoRaWAN.send() part (line 139).

I’m trying to send the transaction id via downlink and then send sensor data tagged with that transition via uplink.

Can somebody help me found a problem?

Thx

Of the device is sleeping it is a Class A nodes.
Class A nodes only receive downlink directly after sending uplinks.

Smash that learn button.

I’m using Class C.
The sleeping switch case is directly in the loop, so that should be the same for Class A and Class C I think.

My opinion is, that after the invocation of the downlink data handler is device reconfigured to Tx mode and I need to configure it back to Rx mode.

What messages are sent to the network before sleeping?
Have looked through the heltec forum?

Finally, something that works :slight_smile:

#include "LoRaWanMinimal_APP.h"
#include "Arduino.h"


#define LORA_BANDWIDTH                              0
#define LORA_SPREADING_FACTOR                       9
#define LORA_CODINGRATE                             1
#define LORA_PREAMBLE_LENGTH                        8         
#define LORA_SYMBOL_TIMEOUT                         0         
#define LORA_FIX_LENGTH_PAYLOAD_ON                  false
#define LORA_IQ_INVERSION_ON                        false


//////////////////////////////////////////////////////////////////////////////////////////////////////
//Set these OTAA parameters to match your app/node in TTN
uint8_t devEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 };

uint16_t userChannelsMask[6]={ 0x00FF,0x0000,0x0000,0x0000,0x0000,0x0000 };
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// INIT SLEEP MODE
TimerEvent_t sleepTimer;
bool sleepTimerExpired;

static void wakeUp()
{
  sleepTimerExpired=true;
}

static void lowPowerSleep(uint32_t sleeptime)
{
  sleepTimerExpired=false;
  TimerInit( &sleepTimer, &wakeUp );
  TimerSetValue( &sleepTimer, sleeptime );
  TimerStart( &sleepTimer );
  //Low power handler also gets interrupted by other timers
  //So wait until our timer had expired
  while (!sleepTimerExpired) lowPowerHandler();
  TimerStop( &sleepTimer );
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// LOOP STUFF
typedef enum
{
  LOWPOWER,
  RX,
  TX
} States_t;

States_t state;
uint8_t counter = 0;
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////


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

  LoRaWAN.begin(LORAWAN_CLASS, ACTIVE_REGION);
  
  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);

  LoRaWAN.setAdaptiveDR(true);

  while (1) {
    Serial.print("Joining... ");
    LoRaWAN.joinOTAA(appEui, appKey, devEui);
    if (!LoRaWAN.isJoined()) {
      Serial.println("JOIN FAILED! Sleeping for 30 seconds");
      lowPowerSleep(30000);
    } else {
      Serial.println("JOINED");
      LoRaWAN.send(1, 0, 1, true);
      break;
    }
  }
}

void loop()
{
  switch(state)
  {
    case TX:
       Serial.println("TX");
        counter++;
        LoRaWAN.send(1, &counter, 1, false);
        state=RX;
        break;
    case RX:
        Serial.println("RX");
        lowPowerHandler();
        break;
    default:
        Serial.printf("DEF");
        state=RX;
        break;
  }
}

void downLinkDataHandle(McpsIndication_t *mcpsIndication)
{
  Serial.printf("Received downlink: %s, RXSIZE %d, PORT %d, DATA: ",mcpsIndication->RxSlot?"RXWIN2":"RXWIN1",mcpsIndication->BufferSize,mcpsIndication->Port);
  for(uint8_t i=0;i<mcpsIndication->BufferSize;i++) {
    Serial.printf("%02X",mcpsIndication->Buffer[i]);
  }
  Serial.println();
  state = TX;
}

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