Downlink to Node with LMIC

Hi

i use a arduino with dragino Shield. This Code works fine:

http://fff-gw-cd1.fff.community/zerobin/?779b5c3d725b208e#dCJtU1i/uJ0JwzEC6DMlCaVmE6BYHUM6EKDw0NVmLkA=

I get the Payload 48656C6C6F2C20776F726C6421 in the TTN Console.

If i send Payload to the Arduino in the console i get the Message in the Arduino seriell console:
33303433: 10EV_TXCOMPLETE (includes waiting for RX windows)
Received
5
bytes of payload

But i have no idea how i see the payload of the message, can anyone help me?

Greets from Germany

Christian

It seems like you sent the number 3043 in ascii, you can use a hex to ascii converter to “decode” the payload

(or do that decoding in your sketch and do something useful with it :slight_smile: )

no i think this is only the ostime (or anything):

void onEvent (ev_t ev) {
Serial.print(os_getTime()); # the Number u see "33303433"
Serial.print(": ");
Serial.print(ev);
switch(ev) {
    ....
    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); # <-- i think the payload is in LMIC.anything but i dont find it?!
          Serial.println(F(" bytes of payload"));
        }...

i have send the message over
https://console.thethingsnetwork.org/applications/XXX/devices/YYY
in the Downlink Input field.

I see only the dataLen but not what payload i send.

If i not send any payload i only see this in de Arduino Seriel Monitor:

Packet queued
437839436: 10EV_TXCOMPLETE (includes waiting for RX windows)
Packet queued
442028291: 10EV_TXCOMPLETE (includes waiting for RX windows)

Received message should be in LMIC.frame with offset LMIC.dataBeg if I recall correctly.

2 Likes

Hi

many thx that was it :slight_smile: Nice thx :slight_smile:

Pleasure on my side!

For future reference, a quick way to print binary content as hexadecimal bytes for debugging:

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();
}

(Maybe Arduino’s offer an easier way.)

Does anyone of you know how the cpp code has to be written to print out the LMIC.dataLen ? We have a RPi as MCU instead of an Arduino - so no ino file.
Here is the cpp example file provided with the Dragino shield that I actually use but not sure if there is any downlink payload sent up to my node. We are investigating this downlink matter, the same salvatore_forte does in another thread.

void onEvent (ev_t ev) {
//debug_event(ev);

switch(ev) {
  // scheduled data sent (optionally data received)
  // note: this includes the receive window!
  case EV_TXCOMPLETE:
      // use this event to keep track of actual transmissions
      fprintf(stdout, "Event EV_TXCOMPLETE, time: %d\n", millis() / 1000);
      if(LMIC.dataLen) { // data received in rx slot after tx
          //debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
          fprintf(stdout, "Data Received!\n");
      }
      break;
   default:
      break;
}

}

Already thanks to anyone for coding this in cpp - we are not familiar with.

if fprintf is available at your platform, then try

fprintf(stdout, "dataLen=%d\n", LMIC.dataLen);

is that what you’ve been looking for?

Something like untested:

if(LMIC.dataLen) { // data received in rx slot after tx
    fprintf(stdout, "Received %d bytes of payload: 0x", LMIC.dataLen);
    for (int i = 0; i < LMIC.dataLen; i++) {
        fprintf(stdout, "%02X", LMIC.frame[LMIC.dataBeg + i]);
    }
    fprintf(stdout, "\n");
}
1 Like

That is it Arjan !
I have tested your cpp code and no problem, the lora node now shows in its console that it receives payload_raw in hex.

The proof of my research is then given : the TTN backend sends data back in downlink via our IMST lora concentrator to the lora device. I guess in its first receive window as the delay is not more than 1s.

Now we can start to do some nice things once we know that the device is able to receive downlink data and store it in its register …

Many tnx for your contribution and also the other comments I have been reading from you on other posts. Always nice and valuable to read.

Just to be sure, not too suppress your enthusiasm, but beware of downlink limitations.

Thanks for this this info, but still I can’t access to what I need.
arjanvanb gave a nice reference to print out downlink message,
but it seems that I can not make use of it (or I’m just not so educated as I should be)

I’m using initial setup Arduino with dragino Shield and OTAA activation sample.
I want to make an if statement for tx payload mydata[] depending on downlink statement. let’s say node received 0x01 in downlink then mydata is “rx works” and if nothing is received than “hello world”

How I can analyze a downlink message and regarding of what bytes node receive it declares some variables?

I’ll send you a PM with an exemple (ABP)

1 Like