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.