Receiving data in Cayenne LPP format using LMIC library

Hi there,
I using LMIC library and CayenneLPP library for sending out data including temperature and light status to TTN in LPP format and showing its appropriate widget on CayenneLPP dashboard. I have already been aware of programming it by adding some code at do_send() function but still been confused in adding a virtual button on Cayenne dashboard and adjusting LMIC example code to receive its current value from there for my own purpose. Your assistance will be appreciated.

Look for the onEvent function, particularly this part:

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

You can insert your own function where the Serial.print’s are. You’ve got LMIC.dataLen that tells you how many bytes were received. The data is in a byte array called LMIC.frame with an index in to the array called LMIC.dataBeg.

So the first byte will be at LMIC.frame[LMIC.dataBeg], the second at LMIC.frame[LMIC.dataBeg+1] etc.

The byte array is exactly what you send, it’s up to you to come up with a format that works for you, that you can send from the Cayenne dashboard and interpret on the device.

Please bear in mind the fair use policy for downlinks, that they only arrive just after a device has uplinked and that delivery is not guaranteed, so should not be used for critical systems.

Thanks. Your help was really useful. I struggled with LMIC.frame and LMIC.dataBeg meaning for days but it’s straightforward for now. Nevertheless, we have to upload digital Input on the dashboard first and I’m still questioning how can we do it? I saw “lpp.addDigitalInput(1,0)” as a predefined function on the Cayenne library but don’t know where in the whole program I can add it. And also, the second parameter, 0 means the value (as noted by the writer) sent to Cayenne while we’re receiving this digitalInput from Cayenne? A bit of conflict here. Hope you clarify it.

To create any output in the cayenne dashboard you need to add it to the uplink data at least once. (Yes, you create downlink fields by sending them in the uplink data)

Add bytes 00 01 00 to your uplink to create the digital output,

However you seem to be getting the answers on the mydevices forum already so please don’t waste our time by asking the same questions here as well.

1 Like