Uplink and downlink CayenneLPP payload to TTN using LMIC library

I have just gotten acquainted with Lora. I’m having some queries about programming correctly to uplink and downlink the Cayenne LPP payload to TTN in the example of LMIC library. I’m using the CayenneLPP library and OTAA method. I looked for some references on the Internet but it just provides the overview and seems to have no specific example on implementing with LMIC library. Hope to get your help. Thank you.

which device are you using? You can first get it connected to TTN using GitHub - mcci-catena/arduino-lmic: LoraWAN-MAC-in-C library, adapted to run under the Arduino environment
Once done we can tweak the code to send data to cayenne.

Hi, thanks for your concern about my post. I’ve already installed and succeed in connecting to TTN. I’m just getting trouble at the next step you mentioned is how to tweak the code in order to send and download CayenneLPP payload using CayenneLpp library from TTN?

for the above lmic library add this code and replace the do_send function. this is just an example sending random temperature and analog value.

#include <CayenneLPP.h>
CayenneLPP lpp(51);


void do_send(osjob_t* j) {
  // Check if there is not a current TX/RX job running
  if (LMIC.opmode & OP_TXRXPEND) {
    Serial.println(F("OP_TXRXPEND, not sending"));
  } else {
    // Prepare upstream data transmission at the next possible time.
    lpp.reset();
    lpp.addTemperature(1, 123));
    lpp.addAnalogInput(4, 123);
    LMIC_setTxData2(1, lpp.getBuffer(), lpp.getSize(), 0);
    Serial.println(F("Packet queued"));
  }
  // Next TX is scheduled after TX_COMPLETE event.
}
1 Like

What about on the rest side? I still can’t imagine the routine of getting data that Cayenne feed to TTN. So i have some questions to be more understanding on it. Hope you clarify it:

  1. Suppose that I want to get the button state on Cayenne so addDigitalInput is the first step?
  2. Then, a button should appear on the Cayenne dashboard and automatically send its state over to TTN within a time interval?
  3. How should I adjust my code for getting that value on TTN?

Correct, This will add the downlink data in the queue for the device to receive it.

the Lmic code already handle the downlink in the EV_TXCOMPLETE case.

Yeah, I’ve ready known it. I just wonder how can we program to recognize that data? Thanks.

You helped me so much. Thanks a million

can you share the data format that is received ??

The data format should follow the structure of the Cayenne payload that is defined in the document of myDevices.


I got an idea to implement it but don’t know whether it’s true. Firstly, I’ll have lpp.addDigitalInput(1,0) where: 1 is channel ID but 0 will represent for what and where to add this line? Still, be stuck in there. After that, depending on the data received from TTN, I will compare the first byte in EV-TXCOMPLETE with the ID that is assigned for digital input before and get the third byte for handling later? Am I correct? Hope you respond soon.

the downlink payload is in this format:-

01 0064 FF. Channel 01 Value (0064) 1.0
01 0000 FF Channel 01 Value(0000) 0.0

FF byte is not necessary.

I got it. Just one more question, I’m aware that it’s needed to use lpp.addDigitalInput(1,0) to make the button show up on the Cayenne dashboard but still not sure where to add it. Is it on do_send() function or somewhere else? Moreover, in the lpp.addDigitalInput(1,0) where 1 means channel ID and 0 represent for value, but what is this value? Is this the one we send for digital Input on Cayenne. Sound a bit of conflict because I want it as a virtual button and send this input to my node. Am I misunderstanding at something?

to create a button you need to send the correct data type. For button it will be lpp.addDigitalInput(1,0) where 1 is the channel and 0 is the one time data. once done you can read the button status with decoding the above downlink format

1 Like