MKR 1300 RTC and LoRa Issues.

Background: I want to create an energy meter that takes reading at every minute and then sends it every 5 minutes.

Problem is, it's not sending, no matter what.

No idea why but if I remove rtc it starts working again:

Here's the code:

#include <EmonLib.h>
#include <RTCZero.h>
#include <MKRWAN.h>


EnergyMonitor emon1;
EnergyMonitor emon2;
EnergyMonitor emon3;
RTCZero rtc;
LoRaModem modem;

String appEui = "1234567891011121";
String appKey = "ffffffffffffffffffffffffffffffff";

/* INITIAL_TIME */
const byte seconds = 0;
const byte minutes = 0;
const byte hours = 0;
const byte day = 17;
const byte month = 12;
const byte year = 18;


byte second_alarm = 0;
byte minute_alarm = 0;
byte hour_alarm = 0;
byte INTERVAL = 60;
int SEND_LOOP = 2;

int totalKW;
int time_running = 0;

void setup()
{
  Serial.begin(115200);
  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());

  Serial.println("Connecting");
  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("Connected");

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

  analogReadResolution(9);
  emon1.current(1, 53);
  emon2.current(2, 53);
  emon3.current(3, 53);
  time_running = 0;

  rtc.begin(); // initialize RTC

  rtc.setAlarmTime(hour_alarm, minute_alarm, second_alarm);
  rtc.enableAlarm(rtc.MATCH_HHMMSS);
  rtc.attachInterrupt(ISR);

  // Set the time
  rtc.setHours(hours);
  rtc.setMinutes(minutes);
  rtc.setSeconds(seconds);

  // Set the date
  rtc.setDay(day);
  rtc.setMonth(month);
  rtc.setYear(year);


}

void loop()
{
}

void ISR() {

  int totalWatt = 0;
  unsigned long delay_send = 0;
  int sending = 0;

  double Irms1 = emon1.calcIrms(600);
  if (Irms1 < 0.3) Irms1 = 0;
  double Watt1 = Irms1 * 230;

  double Irms2 = emon2.calcIrms(600);
  if (Irms2 < 0.3) Irms2 = 0;
  double Watt2 = Irms2 * 230;

  double Irms3 = emon3.calcIrms(600);
  if (Irms3 < 0.3) Irms3 = 0;
  double Watt3 = Irms3 * 230;

  totalWatt = Watt1 + Watt2 + Watt3;
  totalKW = totalKW + totalWatt / 1000;
  Serial.println(time_running);

  sendDataChecker();
  setAlarm();
  time_running = time_running + 1;
}

void sendDataChecker() {
  if (time_running == SEND_LOOP) { 
    double IrmsTotal = Irms1 + Irms2 + Irms3;
    String msg = "{\"id\":\"avac_aud1\",\"kW\":" + String(totalKW) + ", \"current\":" + String(IrmsTotal) + "}";
    int err;
    Serial.println("Ready to Send");
    modem.beginPacket();
    modem.print(msg);
    err = modem.endPacket(true);
    Serial.println("Sent1");
    if (err > 0) {
      //message sent correctly
      Serial.println("Sent");
      time_running = 0;
      totalKW = 0;
    } else {
      Serial.println("ERR");
      time_running = 0;
    }
  }
}

void setAlarm() {
  second_alarm += INTERVAL;
  if (second_alarm >= 60) {
    minute_alarm++;
    second_alarm = 0;
  }
  if (minute_alarm >= 60) {
    hour_alarm++;
    minute_alarm = 0;
  }
  if (hour_alarm >= 24) {
    hour_alarm = 0;
  }

  rtc.setAlarmTime(hour_alarm, minute_alarm, second_alarm);
}

And here's the output:

Connected
0
1
18:13:33.158 -> Ready to Send

Your maybe assuming that the forum realises your attempting to use The Things Network (TTN), there maybe a few people in here who understand the TTN stuff, but I have not see much comment or activity in here.

There is of course a forum specifically for the support of TTN applications.

You may also missunderstand how TTN works, you might decide that you want to send information across this free to use network at an interval thats suits, but there is the fair access policy to adhere to.

Have you asked the company that supplied you the MKR1300 for advice ?

I'm not using TTN it's a gateway outside of the TTN's grid so it's internal only, as for the intervals without RTC I have been sending stuff every 5 minutes but for tests I normally send them at every minute so that's not an issue, this simply stopped working when I added RTC to the mix.

As for the company advice, I might actually do that too. But if someone has come across this issue I would love to know how they fixed it cause right now i'm basically using the normal cpu frequency.