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