mkr 1300, the things network and mydevices cayenne

Hello! I don´t know what is wrong, but I can´t connect my MKR 1300 mydevices cayenne. I´m using the code and the libraries given by cayenne and TTN, but I can´t connect to TTN and mydevices cayenne.
With another code I can connect to TTN without problem, but I can´t whit the second.
The code I used and doesn´t work is:

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

// Set your AppEUI and AppKey
const char *appEui = " ";   // I added the code, don´t worry about that
const char *appKey = " ";

#define loraSerial Serial1
#define debugSerial Serial

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

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

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

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

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

  debugSerial.println("-- JOIN");
  ttn.join(appEui, appKey);
}

void loop()
{
  debugSerial.println("-- LOOP");

  lpp.reset();
  lpp.addTemperature(1, 22.5);
  lpp.addBarometricPressure(2, 1073.21);
  lpp.addGPS(3, 52.37365, 4.88650, 2);

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

  delay(10000);
}

Has someone done the conection with this device to mydevices cayenne throught TTN??
Thanks!

pablodg92:
With another code I can connect to TTN without problem

Please post the working code.

Post a link to where you got the libraries from. Please use the chain links icon on the toolbar to make it clickable. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

pablodg92:
I´m using the code and the libraries given by cayenne and TTN

Are you saying this is the unmodified example code that comes with one of the libraries?

pablodg92:
// Send it off
ttn.sendBytes(lpp.getBuffer(), lpp.getSize());
delay(10000);

Are you sending the data every 10 seconds ?

The working code is:

#include <MKRWAN.h>
#include "arduino_secrets.h"   //another tab to get the appEui and appKey
int intensidad = 3;
// Select your region (AS923, AU915, EU868, KR920, IN865, US915, US915_HYBRID)
_lora_band region = EU868;

LoRaModem modem(Serial1);

void setup() {
  Serial.begin(115200);
  while (!Serial);
  if (!modem.begin(region)) {
    Serial.println("Failed to start module");
    while (1) {}
  };
  Serial.print("Your device EUI is: ");
  Serial.println(modem.deviceEUI());

  int connected = modem.joinOTAA(appEui, appKey);
  if (!connected) {
    Serial.println("Something went wrong; are you indoor? Move near a window and retry");
    while (1) {}
  }
  Serial.println("Successfully joined the network!");
}

void loop() {
  modem.beginPacket();
  modem.print(intensidad);
  int err = modem.endPacket(false);

  if (err > 0) {
    Serial.println("Big success!");
  } else {
    Serial.println("Error");
  }
  delay(1000 * 60);
}

I´m using the Libraries from the Library Manager, the names are TheThingsNetwork and CayenneLPP.

I´m using the code given by TheThingsNetwork or Mydevices cayenne, I didn´t remember, I just added the terms I need.

srnet:
Are you sending the data every 10 seconds ?

I think the programme do this, but the reality is the programme just serial.print --STATUS, and do nothing more. I don´t recibe any information or attempt to connect in the TTN´s data board.

pablodg92:
I think the programme do this.

Sounds like a contradiction with the 'free to use' TTN system fair use policy;

"A good goal is to keep the application payload under 12 bytes, and the interval between messages at least several minutes."

If everyone sent their data every 10 seconds the 'free to use' TTN system would probably collapse.

Also bear in mind that legal duty cycle requirements need to be followed, these can be as low as 1% so you may not be premitted to send your data that often in any case.

I tried lowering the payload and raising the time, but just once the programme changed and in the serial appear:
--STATUS
UEI:

instead just --STATUS, how it was appearing before.
I don´t now what is happening, I´m trying all things and looking in a lot of differents webpages and forum, but nothing happend.

Did you ever find out the answer to this? I'm having the same problem now :frowning:

I was getting the error that I needed to include the #include <pgmspace.h> library, which i subsequently installed. Though now, it's giving me a whole new host of errors.

To my opinion -aside of the issue with sending data too frequently- is that your code obviously refers to The Things Uno device based on the TheThingsNetwork library <TheThingsNetwork.h>. This library however requires the use of a LoRa Module controlled via a UART. TheThingsUno uses an Arduino Leonardo that controls the RN2483 Lora Module via the Serial1 UART interface. The Arduino MKR WAN however uses an CMWX1ZZABZ LoRa Module that is controlled via a SPI interface which is handled inside the <MKRWAN.h> library. Therefore, you need to use the <MKRWAN.h> library together with Cayenne. This means, instead of sending the data with :

ttn.sendBytes(lpp.getBuffer(), lpp.getSize());

you have to use the following call from the MKRWAN library:

modem.write(lpp.getBuffer(), lpp.getSize());

A working code example derived from the MKRWAN Library Send and Receive Example is the following:

/*
  Lora Send And Receive
  This sketch demonstrates how to send and receive data with the MKR WAN 1300 LoRa module.
  This example code is in the public domain.
*/

#include <MKRWAN.h>
#include <CayenneLPP.h>

LoRaModem modem;
CayenneLPP lpp(51);

// Uncomment if using the Murata chip as a module
// LoRaModem modem(Serial1);

//#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
String appEui = " *** ";
String appKey = " *** ";

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  
  pinMode(LED_BUILTIN, OUTPUT);        //sign of live
  for (int i=1; i<=10; i++) {           
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);                       // wait for a second
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
    delay(1000);
    // wait for a second
    Serial.println(10-i);
  }
  
  // change this to your regional band (eg. US915, AS923, ...)
  if (!modem.begin(EU868)) {
    Serial.println("Failed to start module");
    while (1) {}
  };
  Serial.print("Your module version is: ");
  Serial.println(modem.version());
  Serial.print("Your device EUI is: ");
  Serial.println(modem.deviceEUI());

  int connected = modem.joinOTAA(appEui, appKey);
  if (!connected) {
    Serial.println("Something went wrong; are you indoor? Move near a window and retry");
    while (1) {}
  }

  // Set poll interval to 60 secs.
  modem.minPollInterval(60);
  // NOTE: independently by this setting the modem will
  // not allow to send more than one message every 2 minutes,
  // this is enforced by firmware and can not be changed.
}

void loop() {
  int err;
  
  lpp.reset();
  lpp.addTemperature(1, 22.5);
  modem.beginPacket();
  modem.write(lpp.getBuffer(), lpp.getSize());
  err = modem.endPacket(true);
  if (err > 0) {
    Serial.println("Message sent correctly!");
  } else {
    Serial.println("Error sending message :(");
    Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength");
    Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)");
  }
  delay(1000);
  if (!modem.available()) {
    Serial.println("No downlink message received at this time.");
  }
  else {
    String rcv;
    rcv.reserve(64);
    while (modem.available()) {
      rcv += (char)modem.read();
    }
    Serial.print("Received: " + rcv + " - ");
    for (unsigned int i = 0; i < rcv.length(); i++) {
      Serial.print(rcv[i] >> 4, HEX);
      Serial.print(rcv[i] & 0xF, HEX);
      Serial.print(" ");
    }
    Serial.println();
  }
  Serial.println("waiting 60 seconds");
  for (int i=1; i<=60; i++) { //wait a minute
    Serial.println(i);
    delay(1000); 
  }  
}