ESP32_LoRaWAN Downlink message save

Hello all. I have a Heltec LoRa32 V2 that I am using as a node to connect to my TTN gateway. I am using the ESP32_LoRaWAN library. In the past I have used these micro controllers to test node to node communication using the heltec.h library. In this library I was able to save input to global variables using LoRa.read. Now I am trying to do same with this library but can’t seem to find a way to accomplish that. I have seen downlink capabilities in the OTAA_LED sketch as shown below.

void  downLinkDataHandle(McpsIndication_t *mcpsIndication)

{
lora_printf("+REV DATA:%s,RXSIZE %d,PORT %d\r\n",mcpsIndication->RxSlot?“RXWIN2”:“RXWIN1”,mcpsIndication->BufferSize,mcpsIndication->Port);
lora_printf("+REV DATA:");
app(mcpsIndication->Buffer[0]);

for(uint8_t i=0;iBufferSize;i++)
{
lora_printf("%02X",mcpsIndication->Buffer[i]);
}
lora_printf("\r\n");
}

I noticed that in this sketch there is a case-based system for changing the LED state but not to save that downlink message into a global variable. (as shown below)

#define LEDPin 25  //LED light

void app(uint8_t data)
{
// lora_printf(“data:%d\r\n”,data);
switch(data)
{
case 49:
{
pinMode(LEDPin,OUTPUT);
digitalWrite(LEDPin, HIGH);
break;
}
case 50:
{
pinMode(LEDPin,OUTPUT);
digitalWrite(LEDPin, LOW);
break;
}
case 51:
{
break;
}
default:
{
break;
}
}
}

I was wondering if there is a way to do this?

I’ve not used lorar wan but I did a search on the mcpsindication and found an implementation that seems to be reading the data.

Have a look at the routine at line 150 of this library.

It looks like this structure contains an indication whether data has been received, a pointer to the buffer and buffer length. So you may just be able to malloc a global buffer and use memcpy from this.

It may not be that straightforward but hopefully will be of some use.

unfortunately, it didnt work.

You can refer to this example for rewriting.