Downlink Payload print

I wanted to print the payload on serial monitor,
but i stuck with this code. Uplink works fine. I use OTAA. Arduino and Dragoni.The only thing i get on serial monitor is the number of Bytes. Can you help me out? Ty

 
   if (LMIC.dataLen) {
    // data received in rx slot after tx
    Serial.print(F("Received "));
    Serial.print(LMIC.dataLen);
    Serial.print(F(" bytes of payload: 0x"));
    for (int i = 0; i < LMIC.dataLen; i++) {
        if (LMIC.frame[LMIC.dataBeg + i] < 0x10) {
            Serial.print(F("0"));
            Serial.print(LMIC.frame[LMIC.dataBeg + i], HEX);
        }}
        
    }
    Serial.println();
}

your code is waiting for a application to send data ( hence ```
// data received in rx slot after tx


did you send data to that node ?

yes, i send a payload. If i open serial monitor i only receive the number of Bytes.

for (int i = 0; i < LMIC.dataLen; i++) {
    if (LMIC.frame[LMIC.dataBeg + i] < 0x10) {
        Serial.print(F("0"));
        Serial.print(LMIC.frame[LMIC.dataBeg + i], HEX);
    }}
    
}

You need to move the last Serial.print line out of the if statement.

grafik
grafik

    for (int i = 0; i < LMIC.dataLen; i++) {
      if (LMIC.frame[LMIC.dataBeg + i] < 0x10) {
        Serial.print(F("0"));
      }
      Serial.print(LMIC.frame[LMIC.dataBeg + i], HEX);
    }

Is what I use

yes, that worked .Ty very much

Can somebody explain me what they stand for?

LMIC.dataLen = number of Bytes
LMIC.frame= ?
LMIC.dataBeg=?
(LMIC.frame[LMIC.dataBeg + i] = ?

https://github.com/mcci-catena/arduino-lmic/blob/master/doc/LMIC-v2.3.pdf

struct lmic_t {
  u1_t frame[MAX_LEN_FRAME];
  u1_t dataLen; // 0 no data or zero length data, >0 byte count of data
  u1_t dataBeg; // 0 or start of data (dataBeg-1 is port)
  ...
}

And LMIC.frame holds the binary data that was received, as of position dataBeg.

so let me get this straight: LMIC.frame is the content of the byte and dataBeg is the position of the byte
=>
(LMIC.frame[LMIC.dataBeg + i] = Content of a byte at postion i.

LMIC.frame is an array of bytes that is used for almost anything LMIC does. So, it not only holds the optional downlink data, but also the downlink’s port number and maybe even information that is not even related to the downlink at all (say: maybe it even holds the last uplink; I’ve not investigated, but the documentation might tell you more). So, if there was a (possible empty) downlink, then dataBeg tells you where in that array the downlink data starts, and dataLen how many bytes to read, if any.

So, the first byte of the downlink is at position dataBeg, the next at dataBeg + 1, and so on until dataBeg + dataLen - 1. The for (int i = 0; i < LMIC.dataLen; i++) loops variable i from 0 to dataLen - 1.

So, LMIC.frame[LMIC.dataBeg + i] gives you the (i + 1)th byte (when starting to count at one) of the downlink data, if there is any.

Thank you