Handle downlink Data

Hello, I’m having some problems in order to process the data from downlink payload.

I was following the documentation in https://www.chirpstack.io/application-server/integrations/mqtt/#scheduling-a-downlink and prepared two samples for testing in Node-Red:

First example:

{
    "confirmed": true,
    "fPort": 10,
    "data": "NTAw"
}

Second example:

{
    "confirmed": true,
    "fPort": 10,
    "data": "",
     "object": {                      
    "txinterval": {"1": 500}
     }
}

With the first example, the device receive the data, but I can only print in the terminal with the Serial.write(LMIC.frame + LMIC.dataBeg, LMIC.dataLen); I don’t know how to gather that data and use it for other things in my code. My objective is to send a number via node-red into my device that will manage the TX_INTERVAL for the os_setTimedCallback function.

With the second example the device doesn’t receive anything.

case EV_TXCOMPLETE:
            Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
            if (LMIC.txrxFlags & TXRX_ACK)
              Serial.println(F("Received ack"));
            if (LMIC.dataLen) {
              Serial.println(F("Received "));
              Serial.println(LMIC.dataLen);
              Serial.println(F(" bytes of payload"));
              Serial.write(LMIC.frame + LMIC.dataBeg, LMIC.dataLen);
            }
            // Schedule next transmission
            os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);

This is from the ttn-OTAA example of MCCI LoRaWAN LMIC library
When I receive a downlink package the LMIC.dataLen is > 0, in order to see the data I use Serial.write(LMIC.frame + LMIC.dataBeg, LMIC.dataLen); My question is… there is another function or method in order to obtain the value I’m sending?

I manage to understand what whas the problem, first for all, you have to send a converted base64 hexadecimal value: If you want to send 500, you have to convert it to hexadecimal: 01F4, then convert to base64: AfQ= after that, you only have to decode the payload with this line: (LMIC.frame[LMIC.dataBeg] << 8 ) + LMIC.frame[LMIC.dataBeg+1]