Downlink Cayenne with MRK1310

Good morning everybody,
I need some help.
I realized a weather station made with an Arduino MKR1310 that send to a Lora TTN Gateway and I see my data on Cayenne.
All is working for several months.
Now, I want to turn on/off one or more outputs on my Arduino.
Can you help me with some examples? I’m using “CayenneLPP.h” format. How I can read the downlink payload and how I can set the button in the web application in Cayenne?

#include <TheThingsNetwork.h>
#include <CayenneLPP.h>

// Set your AppEUI and AppKey
const char *appEui = "xxxx";
const char *appKey = "xxxx";

#define loraSerial Serial1
#define debugSerial Serial

// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan TTN_FP_US915

TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
CayenneLPP lpp(51);

void setup()
{
  loraSerial.begin(57600);
  debugSerial.begin(9600);

  // Wait a maximum of 10s for Serial Monitor
  while (!debugSerial && millis() < 10000)
    ;
  ttn.onMessage(message);

  debugSerial.println("-- STATUS");
  ttn.showStatus();

  debugSerial.println("-- JOIN");
  ttn.join(appEui, appKey);
}
int x;
void loop()
{
  debugSerial.println("-- LOOP");
  x++;
  lpp.reset();
  lpp.addTemperature(1, x);
  lpp.addAnalogOutput(22, 2);
  lpp.addDigitalOutput(7, 1);

  // Send it off
  ttn.sendBytes(lpp.getBuffer(), lpp.getSize());

  delay(10000);
}


void message(const uint8_t *payload, size_t size, port_t port)
{
  debugSerial.println("-- MESSAGE");
  debugSerial.print("Received " + String(size) + " bytes on port " + String(port) + ":");

  for (int i = 0; i < size; i++)
  {
    debugSerial.print(" " + String(payload[i]));
  }

  debugSerial.println();
  if ( payload[2] == 100)
  {
    debugSerial.println("ON");
  }
  else
  {
    debugSerial.println("OFF");
  }
}

Thank you,
the library "TheThingsNetwork.h"doesn’t wok with MKR WAN 1310. I’m using “MKRWAN.h”.
Can you help me?

can you share the library GitHub link and the code you are using?

#include <MKRWAN.h>
#include <CayenneLPP.h>
#include <DHT.h>
#include "ArduinoLowPower.h"
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define DEBUG

LoRaModem modem;
CayenneLPP lpp(51);

const char *appEui = "XXX";
const char *appKey = "XXXXX";


/*--- SETUP ---*/
void setup() {

  Serial.begin(9600);

  if (!modem.begin(EU868)) {
    Serial.println("Failed to start module");
    while (1) {}
  };

#ifdef DEBUG
  Serial.print("Versione del modulo: ");
  Serial.println(modem.version());
  Serial.print("EUI: ");
  Serial.println(modem.deviceEUI());
#endif

  int connected = modem.joinOTAA(appEui, appKey);
  if (!connected) {
    Serial.println("Qualcosa è andato storto; sei all'interno? Vai vicino alla finestra e riprova");
    while (1) {}
  }


  // Set poll interval to 60 secs.
  modem.minPollInterval(60);
}


/*--- LOOP ---*/
void loop() {

    lpp.reset();
    lpp.addTemperature(1, temperatura_esterna);
    lpp.addRelativeHumidity(2, umidita_esterna);
    lpp.addBarometricPressure(3, pressione_esterna);
    lpp.addTemperature(4, temperature);

    lpp.addAnalogInput(5, VWind);
    lpp.addAnalogInput(6, Wind);
    lpp.addAnalogInput(7, Voltage);

    modem.beginPacket();
    modem.write(lpp.getBuffer(), lpp.getSize());
    err = modem.endPacket(true);
if (err > 0) {
      SendData = false;
    } else {
      
    }
   

  LowPower.deepSleep(60000); 
}

-----

MKRWAN.h is the library for MKR1310 in the Arduine IDE

i do see there is a downlink example here MKRWAN/LoraSendAndReceive.ino at master · arduino-libraries/MKRWAN · GitHub

Thank you,
I 'll try it with Cayenne.

just to note the downlink is in the format of

01 0064 FF
Channel 01
Value 1.0

01 0000 FF
Channel 01
Value 0.0
1 Like