# MKR GSM 1400 Phone-enabled Garage Opener Issues

**URL:** <https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373>\
**Category:** General Guidance\
**Created:** [April 22, 2023, 5:39pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373 "2023-04-22T17:39:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [April 22, 2023, 5:39pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/1 "2023-04-22T17:39:47Z")

</div>

**Please note:**  
I've tried my best to explain the situation in its fullest with all necessary details. If you do have any questions, feel free to ask and I will try to clarify.

**The situation:**  
So I've been having issues with my project for over two years now, and I'm finally seeking help. I hope I'm in the right category with this.

I own a holiday home in a residential apartment building with an underground parking garage for residents only. This garage has an electric garage door that is controlled with remote controls. Each resident only gets 2 remotes.

Since not only I myself, but also my parents, brothers and aunt/uncle come visit this holiday home, we would need more remotes for every car. I've tried to copy a remote and duplicate it, but the problem is that this system requires remotes to be linked with the central computer and they use a rolling code to secure it so I can only use original remotes.

**My solution:**  
I thought of buying an Arduino MKR GSM 1400 to which I would connect a relay, to which in turn I would connect a remote. This way I could short the remote using a relay which would be controlled by the Arduino.

I programmed the Arduino to connect to the GSM network, and control the relay when specific phone numbers would call the Arduino. By whitelisting certain phone numbers I could prevent the misusage by only allowing certain people's phone number to open the garage door.

The only thing I did have to make sure was that the SIM card I had inserted in the module would send out a text message at least once every 3 months. This is because the SIM card would otherwise get disabled by the provider if not used regularly. I programmed the Arduino to send myself a text message once every 3 months.

Also I programmed it to flush every text message it gets (in case it ever gets one) since it doesn't need it.

**The issue:**  
When I set this up about two years ago, the system worked fine. Only once in a while the board would lose connection and I would restart the board after which it would work again. Then I tried to program the board to reset/restart itself when it would lose connection. That's when the issues started.

I cannot get the board to have a stable connection with the GSM network, nor can I have it reliably restart whenever it loses connection. I have no idea why the board will not remain connected, nor do I know why it cannot simply restart when it loses connection. I've tried so many versions of my code, but none would result in a stable reliable setup.

The board will connect, establish a connection and work as intended for an arbitrary amount of times before it will fail after which it is supposed to restart but it won't or will not re-establish connection. This is the issue.

**The hardware:**

- Arduino MKR GSM 1400
- Arduino MKR Relay Shield (Please note that the Arduino is properly plugged in the Relay shield as is intended, I just couldn't make that clear on the schematic visual)
- Dipole Pentaband Waterproof Antenna
- Lithium Ion Polymer Battery - 3.7v 2500mAh [KW-1480]
- Hörmann RSM4-433 remote
- Raspberry Pi 12.5W Micro USB Power Supply

Please note that by advice of many on the internet I have supplied the board with a powerful enough power supply (12.5W) and also a LiPo battery to handle any peak-currents caused by the GSM signal.

**The setup (schematic):**

 ![Arduino MKRGSM Schematic](https://europe1.discourse-cdn.com/arduino/original/4X/5/1/5/515c41e5eccbc555a95f547b26532b7baa3c4832.jpeg)

**The code:**  
Please note I have censored the actual phone numbers of me and my family.

```plaintext
#include <MKRGSM.h>
#include <TimeLib.h>

// GSM and GPRS instances
GSM gsmAccess;
GPRS gprs;
GSMScanner GSMScan;
GSMVoiceCall voiceCall;
GSM_SMS sms;

// Relay and LED pins
const int relayPin = 1;
char PINNUMBER [] = ""; // PIN-Code of the Simcard
const int ledPin = LED_BUILTIN;

// Whitelisted numbers
const char *whitelist[] = {"+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789"};
const int whitelistSize = sizeof(whitelist) / sizeof(whitelist[0]);

// Phone number to send text message
const char *textMessagePhoneNumber = "+00123456789";

// Pre-composed text message
const char *textMessage = "This is an automated message. I'm online.";

// Variables for text message sending interval
int lastSentMonth = -1;

bool connected = false;
unsigned long lastGSMCheck = 0;
unsigned long checkInterval = 60000; // Check connection every 30 seconds
unsigned long reconnectTimeout = 60000; // 30 seconds timeout

void setup() {
  bool connected = false;
  pinMode(relayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);

  Serial.println("Booting.");
  delay(5000); // Give the GSM module some time to initialize
  int retries = 0;
  const int maxRetries = 5;

  while (!connected && retries < maxRetries) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      connected = true;
    } else {
      connected = false;
      Serial.println("Not connected");
      retries++;
      delay(1000);
    }
  }

  if (retries >= maxRetries) {
    Serial.println("Failed to connect after maximum retries. Restarting the board.");
    NVIC_SystemReset();
  } else {
    digitalWrite(ledPin, HIGH); // Solid: connected
    Serial.println("GSM initialized.");
    Serial.println("Awaiting Call.");
    Serial.println("");
  }
}

void loop() {
  unsigned long currentTime = millis();
  if ((currentTime - lastGSMCheck) >= checkInterval) {
    lastGSMCheck = currentTime;
    checkGSMConnection();
  }

  Serial.println(GSMScan.getSignalStrength());
  checkForVoiceCall();
  checkForTextMessage();
  sendTextMessageEveryThreeMonths();
}

void checkGSMConnection() {
  if (gsmAccess.isAccessAlive() != GSM_READY) {
    connected = false;
    Serial.println("Connection lost. Trying to reconnect...");

    unsigned long reconnectStartTime = millis();
    while (!connected && (millis() - reconnectStartTime) < reconnectTimeout) {
      connectToCarrier();
      delay(500); // Short delay between reconnection attempts
    }

    if (!connected) {
      Serial.println("Reconnection failed. Restarting device...");
      NVIC_SystemReset();
    } else {
      Serial.println("Reconnected successfully.");
    }
  }
}

void connectToCarrier() {
  digitalWrite(ledPin, LOW); // Turn LED off.

  // Start GSM connection
  if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
    connected = true;
    Serial.println("\nConnected to carrier.");
    digitalWrite(ledPin, HIGH); // Solid LED: connected
  } else {
    connected = false;
    Serial.println("Not connected");
    delay(1000);
  }
}

void checkForVoiceCall() {
  if (voiceCall.getvoiceCallStatus() == RECEIVINGCALL) {
    char phoneNumber[20];
    voiceCall.retrieveCallingNumber(phoneNumber, 20);

    bool isWhitelisted = false;
    for (int i = 0; i < whitelistSize; i++) { 
      if (strcmp(phoneNumber, whitelist[i]) == 0) {
        isWhitelisted = true;
        break;
      }
    }

    voiceCall.hangCall();

    if (isWhitelisted) { // If whitelisted person calls, activate the relay.
      activateRelay();

      delay(10000);

      NVIC_SystemReset(); // I've tried the code with and without this line. I was trying whether it would be better to just restart the whole setup everytime some had called, it made no difference.
    }
  }
}

void checkForTextMessage() {
  if (sms.available()) {
    char phoneNumber[20];
    sms.remoteNumber(phoneNumber, 20);

    sms.flush(); // Flush the message
  }
}

void activateRelay() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(relayPin, HIGH);
    delay(2000);
    digitalWrite(relayPin, LOW);
    delay(250);
  }
}

void sendTextMessageEveryThreeMonths() {
  time_t currentTime = gsmAccess.getTime();
  int currentMonth = month(currentTime);
  int currentDay = day(currentTime);

  if ((currentMonth - lastSentMonth) % 3 == 0 && currentDay == 1 && currentMonth != lastSentMonth) {
    Serial.print("Send Textmessage. Online.");

    sms.beginSMS(textMessagePhoneNumber);
    sms.print(textMessage);
    sms.endSMS();
    Serial.println("\nCOMPLETE!\n");

    lastSentMonth = currentMonth;
  }
}

```

Thank you very much for taking the time to read about my project and I hope someone is able to help 🙂

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [April 22, 2023, 6:12pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/2 "2023-04-22T18:12:36Z")

</div>

We don't don't know the reason for the concierge to refuse You what You want.  
Helping members to break rules, laws etc. is usually not supported.  
No problem for me as the question is outside my territory.

---

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [April 22, 2023, 6:17pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/3 "2023-04-22T18:17:51Z")

</div>

I'm not breaking any rules though. There are still the same number of remotes and no one that is not supposed to get access is getting access. I'm just letting me and my family enter our own home, for that is only reasonable.

---

<div class="post-metadata">

**Author:** ![Hutkikz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hutkikz/32/218764_2.png) [@Hutkikz](https://forum.arduino.cc/u/Hutkikz)\
**Post date:** [April 22, 2023, 8:26pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/4 "2023-04-22T20:26:28Z")

</div>

I'm gonna guess that your are not able to get the Serial.print debug statements while the device is in service. One way to partially get around that is to send texts. At least you'll know how often it does reconnect and a better idea of when it fails. Another option is to use the [FlashStorage\_SAMD library](https://github.com/khoih-prog/FlashStorage_SAMD) to emulate EEprom and save debug information there to be retrieved later(send a text when restarted).

There are 2 separate pieces of code that connect to GSM. One in setup() and the other in connectToCarrier().  
Something felt off in the function code but I'm not sure what.

So I removed the code from setup() and put it in the connectToCarrier() function.

Removed the checkGSMConnection() function and just put a quick check in loop().

IDK give it a shot.

```plaintext
#include <MKRGSM.h>
#include <TimeLib.h>

// GSM and GPRS instances
GSM gsmAccess;
GPRS gprs;
GSMScanner GSMScan;
GSMVoiceCall voiceCall;
GSM_SMS sms;

// Relay and LED pins
const int relayPin = 1;
char PINNUMBER [] = ""; // PIN-Code of the Simcard
const int ledPin = LED_BUILTIN;

// Whitelisted numbers
const char *whitelist[] = {"+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789"};
const int whitelistSize = sizeof(whitelist) / sizeof(whitelist[0]);

// Phone number to send text message
const char *textMessagePhoneNumber = "+00123456789";

// Pre-composed text message
const char *textMessage = "This is an automated message. I'm online.";

// Variables for text message sending interval
int lastSentMonth = -1;

bool connected = false;
unsigned long lastGSMCheck = 0;
unsigned long checkInterval = 60000; // Check connection every 30 seconds
unsigned long reconnectTimeout = 60000; // 30 seconds timeout

void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);

  Serial.println("Booting.");
  delay(5000); // Give the GSM module some time to initialize
  connectToCarrier();
}

void loop() {
  
  // Check GSM connection
  if (gsmAccess.isAccessAlive() != GSM_READY) {
    digitalWrite(ledPin, LOW); // Turn LED off.
    Serial.println("Connection lost. Trying to reconnect...");
    connectToCarrier();
  }
  
  Serial.println(GSMScan.getSignalStrength());
  checkForVoiceCall();
  checkForTextMessage();
  sendTextMessageEveryThreeMonths();
}

void connectToCarrier() {
  bool connected = false;
  int retries = 0;
  const int maxRetries = 5;

  while (!connected && retries < maxRetries) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      connected = true;.
      digitalWrite(ledPin, HIGH); // Solid: connected
      Serial.println("GSM initialized.");
      Serial.println("Awaiting Call.");
      Serial.println("");
    } else {
      connected = false;
      Serial.println("Not connected");
      retries++;
      delay(1000);
    }
  }

  if (retries >= maxRetries) {
    Serial.println("Failed to connect after maximum retries. Restarting the board.");
    NVIC_SystemReset();
  }
}

void checkForVoiceCall() {
  if (voiceCall.getvoiceCallStatus() == RECEIVINGCALL) {
    char phoneNumber[20];
    voiceCall.retrieveCallingNumber(phoneNumber, 20);

    bool isWhitelisted = false;
    for (int i = 0; i < whitelistSize; i++) {
      if (strcmp(phoneNumber, whitelist[i]) == 0) {
        isWhitelisted = true;
        break;
      }
    }

    voiceCall.hangCall();

    if (isWhitelisted) { // If whitelisted person calls, activate the relay.
      activateRelay();

      delay(10000);

      NVIC_SystemReset(); // I've tried the code with and without this line. I was trying whether it would be better to just restart the whole setup everytime some had called, it made no difference.
    }
  }
}

void checkForTextMessage() {
  if (sms.available()) {
    char phoneNumber[20];
    sms.remoteNumber(phoneNumber, 20);

    sms.flush(); // Flush the message
  }
}

void activateRelay() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(relayPin, HIGH);
    delay(2000);
    digitalWrite(relayPin, LOW);
    delay(250);
  }
}

void sendTextMessageEveryThreeMonths() {
  time_t currentTime = gsmAccess.getTime();
  int currentMonth = month(currentTime);
  int currentDay = day(currentTime);

  if ((currentMonth - lastSentMonth) % 3 == 0 && currentDay == 1 && currentMonth != lastSentMonth) {
    Serial.print("Send Textmessage. Online.");

    sms.beginSMS(textMessagePhoneNumber);
    sms.print(textMessage);
    sms.endSMS();
    Serial.println("\nCOMPLETE!\n");

    lastSentMonth = currentMonth;
  }
}
```

---

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [April 23, 2023, 7:11am UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/5 "2023-04-23T07:11:27Z")

</div>

Thank you for your reply! I have immediately tested your code now to see if it would improve stability. It does make sense to not put that code twice indeed.

Just to give more context; mostly what happened with my code is that the device will boot, connect to a carrier and wait for a call perfectly fine, only when I've called it maybe once or twice will it do one of two things. It either:

- loses connection at a random moment and then fail to reconnect
- or, it will lose connection _exactly_ when I call it, then it will try to reconnect and mostly it will succeed after which it will work for exactly 1 time again. Then when I call it again it will lose connection and the cycle repeats.

I've tried to log signal strength when I call it simultaneously, it almost always outputs a signal strength of around 28-30 with GSMScan.getSignalStrength().  
It will just randomly lose connection, most of the times though triggered by someone calling.

Back to testing your code, unfortunately that did not improve stability. It establishes connection with a carrier after which it immediately loses it and reconnects. This is the output of the serial:

```plaintext
08:53:37.939 -> GSM initialized.
08:53:37.939 -> Awaiting Call.
08:53:37.939 -> 
08:53:37.939 -> 28
08:53:38.700 -> Connection lost. Trying to reconnect...
08:53:53.189 -> Not connected
08:54:09.264 -> GSM initialized.
08:54:09.264 -> Awaiting Call.
08:54:09.264 -> 
08:54:09.299 -> 29
08:54:11.097 -> Connection lost. Trying to reconnect...
08:54:25.587 -> GSM initialized.
08:54:25.587 -> Awaiting Call.
08:54:25.587 -> 
08:54:25.587 -> 28
08:54:25.587 -> Connection lost. Trying to reconnect...
08:54:48.618 -> GSM initialized.
08:54:48.618 -> Awaiting Call.
08:54:48.618 -> 
08:54:48.618 -> 28
08:54:48.618 -> Connection lost. Trying to reconnect...
08:54:56.470 -> GSM initialized.
08:54:56.470 -> Awaiting Call.
08:54:56.470 -> 
08:54:56.470 -> 29
08:54:56.470 -> Connection lost. Trying to reconnect...
08:55:11.262 -> Not connected
08:55:28.391 -> GSM initialized.
08:55:28.391 -> Awaiting Call.
08:55:28.391 -> 
08:55:28.391 -> 28
08:55:29.511 -> Connection lost. Trying to reconnect...
08:55:43.927 -> Not connected
08:55:59.280 -> Not connected
08:56:15.811 -> Not connected
08:56:39.495 -> GSM initialized.
08:56:39.495 -> Awaiting Call.
08:56:39.495 -> 
08:56:39.495 -> 28
08:56:39.495 -> Connection lost. Trying to reconnect...
08:56:51.220 -> GSM initialized.
08:56:51.220 -> Awaiting Call.
08:56:51.220 -> 
08:56:51.220 -> 28
08:56:53.879 -> Connection lost. Trying to reconnect...
08:57:07.068 -> GSM initialized.
08:57:07.068 -> Awaiting Call.
08:57:07.068 -> 
08:57:07.068 -> 29
08:57:07.068 -> Connection lost. Trying to reconnect...
08:57:25.584 -> GSM initialized.
08:57:25.584 -> Awaiting Call.
08:57:25.584 -> 
08:57:25.584 -> 28
08:57:25.584 -> Connection lost. Trying to reconnect...
08:57:37.344 -> GSM initialized.
08:57:37.344 -> Awaiting Call.
08:57:37.344 -> 
08:57:37.344 -> 28
08:57:39.913 -> Connection lost. Trying to reconnect...
08:57:54.219 -> GSM initialized.
08:57:54.219 -> Awaiting Call.
08:57:54.219 -> 
08:57:54.219 -> 28
08:57:54.219 -> Connection lost. Trying to reconnect...
08:58:09.239 -> GSM initialized.
08:58:09.239 -> Awaiting Call.
08:58:09.239 -> 
08:58:09.239 -> 28
08:58:09.959 -> Connection lost. Trying to reconnect...
08:58:33.590 -> GSM initialized.
08:58:33.590 -> Awaiting Call.
08:58:33.590 -> 
08:58:33.590 -> 28
08:58:33.590 -> Connection lost. Trying to reconnect...
08:58:48.692 -> GSM initialized.
08:58:48.692 -> Awaiting Call.
08:58:48.692 -> 
08:58:48.692 -> 29
08:58:48.692 -> Connection lost. Trying to reconnect...
08:58:58.053 -> GSM initialized.
08:58:58.053 -> Awaiting Call.
08:58:58.053 -> 
08:58:58.053 -> 29
08:58:59.127 -> Connection lost. Trying to reconnect...
08:59:21.592 -> GSM initialized.
08:59:21.592 -> Awaiting Call.
08:59:21.592 -> 
08:59:21.592 -> 29
08:59:21.592 -> Connection lost. Trying to reconnect...
08:59:32.383 -> GSM initialized.
08:59:32.383 -> Awaiting Call.
08:59:32.383 -> 
08:59:32.383 -> 28
08:59:32.383 -> Connection lost. Trying to reconnect...
09:00:03.087 -> GSM initialized.
09:00:03.087 -> Awaiting Call.
09:00:03.087 -> 
09:00:03.087 -> 29
09:00:03.087 -> Connection lost. Trying to reconnect...
09:00:12.834 -> GSM initialized.
09:00:12.834 -> Awaiting Call.
09:00:12.834 -> 
09:00:12.834 -> 29
09:00:12.834 -> Connection lost. Trying to reconnect...
09:00:18.350 -> Not connected
09:00:33.556 -> Not connected
09:00:48.724 -> Not connected
09:01:03.935 -> Not connected
09:01:19.156 -> Not connected
09:01:20.159 -> Failed to connect after maximum retries. Restarting the board.
09:01:40.022 -> Not connected
09:01:56.424 -> GSM initialized.
09:01:56.424 -> Awaiting Call.
09:01:56.424 -> 
09:01:56.424 -> Connection lost. Trying to reconnect...
09:02:12.033 -> GSM initialized.
09:02:12.033 -> Awaiting Call.
09:02:12.033 -> 
09:02:12.033 -> 29
09:02:12.815 -> Connection lost. Trying to reconnect...
09:02:27.059 -> Not connected
09:02:44.656 -> GSM initialized.
09:02:44.656 -> Awaiting Call.
09:02:44.656 -> 
09:02:44.696 -> 29
09:02:45.433 -> Connection lost. Trying to reconnect...
09:03:01.231 -> GSM initialized.
09:03:01.231 -> Awaiting Call.
09:03:01.231 -> 
09:03:01.264 -> 29
09:03:02.028 -> Connection lost. Trying to reconnect...
09:03:19.222 -> GSM initialized.
09:03:19.222 -> Awaiting Call.
09:03:19.222 -> 
09:03:19.222 -> 28
09:03:19.222 -> Connection lost. Trying to reconnect...
09:03:33.233 -> GSM initialized.
09:03:33.233 -> Awaiting Call.
09:03:33.233 -> 
09:03:33.233 -> 29
09:03:34.011 -> Connection lost. Trying to reconnect...
09:03:48.978 -> GSM initialized.
09:03:48.978 -> Awaiting Call.
09:03:48.978 -> 
09:03:49.021 -> 29
09:03:49.800 -> Connection lost. Trying to reconnect...
09:04:04.973 -> GSM initialized.
09:04:04.973 -> Awaiting Call.
09:04:04.973 -> 
09:04:05.014 -> 28
09:04:05.789 -> Connection lost. Trying to reconnect...
09:04:23.263 -> GSM initialized.
09:04:23.263 -> Awaiting Call.
09:04:23.263 -> 
09:04:23.263 -> 29
09:04:23.263 -> Connection lost. Trying to reconnect...
09:04:42.861 -> Not connected
09:04:54.416 -> GSM initialized.
09:04:54.416 -> Awaiting Call.
09:04:54.416 -> 
09:04:54.416 -> 29
09:04:54.416 -> Connection lost. Trying to reconnect...
09:05:08.616 -> GSM initialized.
09:05:08.616 -> Awaiting Call.
09:05:08.616 -> 
09:05:08.656 -> 29
09:05:09.419 -> Connection lost. Trying to reconnect...
09:05:23.699 -> Not connected
09:05:38.984 -> Not connected
09:06:13.266 -> GSM initialized.
09:06:13.266 -> Awaiting Call.
09:06:13.266 -> 
09:06:13.304 -> 29
09:06:14.040 -> Connection lost. Trying to reconnect...
09:06:44.353 -> GSM initialized.
09:06:44.353 -> Awaiting Call.
09:06:44.353 -> 
09:06:44.353 -> 29
09:06:45.121 -> Connection lost. Trying to reconnect...
09:07:10.977 -> GSM initialized.
09:07:10.977 -> Awaiting Call.
09:07:10.977 -> 
09:07:11.013 -> 29
09:07:11.763 -> Connection lost. Trying to reconnect...

```

---

<div class="post-metadata">

**Author:** ![Hutkikz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hutkikz/32/218764_2.png) [@Hutkikz](https://forum.arduino.cc/u/Hutkikz)\
**Post date:** [April 23, 2023, 1:24pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/6 "2023-04-23T13:24:29Z")

</div>

Thank you for the Serial output. Lets add more

Added a temporary debugConnectionCheck(); function it only checks does not connect.  
Added some more prints.  
Added line numbers to the prints makes it easier to know where we are.  
Finally I added a: `while(!Serial);` after `Serial.begin();` to wait for Serial to be initialized so we don't miss any prints.

```plaintext
#include <MKRGSM.h>
#include <TimeLib.h>

// GSM and GPRS instances
GSM gsmAccess;
GPRS gprs;
GSMScanner GSMScan;
GSMVoiceCall voiceCall;
GSM_SMS sms;

// Relay and LED pins
const int relayPin = 1;
char PINNUMBER [] = ""; // PIN-Code of the Simcard
const int ledPin = LED_BUILTIN;

// Whitelisted numbers
const char *whitelist[] = {"+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789"};
const int whitelistSize = sizeof(whitelist) / sizeof(whitelist[0]);

// Phone number to send text message
const char *textMessagePhoneNumber = "+00123456789";

// Pre-composed text message
const char *textMessage = "This is an automated message. I'm online.";

// Variables for text message sending interval
int lastSentMonth = -1;

bool connected = false;
unsigned long lastGSMCheck = 0;
unsigned long checkInterval = 60000; // Check connection every 30 seconds
unsigned long reconnectTimeout = 60000; // 30 seconds timeout

void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);
  while (!Serial); // wait for Serial to initialize so we don't miss any messages

  Serial.println("42 Booting.");
  delay(5000); // Give the GSM module some time to initialize
  connectToCarrier();
}

void loop() {

  // Check GSM connection
  if (gsmAccess.isAccessAlive() != GSM_READY) {
    digitalWrite(ledPin, LOW); // Turn LED off.
    Serial.println("54 Connection lost. Trying to reconnect...");
    connectToCarrier();
  }

  Serial.print("58 Signal Strength = ");
  Serial.println(GSMScan.getSignalStrength());
  debugConnectionCheck(60);
  checkForVoiceCall();
  debugConnectionCheck(62);
  checkForTextMessage();
  debugConnectionCheck(64);
  sendTextMessageEveryThreeMonths();
  debugConnectionCheck(66);
}

void debugConnectionCheck(int lineNum) {
  Serial.print(lineNum);
  if (gsmAccess.isAccessAlive() != GSM_READY) {
    digitalWrite(ledPin, LOW); // Turn LED off.
    Serial.println(" Connection lost.");
    return;
  }
  Serial.println(" Connection stable.");
}

void connectToCarrier() {
  bool connected = false;
  int retries = 0;
  const int maxRetries = 5;

  while (!connected && retries < maxRetries) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      connected = true; 
      digitalWrite(ledPin, HIGH); // Solid: connected
      Serial.println("85 GSM initialized.");
      Serial.println("Awaiting Call.");
      Serial.println("");
    } else {
      connected = false;
      Serial.print("90 Not connected retry# ");
      retries++;
      Serial.println(retries);
      delay(1000);
    }
  }

  if (retries >= maxRetries) {
    Serial.println("98 Failed to connect after maximum retries. Restarting the board.");
    NVIC_SystemReset();
  }
}

void checkForVoiceCall() {
  if (voiceCall.getvoiceCallStatus() == RECEIVINGCALL) {
    char phoneNumber[20];
    voiceCall.retrieveCallingNumber(phoneNumber, 20);

    bool isWhitelisted = false;
    for (int i = 0; i < whitelistSize; i++) {
      if (strcmp(phoneNumber, whitelist[i]) == 0) {
        isWhitelisted = true;
        break;
      }
    }

    voiceCall.hangCall();

    if (isWhitelisted) { // If whitelisted person calls, activate the relay.
      activateRelay();

      delay(10000);

      Serial.println("127 WhiteListed system reset");
      NVIC_SystemReset(); // I've tried the code with and without this line. I was trying whether it would be better to just restart the whole setup everytime some had called, it made no difference.
    }
  }
}

void checkForTextMessage() {
  if (sms.available()) {
    char phoneNumber[20];
    sms.remoteNumber(phoneNumber, 20);

    sms.flush(); // Flush the message
  }
}

void activateRelay() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(relayPin, HIGH);
    delay(2000);
    digitalWrite(relayPin, LOW);
    delay(250);
  }
}

void sendTextMessageEveryThreeMonths() {
  time_t currentTime = gsmAccess.getTime();
  int currentMonth = month(currentTime);
  int currentDay = day(currentTime);

  if ((currentMonth - lastSentMonth) % 3 == 0 && currentDay == 1 && currentMonth != lastSentMonth) {
    Serial.print("153 Send Textmessage. Online.");

    sms.beginSMS(textMessagePhoneNumber);
    sms.print(textMessage);
    sms.endSMS();
    Serial.println("158 \nCOMPLETE!\n");

    lastSentMonth = currentMonth;
  }
}
```

---

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [April 23, 2023, 2:24pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/7 "2023-04-23T14:24:49Z")

</div>

Thank you once again! I've tried the code but unfortunately to no avail. This is the serial output I'm getting:

```plaintext
16:07:57.434 -> 42 Booting.
16:08:18.188 -> 85 GSM initialized.
16:08:18.188 -> Awaiting Call.
16:08:18.188 -> 
16:08:18.223 -> 54 Connection lost. Trying to reconnect...
16:08:57.263 -> 85 GSM initialized.
16:08:57.263 -> Awaiting Call.
16:08:57.263 -> 
16:08:57.263 -> 58 Signal Strength = 28
16:08:57.301 -> 60 Connection lost.
16:08:57.301 -> 62 Connection lost.
16:08:58.698 -> 64 Connection lost.
16:08:58.732 -> 66 Connection lost.
16:08:58.799 -> 54 Connection lost. Trying to reconnect...
16:09:13.005 -> 90 Not connected retry# 1
16:09:29.376 -> 85 GSM initialized.
16:09:29.376 -> Awaiting Call.
16:09:29.376 -> 
16:09:29.376 -> 58 Signal Strength = 28
16:09:29.376 -> 60 Connection lost.
16:09:29.412 -> 62 Connection lost.
16:09:29.450 -> 64 Connection lost.
16:09:29.484 -> 66 Connection lost.
16:09:29.552 -> 54 Connection lost. Trying to reconnect...
16:09:44.521 -> 85 GSM initialized.
16:09:44.521 -> Awaiting Call.
16:09:44.521 -> 
16:09:44.521 -> 58 Signal Strength = 28
16:09:44.521 -> 60 Connection lost.
16:09:44.556 -> 62 Connection lost.
16:09:44.589 -> 64 Connection lost.
16:09:44.658 -> 66 Connection lost.
16:09:44.691 -> 54 Connection lost. Trying to reconnect...
16:09:58.895 -> 90 Not connected retry# 1
16:10:14.116 -> 90 Not connected retry# 2
16:10:29.323 -> 90 Not connected retry# 3
16:10:44.567 -> 90 Not connected retry# 4
16:10:59.798 -> 90 Not connected retry# 5
16:11:00.817 -> 98 Failed to connect after maximum retries. Restarting the board.
16:11:02.807 -> 42 Booting.
16:11:22.064 -> 90 Not connected retry# 1
16:11:48.079 -> 85 GSM initialized.
16:11:48.079 -> Awaiting Call.
16:11:48.079 -> 
16:11:48.117 -> 54 Connection lost. Trying to reconnect...
16:12:02.504 -> 85 GSM initialized.
16:12:02.504 -> Awaiting Call.
16:12:02.504 -> 
16:12:02.504 -> 58 Signal Strength = 26
16:12:02.541 -> 60 Connection lost.
16:12:02.576 -> 62 Connection lost.
16:12:03.315 -> 64 Connection lost.
16:12:03.351 -> 66 Connection lost.
16:12:03.385 -> 54 Connection lost. Trying to reconnect...
16:12:18.576 -> 85 GSM initialized.
16:12:18.576 -> Awaiting Call.
16:12:18.576 -> 
16:12:18.576 -> 58 Signal Strength = 27
16:12:18.609 -> 60 Connection lost.
16:12:18.647 -> 62 Connection lost.
16:12:19.384 -> 64 Connection lost.
16:12:19.419 -> 66 Connection lost.
16:12:19.453 -> 54 Connection lost. Trying to reconnect...
16:12:33.708 -> 90 Not connected retry# 1
16:12:48.937 -> 85 GSM initialized.
16:12:48.937 -> Awaiting Call.
16:12:48.937 -> 
16:12:48.937 -> 58 Signal Strength = 27
16:12:48.937 -> 60 Connection lost.
16:12:48.971 -> 62 Connection lost.
16:12:49.695 -> 64 Connection lost.
16:12:49.766 -> 66 Connection lost.
16:12:49.801 -> 54 Connection lost. Trying to reconnect...
16:13:04.781 -> 85 GSM initialized.
16:13:04.781 -> Awaiting Call.
16:13:04.781 -> 
16:13:04.781 -> 58 Signal Strength = 27
16:13:04.815 -> 60 Connection lost.
16:13:04.851 -> 62 Connection lost.
16:13:05.572 -> 64 Connection lost.
16:13:05.639 -> 66 Connection lost.
16:13:05.672 -> 54 Connection lost. Trying to reconnect...
16:13:49.990 -> 85 GSM initialized.
16:13:49.990 -> Awaiting Call.
16:13:49.990 -> 
16:13:49.990 -> 58 Signal Strength = 19
16:13:49.990 -> 60 Connection lost.
16:13:50.027 -> 62 Connection lost.
16:13:51.388 -> 64 Connection lost.
16:13:51.457 -> 66 Connection lost.
16:13:51.492 -> 54 Connection lost. Trying to reconnect...
16:14:06.509 -> 85 GSM initialized.
16:14:06.509 -> Awaiting Call.
16:14:06.509 -> 
16:14:06.509 -> 58 Signal Strength = 26
16:14:06.509 -> 60 Connection lost.
16:14:06.542 -> 62 Connection lost.
16:14:06.581 -> 64 Connection lost.
16:14:06.618 -> 66 Connection lost.
16:14:06.687 -> 54 Connection lost. Trying to reconnect...
16:14:21.867 -> 85 GSM initialized.
16:14:21.867 -> Awaiting Call.
16:14:21.867 -> 
16:14:21.867 -> 58 Signal Strength = 28
16:14:21.900 -> 60 Connection lost.
16:14:21.934 -> 62 Connection lost.
16:14:22.651 -> 64 Connection lost.
16:14:22.719 -> 66 Connection lost.
16:14:22.752 -> 54 Connection lost. Trying to reconnect...
16:14:37.032 -> 90 Not connected retry# 1
16:14:52.034 -> 85 GSM initialized.
16:14:52.034 -> Awaiting Call.
16:14:52.034 -> 
16:14:52.034 -> 58 Signal Strength = 28
16:14:52.067 -> 60 Connection lost.
16:14:52.101 -> 62 Connection lost.
16:14:52.819 -> 64 Connection lost.
16:14:52.888 -> 66 Connection lost.
16:14:52.921 -> 54 Connection lost. Trying to reconnect...
16:15:07.256 -> 90 Not connected retry# 1
16:15:22.560 -> 90 Not connected retry# 2

```

---

<div class="post-metadata">

**Author:** ![Hutkikz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hutkikz/32/218764_2.png) [@Hutkikz](https://forum.arduino.cc/u/Hutkikz)\
**Post date:** [April 23, 2023, 3:05pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/8 "2023-04-23T15:05:39Z")

</div>

Let's try another test:

```plaintext
#include <MKRGSM.h>
#include <TimeLib.h>

// GSM and GPRS instances
GSM gsmAccess;
GPRS gprs;
GSMScanner GSMScan;
GSMVoiceCall voiceCall;
GSM_SMS sms;

// Relay and LED pins
const int relayPin = 1;
char PINNUMBER [] = ""; // PIN-Code of the Simcard
const int ledPin = LED_BUILTIN;

// Whitelisted numbers
const char *whitelist[] = {"+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789"};
const int whitelistSize = sizeof(whitelist) / sizeof(whitelist[0]);

// Phone number to send text message
const char *textMessagePhoneNumber = "+00123456789";

// Pre-composed text message
const char *textMessage = "This is an automated message. I'm online.";

// Variables for text message sending interval
int lastSentMonth = -1;

bool connected = false;
unsigned long lastGSMCheck = 0;
unsigned long checkInterval = 60000; // Check connection every 30 seconds
unsigned long reconnectTimeout = 60000; // 30 seconds timeout

void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);
  while (!Serial); // wait for Serial to initialize so we don't miss any messages

  Serial.println("42 Booting.");
  delay(5000); // Give the GSM module some time to initialize
  connectToCarrier();
}

void loop() {

  // Check GSM connection
  if (gsmAccess.isAccessAlive() != GSM_READY) {
    digitalWrite(ledPin, LOW); // Turn LED off.
    Serial.println("54 Connection lost. Trying to reconnect...");
    connectToCarrier();
  }
  debugConnectionCheck(57);
  Serial.print("58 Signal Strength = ");
  Serial.println(GSMScan.getSignalStrength());
  debugConnectionCheck(60);
  checkForVoiceCall();
  checkForTextMessage();
  sendTextMessageEveryThreeMonths();
}

void debugConnectionCheck(int lineNum) {
  Serial.print(lineNum);
  if (gsmAccess.isAccessAlive() != GSM_READY) {
    digitalWrite(ledPin, LOW); // Turn LED off.
    Serial.println(" Connection lost.");
    return;
  }
  Serial.println(" Connection stable.");
}

void connectToCarrier() {
  bool connected = false;
  int retries = 0;
  const int maxRetries = 5;
  gsmAccess.setTimeout(180000); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

  while (!connected && retries < maxRetries) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      connected = true; 
      digitalWrite(ledPin, HIGH); // Solid: connected
      Serial.print("85 GSM initialized. - ");
      Serial.println("Awaiting Call.");
      Serial.println("");
    } else {
      connected = false;
      Serial.print("91 Not connected retry# ");
      retries++;
      Serial.println(retries);
      delay(1000);
    }
    debugConnectionCheck(96);
  }

  if (retries >= maxRetries) {
    Serial.println("100 Failed to connect after maximum retries. Restarting the board.");
    NVIC_SystemReset();
  }
}

void checkForVoiceCall() {
  if (voiceCall.getvoiceCallStatus() == RECEIVINGCALL) {
    char phoneNumber[20];
    voiceCall.retrieveCallingNumber(phoneNumber, 20);

    bool isWhitelisted = false;
    for (int i = 0; i < whitelistSize; i++) {
      if (strcmp(phoneNumber, whitelist[i]) == 0) {
        isWhitelisted = true;
        break;
      }
    }

    voiceCall.hangCall();

    if (isWhitelisted) { // If whitelisted person calls, activate the relay.
      activateRelay();

      delay(10000);

      Serial.println("126 WhiteListed system reset");
      NVIC_SystemReset(); // I've tried the code with and without this line. I was trying whether it would be better to just restart the whole setup everytime some had called, it made no difference.
    }
  }
}

void checkForTextMessage() {
  if (sms.available()) {
    char phoneNumber[20];
    sms.remoteNumber(phoneNumber, 20);

    sms.flush(); // Flush the message
  }
}

void activateRelay() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(relayPin, HIGH);
    delay(2000);
    digitalWrite(relayPin, LOW);
    delay(250);
  }
}

void sendTextMessageEveryThreeMonths() {
  time_t currentTime = gsmAccess.getTime();
  int currentMonth = month(currentTime);
  int currentDay = day(currentTime);

  if ((currentMonth - lastSentMonth) % 3 == 0 && currentDay == 1 && currentMonth != lastSentMonth) {
    Serial.print("156 Send Textmessage. Online.");

    sms.beginSMS(textMessagePhoneNumber);
    sms.print(textMessage);
    sms.endSMS();
    Serial.println("160 \nCOMPLETE!\n");

    lastSentMonth = currentMonth;
  }
}
```

---

<div class="post-metadata">

**Author:** ![gardner](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gardner/32/213975_2.png) [@gardner](https://forum.arduino.cc/u/gardner)\
**Post date:** [April 23, 2023, 4:18pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/9 "2023-04-23T16:18:21Z")

</div>

> [@valley09](#):
>
> When I set this up about two years ago, the system worked fine.

Is it possible the PSU or LiIon battery is getting old and causing trouble? I have had projects go wonky after years of stable service due to the wall wart going bad after 5 years of being plugged in. These things don't last forever.

---

<div class="post-metadata">

**Author:** ![Hutkikz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hutkikz/32/218764_2.png) [@Hutkikz](https://forum.arduino.cc/u/Hutkikz)\
**Post date:** [April 23, 2023, 4:40pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/10 "2023-04-23T16:40:27Z")

</div>

> [@gardner](#):
>
> Is it possible the PSU or LiIon battery is getting old and causing trouble?

The modem does draw a lot of juice, so if the battery is weak it would be the first to go out. I agree you should check that.

---

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [April 23, 2023, 5:03pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/11 "2023-04-23T17:03:39Z")

</div>

I've suspected the battery before, so I replaced it May 2022. That didn't improve it back then so I don't think that's the culprit.

---

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [April 23, 2023, 5:08pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/12 "2023-04-23T17:08:42Z")

</div>

I've tried the new code and found no improvement yet, sadly.

```plaintext
19:04:10.873 -> 42 Booting.
19:04:31.421 -> 85 GSM initialized. - Awaiting Call.
19:04:31.421 -> 
19:04:31.421 -> 96 Connection lost.
19:04:31.459 -> 54 Connection lost. Trying to reconnect...
19:04:46.763 -> 85 GSM initialized. - Awaiting Call.
19:04:46.763 -> 
19:04:46.763 -> 96 Connection lost.
19:04:46.797 -> 57 Connection lost.
19:04:46.830 -> 58 Signal Strength = 24
19:04:46.830 -> 60 Connection lost.
19:04:47.635 -> 54 Connection lost. Trying to reconnect...
19:05:02.778 -> 85 GSM initialized. - Awaiting Call.
19:05:02.778 -> 
19:05:02.778 -> 96 Connection lost.
19:05:02.778 -> 57 Connection lost.
19:05:02.815 -> 58 Signal Strength = 25
19:05:02.815 -> 60 Connection lost.
19:05:03.608 -> 54 Connection lost. Trying to reconnect...
19:05:19.334 -> 85 GSM initialized. - Awaiting Call.
19:05:19.334 -> 
19:05:19.334 -> 96 Connection lost.
19:05:19.372 -> 57 Connection lost.
19:05:19.407 -> 58 Signal Strength = 26
19:05:19.407 -> 60 Connection lost.
19:05:20.204 -> 54 Connection lost. Trying to reconnect...
19:05:34.141 -> 85 GSM initialized. - Awaiting Call.
19:05:34.141 -> 
19:05:34.141 -> 96 Connection lost.
19:05:34.141 -> 57 Connection lost.
19:05:34.175 -> 58 Signal Strength = 26
19:05:34.211 -> 60 Connection lost.
19:05:34.982 -> 54 Connection lost. Trying to reconnect...
19:05:49.524 -> 91 Not connected retry# 1
19:05:50.529 -> 96 Connection lost.
19:06:06.958 -> 85 GSM initialized. - Awaiting Call.
19:06:06.958 -> 
19:06:06.958 -> 96 Connection lost.
19:06:06.992 -> 57 Connection lost.
19:06:06.992 -> 58 Signal Strength = 27
19:06:07.029 -> 60 Connection lost.
19:06:07.800 -> 54 Connection lost. Trying to reconnect...
19:06:22.257 -> 91 Not connected retry# 1
19:06:23.264 -> 96 Connection lost.
19:06:37.117 -> 85 GSM initialized. - Awaiting Call.
19:06:37.117 -> 
19:06:37.117 -> 96 Connection lost.
19:06:37.117 -> 57 Connection lost.
19:06:37.150 -> 58 Signal Strength = 26
19:06:37.150 -> 60 Connection lost.
19:06:37.951 -> 54 Connection lost. Trying to reconnect...
19:06:52.284 -> 85 GSM initialized. - Awaiting Call.
19:06:52.284 -> 
19:06:52.284 -> 96 Connection lost.
19:06:52.318 -> 57 Connection lost.
19:06:52.351 -> 58 Signal Strength = 27
19:06:52.351 -> 60 Connection lost.
19:06:53.139 -> 54 Connection lost. Trying to reconnect...
19:07:06.494 -> 85 GSM initialized. - Awaiting Call.
19:07:06.494 -> 
19:07:06.494 -> 96 Connection lost.
19:07:06.527 -> 57 Connection lost.
19:07:06.562 -> 58 Signal Strength = 25
19:07:06.562 -> 60 Connection lost.
19:07:07.360 -> 54 Connection lost. Trying to reconnect...
19:07:22.698 -> 85 GSM initialized. - Awaiting Call.
19:07:22.698 -> 
19:07:22.698 -> 96 Connection lost.
19:07:22.732 -> 57 Connection lost.
19:07:22.766 -> 58 Signal Strength = 29
19:07:22.766 -> 60 Connection lost.
19:07:23.560 -> 54 Connection lost. Trying to reconnect...
19:07:38.524 -> 85 GSM initialized. - Awaiting Call.
19:07:38.524 -> 
19:07:38.524 -> 96 Connection lost.
19:07:38.558 -> 57 Connection lost.
19:07:38.558 -> 58 Signal Strength = 29
19:07:38.592 -> 60 Connection lost.
19:07:39.380 -> 54 Connection lost. Trying to reconnect...
19:07:54.141 -> 85 GSM initialized. - Awaiting Call.
19:07:54.141 -> 
19:07:54.141 -> 96 Connection lost.
19:07:54.141 -> 57 Connection lost.
19:07:54.174 -> 58 Signal Strength = 29
19:07:54.208 -> 60 Connection lost.
19:07:55.000 -> 54 Connection lost. Trying to reconnect...

```

---

<div class="post-metadata">

**Author:** ![Hutkikz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hutkikz/32/218764_2.png) [@Hutkikz](https://forum.arduino.cc/u/Hutkikz)\
**Post date:** [April 23, 2023, 7:50pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/13 "2023-04-23T19:50:34Z")

</div>

> [@valley09](#):
>
> I've tried the new code and found no improvement yet, sadly.

That's because we haven't tried to fix it yet. 🤔  
We have been placing prints and checks to see what is really happening with your project using the Serial Monitor. You should try to follow it.😜

Maybe with this one we can make a little progress. 🫣  
We should at least learn more, ... babysteps. 🤨

```arduino
#include <MKRGSM.h>
#include <TimeLib.h>

// GSM and GPRS instances
GSM gsmAccess;
GPRS gprs;
GSMScanner GSMScan;
GSMVoiceCall voiceCall;
GSM_SMS sms;

// Relay and LED pins
const int relayPin = 1;
char PINNUMBER [] = ""; // PIN-Code of the Simcard
const int ledPin = LED_BUILTIN;

// Whitelisted numbers
const char *whitelist[] = {"+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789"};
const int whitelistSize = sizeof(whitelist) / sizeof(whitelist[0]);

// Phone number to send text message
const char *textMessagePhoneNumber = "+00123456789";

// Pre-composed text message
const char *textMessage = "This is an automated message. I'm online.";

// Variables for text message sending interval
int lastSentMonth = -1;

bool connected = false;
unsigned long lastGSMCheck = 0;
unsigned long checkInterval = 60000; // Check connection every 30 seconds
unsigned long reconnectTimeout = 60000; // 30 seconds timeout

void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);
  while (!Serial); // wait for Serial to initialize so we don't miss any messages

  Serial.println("42 Booting.");
  delay(5000); // Give the GSM module some time to initialize
  connectToCarrier();
}

void loop() {
  static int loopCounter;
  Serial.print(" ************* loop# ");
  Serial.print(++loopCounter);
  Serial.println(" *************");

  // Check GSM connection
  if (gsmAccess.isAccessAlive() != GSM_READY) {
    digitalWrite(ledPin, LOW); // Turn LED off.
    Serial.println("54 Connection lost. Trying to reconnect...");
    connectToCarrier();
  }
  Serial.print("57 Signal Strength = ");
  Serial.println(GSMScan.getSignalStrength());
  checkForVoiceCall();
  checkForTextMessage();
  sendTextMessageEveryThreeMonths();
}

void connectToCarrier() {
  static bool connected = false;
  static int retries = 0;
  const int maxRetries = 5;

  while (!connected && retries < maxRetries) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      connected = true; 
      digitalWrite(ledPin, HIGH); // Solid: connected
      Serial.print("73 GSM initialized. - ");
      Serial.println("Awaiting Call.");
      Serial.println("");
    } else {
      connected = false;
      Serial.print("78 Not connected retry# ");
      retries++;
      Serial.println(retries);
      delay(1000);
    }
  }

  if (retries >= maxRetries) {
    Serial.println("86 Failed to connect after maximum retries. Restarting the board.");
    NVIC_SystemReset();
  }
}

void checkForVoiceCall() {
  if (voiceCall.getvoiceCallStatus() == RECEIVINGCALL) {
    char phoneNumber[20];
    voiceCall.retrieveCallingNumber(phoneNumber, 20);

    bool isWhitelisted = false;
    for (int i = 0; i < whitelistSize; i++) {
      if (strcmp(phoneNumber, whitelist[i]) == 0) {
        isWhitelisted = true;
        break;
      }
    }

    voiceCall.hangCall();

    if (isWhitelisted) { // If whitelisted person calls, activate the relay.
      activateRelay();

      delay(10000);

      Serial.println("112 WhiteListed system reset");
      NVIC_SystemReset(); // I've tried the code with and without this line. I was trying whether it would be better to just restart the whole setup everytime some had called, it made no difference.
    }
  }
}

void checkForTextMessage() {
  if (sms.available()) {
    char phoneNumber[20];
    sms.remoteNumber(phoneNumber, 20);

    sms.flush(); // Flush the message
  }
}

void activateRelay() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(relayPin, HIGH);
    delay(2000);
    digitalWrite(relayPin, LOW);
    delay(250);
  }
}

void sendTextMessageEveryThreeMonths() {
  time_t currentTime = gsmAccess.getTime();
  int currentMonth = month(currentTime);
  int currentDay = day(currentTime);
  Serial.println("144 Month is ");
  Serial.println(currentMonth);
  Serial.println("146 Day is ");
  Serial.println(currentDay);

  if ((currentMonth - lastSentMonth) % 3 == 0 && currentDay == 1 && currentMonth != lastSentMonth) {
    Serial.print("142 Send Textmessage. Online.");

    sms.beginSMS(textMessagePhoneNumber);
    sms.print(textMessage);
    sms.endSMS();
    Serial.println("153 \nCOMPLETE!\n");

    lastSentMonth = currentMonth;
  }
}
```

---

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [April 23, 2023, 8:17pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/14 "2023-04-23T20:17:55Z")

</div>

I'm sorry haha its just that I've been working on this code all day too and together with my brother we've also been uploading about 20 different versions of my code to the board trying to fix it ourselves too in the meantime.

So I guess you can say my focus is long gone for today and I'm not the best at spotting the exact differences between each and every version of the code anymore, I apologize 😓 But nonetheless your time and effort is very much appreciated!

But back to debugging, this is what that last code produced:

```plaintext
22:06:57.060 -> 42 Booting.
22:07:17.263 -> 73 GSM initialized. - Awaiting Call.
22:07:17.263 -> 
22:07:17.263 -> *************loop# 1*************
22:07:17.263 -> 54 Connection lost. Trying to reconnect...
22:07:17.263 -> 57 Signal Strength = 27
22:07:18.055 -> 144 Month is 
22:07:18.055 -> 4
22:07:18.055 -> 146 Day is 
22:07:18.055 -> 23
22:07:18.055 -> *************loop# 2*************
22:07:18.055 -> 54 Connection lost. Trying to reconnect...
22:07:18.055 -> 57 Signal Strength = 27
22:07:18.831 -> 144 Month is 
22:07:18.831 -> 4
22:07:18.831 -> 146 Day is 
22:07:18.831 -> 23
22:07:18.831 -> *************loop# 3*************
22:07:18.868 -> 54 Connection lost. Trying to reconnect...
22:07:18.868 -> 57 Signal Strength = 27
22:07:19.627 -> 144 Month is 
22:07:19.627 -> 4
22:07:19.627 -> 146 Day is 
22:07:19.627 -> 23
22:07:19.627 -> *************loop# 4*************
22:07:19.665 -> 54 Connection lost. Trying to reconnect...
22:07:19.665 -> 57 Signal Strength = 27
22:07:20.427 -> 144 Month is 
22:07:20.427 -> 4
22:07:20.427 -> 146 Day is 
22:07:20.427 -> 23
22:07:20.427 -> *************loop# 5*************
22:07:20.427 -> 54 Connection lost. Trying to reconnect...
22:07:20.427 -> 57 Signal Strength = 27
22:07:21.218 -> 144 Month is 
22:07:21.218 -> 4
22:07:21.218 -> 146 Day is 
22:07:21.218 -> 23
22:07:21.218 -> *************loop# 6*************
22:07:21.218 -> 54 Connection lost. Trying to reconnect...
22:07:21.218 -> 57 Signal Strength = 27
22:07:22.002 -> 144 Month is 
22:07:22.002 -> 4
22:07:22.002 -> 146 Day is 
22:07:22.002 -> 23
22:07:22.002 -> *************loop# 7*************
22:07:22.002 -> 54 Connection lost. Trying to reconnect...
22:07:22.002 -> 57 Signal Strength = 27
22:07:22.784 -> 144 Month is 
22:07:22.784 -> 4
22:07:22.784 -> 146 Day is 
22:07:22.784 -> 23
22:07:22.784 -> *************loop# 8*************
22:07:22.822 -> 54 Connection lost. Trying to reconnect...
22:07:22.822 -> 57 Signal Strength = 27
22:07:23.565 -> 144 Month is 
22:07:23.565 -> 4
22:07:23.565 -> 146 Day is 
22:07:23.565 -> 23
22:07:23.565 -> *************loop# 9*************
22:07:23.603 -> 54 Connection lost. Trying to reconnect...
22:07:23.603 -> 57 Signal Strength = 27
22:07:24.356 -> 144 Month is 
22:07:24.356 -> 4
22:07:24.356 -> 146 Day is 
22:07:24.356 -> 23
22:07:24.356 -> *************loop# 10*************
22:07:24.389 -> 54 Connection lost. Trying to reconnect...
22:07:24.389 -> 57 Signal Strength = 27
22:07:25.147 -> 144 Month is 
22:07:25.147 -> 4
22:07:25.147 -> 146 Day is 
22:07:25.147 -> 23
22:07:25.147 -> *************loop# 11*************
22:07:25.185 -> 54 Connection lost. Trying to reconnect...
22:07:25.185 -> 57 Signal Strength = 27
22:07:25.929 -> 144 Month is 
22:07:25.929 -> 4
22:07:25.929 -> 146 Day is 
22:07:25.929 -> 23
22:07:25.929 -> *************loop# 12*************
22:07:25.967 -> 54 Connection lost. Trying to reconnect...
22:07:25.967 -> 57 Signal Strength = 27
22:07:26.720 -> 144 Month is 
22:07:26.720 -> 4
22:07:26.720 -> 146 Day is 
22:07:26.720 -> 23
22:07:26.720 -> *************loop# 13*************
22:07:26.755 -> 54 Connection lost. Trying to reconnect...
22:07:26.755 -> 57 Signal Strength = 27
22:07:27.535 -> 144 Month is 
22:07:27.535 -> 4
22:07:27.535 -> 146 Day is 
22:07:27.535 -> 23
22:07:27.535 -> *************loop# 14*************
22:07:27.535 -> 54 Connection lost. Trying to reconnect...
22:07:27.535 -> 57 Signal Strength = 27
22:07:28.291 -> 144 Month is 
22:07:28.291 -> 4
22:07:28.291 -> 146 Day is 
22:07:28.291 -> 23
22:07:28.291 -> *************loop# 15*************
22:07:28.327 -> 54 Connection lost. Trying to reconnect...
22:07:28.327 -> 57 Signal Strength = 27
22:07:29.109 -> 144 Month is 
22:07:29.109 -> 4
22:07:29.109 -> 146 Day is 
22:07:29.109 -> 23
22:07:29.109 -> *************loop# 16*************
22:07:29.109 -> 54 Connection lost. Trying to reconnect...
22:07:29.109 -> 57 Signal Strength = 27
22:07:29.891 -> 144 Month is 
22:07:29.891 -> 4
22:07:29.891 -> 146 Day is 
22:07:29.891 -> 23
22:07:29.891 -> *************loop# 17*************
22:07:29.891 -> 54 Connection lost. Trying to reconnect...
22:07:29.891 -> 57 Signal Strength = 27
22:07:30.679 -> 144 Month is 
22:07:30.679 -> 4
22:07:30.679 -> 146 Day is 
22:07:30.679 -> 23
22:07:30.679 -> *************loop# 18*************
22:07:30.714 -> 54 Connection lost. Trying to reconnect...
22:07:30.714 -> 57 Signal Strength = 27
22:07:31.454 -> 144 Month is 
22:07:31.454 -> 4
22:07:31.454 -> 146 Day is 
22:07:31.454 -> 23
22:07:31.454 -> *************loop# 19*************
22:07:31.492 -> 54 Connection lost. Trying to reconnect...
22:07:31.492 -> 57 Signal Strength = 27
22:07:32.257 -> 144 Month is 
22:07:32.257 -> 4
22:07:32.257 -> 146 Day is 
22:07:32.257 -> 23
22:07:32.257 -> *************loop# 20*************
22:07:32.291 -> 54 Connection lost. Trying to reconnect...
22:07:32.291 -> 57 Signal Strength = 27
22:07:33.052 -> 144 Month is 
22:07:33.052 -> 4
22:07:33.052 -> 146 Day is 
22:07:33.052 -> 23
22:07:33.052 -> *************loop# 21*************
22:07:33.052 -> 54 Connection lost. Trying to reconnect...
22:07:33.052 -> 57 Signal Strength = 27
22:07:33.852 -> 144 Month is 
22:07:33.852 -> 4
22:07:33.852 -> 146 Day is 
22:07:33.852 -> 23
22:07:33.852 -> *************loop# 22*************
22:07:33.852 -> 54 Connection lost. Trying to reconnect...
22:07:33.852 -> 57 Signal Strength = 27
22:07:34.610 -> 144 Month is 
22:07:34.610 -> 4
22:07:34.610 -> 146 Day is 
22:07:34.610 -> 23
22:07:34.610 -> *************loop# 23*************
22:07:34.643 -> 54 Connection lost. Trying to reconnect...
22:07:34.643 -> 57 Signal Strength = 27
22:07:35.412 -> 144 Month is 
22:07:35.412 -> 4
22:07:35.412 -> 146 Day is 
22:07:35.412 -> 23
22:07:35.412 -> *************loop# 24*************
22:07:35.445 -> 54 Connection lost. Trying to reconnect...
22:07:35.445 -> 57 Signal Strength = 27
22:07:36.191 -> 144 Month is 
22:07:36.191 -> 4
22:07:36.191 -> 146 Day is 
22:07:36.191 -> 23
22:07:36.191 -> *************loop# 25*************
22:07:36.225 -> 54 Connection lost. Trying to reconnect...
22:07:36.225 -> 57 Signal Strength = 27
22:07:37.001 -> 144 Month is 
22:07:37.001 -> 4
22:07:37.001 -> 146 Day is 
22:07:37.001 -> 23
22:07:37.001 -> *************loop# 26*************
22:07:37.001 -> 54 Connection lost. Trying to reconnect...
22:07:37.001 -> 57 Signal Strength = 27
22:07:37.776 -> 144 Month is 
22:07:37.776 -> 4
22:07:37.776 -> 146 Day is 
22:07:37.776 -> 23
22:07:37.776 -> *************loop# 27*************
22:07:37.810 -> 54 Connection lost. Trying to reconnect...
22:07:37.810 -> 57 Signal Strength = 27
22:07:38.558 -> 144 Month is 
22:07:38.558 -> 4
22:07:38.558 -> 146 Day is 
22:07:38.558 -> 23
22:07:38.558 -> *************loop# 28*************
22:07:38.596 -> 54 Connection lost. Trying to reconnect...
22:07:38.596 -> 57 Signal Strength = 27
22:07:39.351 -> 144 Month is 
22:07:39.351 -> 4
22:07:39.351 -> 146 Day is 
22:07:39.351 -> 23
22:07:39.351 -> *************loop# 29*************
22:07:39.385 -> 54 Connection lost. Trying to reconnect...
22:07:39.385 -> 57 Signal Strength = 27
22:07:40.157 -> 144 Month is 
22:07:40.157 -> 4
22:07:40.157 -> 146 Day is 
22:07:40.157 -> 23
22:07:40.157 -> *************loop# 30*************
22:07:40.157 -> 54 Connection lost. Trying to reconnect...
22:07:40.157 -> 57 Signal Strength = 27
22:07:40.936 -> 144 Month is 
22:07:40.936 -> 4
22:07:40.936 -> 146 Day is 
22:07:40.936 -> 23
22:07:40.936 -> *************loop# 31*************
22:07:40.973 -> 54 Connection lost. Trying to reconnect...
22:07:40.973 -> 57 Signal Strength = 27
22:07:41.730 -> 144 Month is 
22:07:41.730 -> 4
22:07:41.730 -> 146 Day is 
22:07:41.730 -> 23
22:07:41.730 -> *************loop# 32*************
22:07:41.766 -> 54 Connection lost. Trying to reconnect...
22:07:41.766 -> 57 Signal Strength = 27
22:07:42.502 -> 144 Month is 
22:07:42.502 -> 4
22:07:42.502 -> 146 Day is 
22:07:42.502 -> 23
22:07:42.502 -> *************loop# 33*************
22:07:42.536 -> 54 Connection lost. Trying to reconnect...
22:07:42.536 -> 57 Signal Strength = 27
22:07:43.294 -> 144 Month is 
22:07:43.294 -> 4
22:07:43.294 -> 146 Day is 
22:07:43.294 -> 23
22:07:43.294 -> *************loop# 34*************
22:07:43.331 -> 54 Connection lost. Trying to reconnect...
22:07:43.331 -> 57 Signal Strength = 27
22:07:44.088 -> 144 Month is 
22:07:44.088 -> 4
22:07:44.088 -> 146 Day is 
22:07:44.088 -> 23
22:07:44.088 -> *************loop# 35*************
22:07:44.126 -> 54 Connection lost. Trying to reconnect...
22:07:44.126 -> 57 Signal Strength = 26
22:07:44.897 -> 144 Month is 
22:07:44.897 -> 4
22:07:44.897 -> 146 Day is 
22:07:44.897 -> 23
22:07:44.897 -> *************loop# 36*************
22:07:44.897 -> 54 Connection lost. Trying to reconnect...
22:07:44.897 -> 57 Signal Strength = 26
22:07:45.669 -> 144 Month is 
22:07:45.669 -> 4
22:07:45.669 -> 146 Day is 
22:07:45.669 -> 23
22:07:45.669 -> *************loop# 37*************
22:07:45.704 -> 54 Connection lost. Trying to reconnect...
22:07:45.704 -> 57 Signal Strength = 26
22:07:46.454 -> 144 Month is 
22:07:46.454 -> 4
22:07:46.454 -> 146 Day is 
22:07:46.454 -> 23
22:07:46.454 -> *************loop# 38*************
22:07:46.489 -> 54 Connection lost. Trying to reconnect...
22:07:46.489 -> 57 Signal Strength = 26
22:07:47.266 -> 144 Month is 
22:07:47.266 -> 4
22:07:47.266 -> 146 Day is 
22:07:47.266 -> 23
22:07:47.266 -> *************loop# 39*************
22:07:47.266 -> 54 Connection lost. Trying to reconnect...
22:07:47.266 -> 57 Signal Strength = 26
22:07:48.052 -> 144 Month is 
22:07:48.052 -> 4
22:07:48.052 -> 146 Day is 
22:07:48.052 -> 23
22:07:48.052 -> *************loop# 40*************
22:07:48.052 -> 54 Connection lost. Trying to reconnect...
22:07:48.052 -> 57 Signal Strength = 26
22:07:48.830 -> 144 Month is 
22:07:48.830 -> 4
22:07:48.830 -> 146 Day is 
22:07:48.830 -> 23
22:07:48.830 -> *************loop# 41*************
22:07:48.868 -> 54 Connection lost. Trying to reconnect...
22:07:48.868 -> 57 Signal Strength = 26
22:07:49.911 -> 144 Month is 
22:07:49.911 -> 4
22:07:49.911 -> 146 Day is 
22:07:49.911 -> 23
22:07:49.911 -> *************loop# 42*************
22:07:49.911 -> 54 Connection lost. Trying to reconnect...
22:07:49.911 -> 57 Signal Strength = 26
22:07:50.878 -> 144 Month is 
22:07:50.878 -> 4
22:07:50.878 -> 146 Day is 
22:07:50.878 -> 23
22:07:50.878 -> *************loop# 43*************
22:07:50.878 -> 54 Connection lost. Trying to reconnect...
22:07:50.878 -> 57 Signal Strength = 26
22:07:52.106 -> 144 Month is 
22:07:52.106 -> 4
22:07:52.106 -> 146 Day is 
22:07:52.106 -> 23
22:07:52.106 -> *************loop# 44*************
22:07:52.106 -> 54 Connection lost. Trying to reconnect...
22:07:52.106 -> 57 Signal Strength = 26
22:07:52.955 -> 144 Month is 
22:07:52.955 -> 4
22:07:52.955 -> 146 Day is 
22:07:52.955 -> 23
22:07:52.955 -> *************loop# 45*************
22:07:52.955 -> 54 Connection lost. Trying to reconnect...
22:07:52.955 -> 57 Signal Strength = 26
22:07:54.422 -> 144 Month is 
22:07:54.422 -> 4
22:07:54.422 -> 146 Day is 
22:07:54.422 -> 23
22:07:54.422 -> *************loop# 46*************
22:07:54.422 -> 54 Connection lost. Trying to reconnect...
22:07:54.422 -> 57 Signal Strength = 26
22:07:55.607 -> 144 Month is 
22:07:55.607 -> 4
22:07:55.607 -> 146 Day is 
22:07:55.607 -> 23
22:07:55.607 -> *************loop# 47*************
22:07:55.607 -> 54 Connection lost. Trying to reconnect...
22:07:55.607 -> 57 Signal Strength = 26
22:07:55.607 -> 144 Month is 
22:07:55.607 -> 4
22:07:55.607 -> 146 Day is 
22:07:55.607 -> 23
22:07:55.607 -> *************loop# 48*************
22:07:55.607 -> 54 Connection lost. Trying to reconnect...
22:07:55.607 -> 57 Signal Strength = 26
22:07:55.607 -> 144 Month is 
22:07:55.607 -> 4
22:07:55.607 -> 146 Day is 
22:07:55.607 -> 23
22:07:55.607 -> *************loop# 49*************
22:07:55.607 -> 54 Connection lost. Trying to reconnect...
22:07:55.607 -> 57 Signal Strength = 26
22:07:57.213 -> 144 Month is 
22:07:57.213 -> 4
22:07:57.213 -> 146 Day is 
22:07:57.213 -> 23
22:07:57.213 -> *************loop# 50*************
22:07:57.213 -> 54 Connection lost. Trying to reconnect...
22:07:57.213 -> 57 Signal Strength = 26
22:07:57.213 -> 144 Month is 
22:07:57.213 -> 4
22:07:57.213 -> 146 Day is 
22:07:57.213 -> 23
22:07:57.213 -> *************loop# 51*************
22:07:57.213 -> 54 Connection lost. Trying to reconnect...
22:07:57.213 -> 57 Signal Strength = 26
22:07:57.608 -> 144 Month is 
22:07:57.608 -> 4
22:07:57.608 -> 146 Day is 
22:07:57.608 -> 23
22:07:57.608 -> *************loop# 52*************
22:07:57.608 -> 54 Connection lost. Trying to reconnect...
22:07:57.608 -> 57 Signal Strength = 26
22:07:58.708 -> 144 Month is 
22:07:58.708 -> 4
22:07:58.708 -> 146 Day is 
22:07:58.708 -> 23
22:07:58.708 -> *************loop# 53*************
22:07:58.708 -> 54 Connection lost. Trying to reconnect...
22:07:58.708 -> 57 Signal Strength = 26
22:07:59.107 -> 144 Month is 
22:07:59.107 -> 4
22:07:59.107 -> 146 Day is 
22:07:59.107 -> 23
22:07:59.107 -> *************loop# 54*************
22:07:59.107 -> 54 Connection lost. Trying to reconnect...
22:07:59.107 -> 57 Signal Strength = 26
22:08:00.332 -> 144 Month is 
22:08:00.332 -> 4
22:08:00.332 -> 146 Day is 
22:08:00.332 -> 23
22:08:00.332 -> *************loop# 55*************
22:08:00.332 -> 54 Connection lost. Trying to reconnect...
22:08:00.332 -> 57 Signal Strength = 26
22:08:00.922 -> 144 Month is 
22:08:00.922 -> 4
22:08:00.922 -> 146 Day is 
22:08:00.922 -> 23
22:08:00.922 -> *************loop# 56*************
22:08:00.922 -> 54 Connection lost. Trying to reconnect...
22:08:00.922 -> 57 Signal Strength = 26
22:08:01.868 -> 144 Month is 
22:08:01.868 -> 4
22:08:01.868 -> 146 Day is 
22:08:01.868 -> 23
22:08:01.868 -> *************loop# 57*************
22:08:01.868 -> 54 Connection lost. Trying to reconnect...
22:08:01.868 -> 57 Signal Strength = 26
22:08:04.462 -> 144 Month is 
22:08:04.462 -> 4
22:08:04.462 -> 146 Day is 
22:08:04.462 -> 23
22:08:04.462 -> *************loop# 58*************
22:08:04.462 -> 54 Connection lost. Trying to reconnect...
22:08:04.462 -> 57 Signal Strength = 26
22:08:04.462 -> 144 Month is 
22:08:04.462 -> 4
22:08:04.462 -> 146 Day is 
22:08:04.462 -> 23
22:08:04.462 -> *************loop# 59*************
22:08:04.462 -> 54 Connection lost. Trying to reconnect...
22:08:04.462 -> 57 Signal Strength = 26
22:08:04.462 -> 144 Month is 
22:08:04.462 -> 4
22:08:04.462 -> 146 Day is 
22:08:04.462 -> 23
22:08:04.462 -> *************loop# 60*************
22:08:04.462 -> 54 Connection lost. Trying to reconnect...
22:08:04.462 -> 57 Signal Strength = 26
22:08:05.113 -> 144 Month is 
22:08:05.113 -> 4
22:08:05.113 -> 146 Day is 
22:08:05.113 -> 23
22:08:05.113 -> *************loop# 61*************
22:08:05.113 -> 54 Connection lost. Trying to reconnect...
22:08:05.113 -> 57 Signal Strength = 26
22:08:09.201 -> 144 Month is 
22:08:09.201 -> 4
22:08:09.201 -> 146 Day is 
22:08:09.201 -> 23
22:08:09.201 -> *************loop# 62*************
22:08:09.201 -> 54 Connection lost. Trying to reconnect...
22:08:09.201 -> 57 Signal Strength = 27
22:08:09.201 -> 144 Month is 
22:08:09.201 -> 4
22:08:09.201 -> 146 Day is 
22:08:09.201 -> 23
22:08:09.201 -> *************loop# 63*************
22:08:09.201 -> 54 Connection lost. Trying to reconnect...
22:08:09.201 -> 57 Signal Strength = 27
22:08:09.201 -> 144 Month is 
22:08:09.201 -> 4
22:08:09.201 -> 146 Day is 
22:08:09.201 -> 23
22:08:09.201 -> *************loop# 64*************
22:08:09.201 -> 54 Connection lost. Trying to reconnect...
22:08:09.201 -> 57 Signal Strength = 27
22:08:09.201 -> 144 Month is 
22:08:09.201 -> 4
22:08:09.201 -> 146 Day is 
22:08:09.201 -> 23
22:08:09.201 -> *************loop# 65*************
22:08:09.201 -> 54 Connection lost. Trying to reconnect...
22:08:09.201 -> 57 Signal Strength = 27
22:08:10.330 -> 144 Month is 
22:08:10.330 -> 4
22:08:10.330 -> 146 Day is 
22:08:10.330 -> 23
22:08:10.330 -> *************loop# 66*************
22:08:10.330 -> 54 Connection lost. Trying to reconnect...
22:08:10.330 -> 57 Signal Strength = 27
22:08:10.330 -> 144 Month is 
22:08:10.330 -> 4
22:08:10.330 -> 146 Day is 
22:08:10.330 -> 23
22:08:10.330 -> *************loop# 67*************
22:08:10.330 -> 54 Connection lost. Trying to reconnect...
22:08:10.330 -> 57 Signal Strength = 27
22:08:10.330 -> 144 Month is 
22:08:10.330 -> 4
22:08:10.330 -> 146 Day is 
22:08:10.330 -> 23
22:08:10.330 -> *************loop# 68*************
22:08:10.330 -> 54 Connection lost. Trying to reconnect...
22:08:10.330 -> 57 Signal Strength = 27
22:08:11.430 -> 144 Month is 
22:08:11.430 -> 4
22:08:11.430 -> 146 Day is 
22:08:11.430 -> 23
22:08:11.430 -> *************loop# 69*************
22:08:11.430 -> 54 Connection lost. Trying to reconnect...
22:08:11.430 -> 57 Signal Strength = 27
22:08:12.562 -> 144 Month is 
22:08:12.562 -> 4
22:08:12.562 -> 146 Day is 
22:08:12.562 -> 23
22:08:12.562 -> *************loop# 70*************
22:08:12.562 -> 54 Connection lost. Trying to reconnect...
22:08:12.562 -> 57 Signal Strength = 27
22:08:12.562 -> 144 Month is 
22:08:12.562 -> 4
22:08:12.562 -> 146 Day is 
22:08:12.562 -> 23
22:08:12.562 -> *************loop# 71*************
22:08:12.562 -> 54 Connection lost. Trying to reconnect...
22:08:12.562 -> 57 Signal Strength = 27
22:08:13.679 -> 144 Month is 
22:08:13.679 -> 4
22:08:13.679 -> 146 Day is 
22:08:13.679 -> 23
22:08:13.679 -> *************loop# 72*************
22:08:13.679 -> 54 Connection lost. Trying to reconnect...
22:08:13.679 -> 57 Signal Strength = 27
22:08:14.784 -> 144 Month is 
22:08:14.784 -> 4
22:08:14.784 -> 146 Day is 
22:08:14.784 -> 23
22:08:14.784 -> *************loop# 73*************
22:08:14.784 -> 54 Connection lost. Trying to reconnect...
22:08:14.784 -> 57 Signal Strength = 27
22:08:14.994 -> 144 Month is 
22:08:14.994 -> 4
22:08:14.994 -> 146 Day is 
22:08:14.994 -> 23
22:08:14.994 -> *************loop# 74*************
22:08:14.994 -> 54 Connection lost. Trying to reconnect...
22:08:14.994 -> 57 Signal Strength = 27
22:08:17.362 -> 144 Month is 
22:08:17.362 -> 4
22:08:17.362 -> 146 Day is 
22:08:17.362 -> 23
22:08:17.362 -> *************loop# 75*************
22:08:17.362 -> 54 Connection lost. Trying to reconnect...
22:08:17.362 -> 57 Signal Strength = 27
22:08:17.362 -> 144 Month is 
22:08:17.362 -> 4
22:08:17.362 -> 146 Day is 
22:08:17.362 -> 23
22:08:17.362 -> *************loop# 76*************
22:08:17.589 -> 54 Connection lost. Trying to reconnect...
22:08:17.589 -> 57 Signal Strength = 27
22:08:17.589 -> 144 Month is 
22:08:17.589 -> 4
22:08:17.589 -> 146 Day is 
22:08:17.589 -> 23
22:08:17.589 -> *************loop# 77*************
22:08:17.589 -> 54 Connection lost. Trying to reconnect...
22:08:17.589 -> 57 Signal Strength = 27
22:08:19.063 -> 144 Month is 
22:08:19.063 -> 4
22:08:19.063 -> 146 Day is 
22:08:19.063 -> 23
22:08:19.063 -> *************loop# 78*************
22:08:19.063 -> 54 Connection lost. Trying to reconnect...
22:08:19.063 -> 57 Signal Strength = 27
22:08:20.235 -> 144 Month is 
22:08:20.235 -> 4
22:08:20.235 -> 146 Day is 
22:08:20.235 -> 23
22:08:20.235 -> *************loop# 79*************
22:08:20.235 -> 54 Connection lost. Trying to reconnect...
22:08:20.235 -> 57 Signal Strength = 27
22:08:20.438 -> 144 Month is 
22:08:20.438 -> 4
22:08:20.438 -> 146 Day is 
22:08:20.438 -> 23
22:08:20.438 -> *************loop# 80*************
22:08:20.438 -> 54 Connection lost. Trying to reconnect...
22:08:20.438 -> 57 Signal Strength = 27
22:08:20.756 -> 144 Month is 
22:08:20.756 -> 4
22:08:20.756 -> 146 Day is 
22:08:20.756 -> 23
22:08:20.756 -> *************loop# 81*************
22:08:20.756 -> 54 Connection lost. Trying to reconnect...
22:08:20.756 -> 57 Signal Strength = 27
22:08:23.015 -> 144 Month is 
22:08:23.015 -> 4
22:08:23.015 -> 146 Day is 
22:08:23.015 -> 23
22:08:23.015 -> *************loop# 82*************
22:08:23.015 -> 54 Connection lost. Trying to reconnect...
22:08:23.015 -> 57 Signal Strength = 27
22:08:23.509 -> 144 Month is 
22:08:23.509 -> 4
22:08:23.509 -> 146 Day is 
22:08:23.509 -> 23
22:08:23.509 -> *************loop# 83*************
22:08:23.509 -> 54 Connection lost. Trying to reconnect...
22:08:23.509 -> 57 Signal Strength = 27
22:08:23.509 -> 144 Month is 
22:08:23.509 -> 4
22:08:23.509 -> 146 Day is 
22:08:23.509 -> 23
22:08:23.509 -> *************loop# 84*************
22:08:23.509 -> 54 Connection lost. Trying to reconnect...
22:08:23.509 -> 57 Signal Strength = 27
22:08:24.998 -> 144 Month is 
22:08:24.998 -> 4
22:08:24.998 -> 146 Day is 
22:08:24.998 -> 23
22:08:24.998 -> *************loop# 85*************
22:08:24.998 -> 54 Connection lost. Trying to reconnect...
22:08:24.998 -> 57 Signal Strength = 27
22:08:24.998 -> 144 Month is 
22:08:24.998 -> 4
22:08:24.998 -> 146 Day is 
22:08:24.998 -> 23
22:08:24.998 -> *************loop# 86*************
22:08:24.998 -> 54 Connection lost. Trying to reconnect...
22:08:24.998 -> 57 Signal Strength = 27
22:08:25.206 -> 144 Month is 
22:08:25.206 -> 4
22:08:25.206 -> 146 Day is 
22:08:25.206 -> 23
22:08:25.206 -> *************loop# 87*************
22:08:25.206 -> 54 Connection lost. Trying to reconnect...
22:08:25.206 -> 57 Signal Strength = 27
22:08:26.201 -> 144 Month is 
22:08:26.201 -> 4
22:08:26.201 -> 146 Day is 
22:08:26.201 -> 23
22:08:26.201 -> *************loop# 88*************
22:08:26.201 -> 54 Connection lost. Trying to reconnect...
22:08:26.201 -> 57 Signal Strength = 27
22:08:27.496 -> 144 Month is 
22:08:27.496 -> 4
22:08:27.496 -> 146 Day is 
22:08:27.496 -> 23
22:08:27.496 -> *************loop# 89*************
22:08:27.496 -> 54 Connection lost. Trying to reconnect...
22:08:27.496 -> 57 Signal Strength = 27
22:08:27.496 -> 144 Month is 
22:08:27.496 -> 4
22:08:27.496 -> 146 Day is 
22:08:27.496 -> 23
22:08:27.496 -> *************loop# 90*************
22:08:28.789 -> 54 Connection lost. Trying to reconnect...
22:08:28.789 -> 57 Signal Strength = 27
22:08:28.789 -> 144 Month is 
22:08:28.789 -> 4
22:08:28.789 -> 146 Day is 
22:08:28.789 -> 23
22:08:28.789 -> *************loop# 91*************
22:08:28.789 -> 54 Connection lost. Trying to reconnect...
22:08:28.789 -> 57 Signal Strength = 27
22:08:29.111 -> 144 Month is 
22:08:29.111 -> 4
22:08:29.111 -> 146 Day is 
22:08:29.111 -> 23
22:08:29.111 -> *************loop# 92*************
22:08:29.111 -> 54 Connection lost. Trying to reconnect...
22:08:29.111 -> 57 Signal Strength = 27
22:08:29.943 -> 144 Month is 
22:08:29.943 -> 4
22:08:29.943 -> 146 Day is 
22:08:29.943 -> 23
22:08:29.943 -> *************loop# 93*************
22:08:29.943 -> 54 Connection lost. Trying to reconnect...
22:08:29.943 -> 57 Signal Strength = 27
22:08:31.489 -> 144 Month is 
22:08:31.489 -> 4
22:08:31.489 -> 146 Day is 
22:08:31.489 -> 23
22:08:31.489 -> *************loop# 94*************
22:08:31.489 -> 54 Connection lost. Trying to reconnect...
22:08:31.489 -> 57 Signal Strength = 27
22:08:31.489 -> 144 Month is 
22:08:31.489 -> 4
22:08:31.489 -> 146 Day is 
22:08:31.489 -> 23
22:08:31.489 -> *************loop# 95*************
22:08:31.489 -> 54 Connection lost. Trying to reconnect...
22:08:31.489 -> 57 Signal Strength = 27
22:08:32.876 -> 144 Month is 
22:08:32.876 -> 4
22:08:32.876 -> 146 Day is 
22:08:32.876 -> 23
22:08:32.876 -> *************loop# 96*************
22:08:32.876 -> 54 Connection lost. Trying to reconnect...
22:08:32.876 -> 57 Signal Strength = 27
22:08:35.036 -> 144 Month is 
22:08:35.036 -> 4
22:08:35.036 -> 146 Day is 
22:08:35.036 -> 23
22:08:35.036 -> *************loop# 97*************
22:08:35.036 -> 54 Connection lost. Trying to reconnect...
22:08:35.036 -> 57 Signal Strength = 27
22:08:35.036 -> 144 Month is 
22:08:35.036 -> 4
22:08:35.036 -> 146 Day is 
22:08:35.036 -> 23
22:08:35.036 -> *************loop# 98*************
22:08:35.036 -> 54 Connection lost. Trying to reconnect...
22:08:35.036 -> 57 Signal Strength = 27
22:08:35.726 -> 144 Month is 
22:08:35.726 -> 4
22:08:35.726 -> 146 Day is 
22:08:35.726 -> 23
22:08:35.726 -> *************loop# 99*************
22:08:35.726 -> 54 Connection lost. Trying to reconnect...
22:08:35.726 -> 57 Signal Strength = 27
22:08:35.726 -> 144 Month is 
22:08:35.726 -> 4
22:08:35.726 -> 146 Day is 
22:08:35.726 -> 23
22:08:35.726 -> *************loop# 100*************
22:08:35.726 -> 54 Connection lost. Trying to reconnect...
22:08:35.726 -> 57 Signal Strength = 27
22:08:36.346 -> 144 Month is 
22:08:36.346 -> 4
22:08:36.346 -> 146 Day is 
22:08:36.346 -> 23
22:08:36.346 -> *************loop# 101*************
22:08:36.346 -> 54 Connection lost. Trying to reconnect...
22:08:36.346 -> 57 Signal Strength = 27
22:08:37.520 -> 144 Month is 
22:08:37.520 -> 4
22:08:37.520 -> 146 Day is 
22:08:37.520 -> 23
22:08:37.520 -> *************loop# 102*************
22:08:37.520 -> 54 Connection lost. Trying to reconnect...
22:08:37.520 -> 57 Signal Strength = 27
22:08:39.132 -> 144 Month is 
22:08:39.132 -> 4
22:08:39.132 -> 146 Day is 
22:08:39.132 -> 23
22:08:39.132 -> *************loop# 103*************
22:08:39.132 -> 54 Connection lost. Trying to reconnect...
22:08:39.132 -> 57 Signal Strength = 27
22:08:39.132 -> 144 Month is 
22:08:39.132 -> 4
22:08:39.132 -> 146 Day is 
22:08:39.132 -> 23
22:08:39.132 -> *************loop# 104*************
22:08:39.132 -> 54 Connection lost. Trying to reconnect...
22:08:39.132 -> 57 Signal Strength = 27
22:08:39.869 -> 144 Month is 
22:08:39.869 -> 4
22:08:39.869 -> 146 Day is 
22:08:39.869 -> 23
22:08:39.869 -> *************loop# 105*************
22:08:39.869 -> 54 Connection lost. Trying to reconnect...
22:08:39.869 -> 57 Signal Strength = 27
22:08:41.153 -> 144 Month is 
22:08:41.153 -> 4
22:08:41.153 -> 146 Day is 
22:08:41.153 -> 23
22:08:41.153 -> *************loop# 106*************
22:08:41.153 -> 54 Connection lost. Trying to reconnect...
22:08:41.153 -> 57 Signal Strength = 27
22:08:41.153 -> 144 Month is 
22:08:41.153 -> 4
22:08:41.153 -> 146 Day is 
22:08:41.153 -> 23
22:08:41.153 -> *************loop# 107*************
22:08:41.153 -> 54 Connection lost. Trying to reconnect...
22:08:41.153 -> 57 Signal Strength = 27
22:08:42.080 -> 144 Month is 
22:08:42.080 -> 4
22:08:42.080 -> 146 Day is 
22:08:42.080 -> 23
22:08:42.080 -> *************loop# 108*************
22:08:42.080 -> 54 Connection lost. Trying to reconnect...
22:08:42.080 -> 57 Signal Strength = 27
22:08:42.966 -> 144 Month is 
22:08:42.966 -> 4
22:08:42.966 -> 146 Day is 
22:08:42.966 -> 23
22:08:42.966 -> *************loop# 109*************
22:08:42.966 -> 54 Connection lost. Trying to reconnect...
22:08:42.966 -> 57 Signal Strength = 27
22:08:44.067 -> 144 Month is 
22:08:44.067 -> 4
22:08:44.067 -> 146 Day is 
22:08:44.067 -> 23
22:08:44.067 -> *************loop# 110*************
22:08:44.067 -> 54 Connection lost. Trying to reconnect...
22:08:44.067 -> 57 Signal Strength = 27
22:08:44.888 -> 144 Month is 
22:08:44.888 -> 4
22:08:44.888 -> 146 Day is 
22:08:44.888 -> 23
22:08:44.888 -> *************loop# 111*************
22:08:44.888 -> 54 Connection lost. Trying to reconnect...
22:08:44.888 -> 57 Signal Strength = 27
22:08:44.921 -> 144 Month is 
22:08:44.921 -> 4
22:08:44.921 -> 146 Day is 
22:08:44.921 -> 23
22:08:44.921 -> *************loop# 112*************
22:08:44.921 -> 54 Connection lost. Trying to reconnect...
22:08:44.921 -> 57 Signal Strength = 27
22:08:47.028 -> 144 Month is 
22:08:47.028 -> 4
22:08:47.028 -> 146 Day is 
22:08:47.028 -> 23
22:08:47.028 -> *************loop# 113*************
22:08:47.028 -> 54 Connection lost. Trying to reconnect...
22:08:47.028 -> 57 Signal Strength = 27
22:08:47.028 -> 144 Month is 
22:08:47.028 -> 4
22:08:47.028 -> 146 Day is 
22:08:47.028 -> 23
22:08:47.028 -> *************loop# 114*************
22:08:47.028 -> 54 Connection lost. Trying to reconnect...
22:08:47.028 -> 57 Signal Strength = 28
22:08:48.847 -> 144 Month is 
22:08:48.847 -> 4
22:08:48.847 -> 146 Day is 
22:08:48.847 -> 23
22:08:48.847 -> *************loop# 115*************
22:08:48.847 -> 54 Connection lost. Trying to reconnect...
22:08:48.847 -> 57 Signal Strength = 28
22:08:50.492 -> 144 Month is 
22:08:50.492 -> 4
22:08:50.492 -> 146 Day is 
22:08:50.492 -> 23
22:08:50.492 -> *************loop# 116*************
22:08:50.492 -> 54 Connection lost. Trying to reconnect...
22:08:50.492 -> 57 Signal Strength = 28
22:08:50.492 -> 144 Month is 
22:08:50.492 -> 4
22:08:50.492 -> 146 Day is 
22:08:50.492 -> 23
22:08:50.492 -> *************loop# 117*************
22:08:50.492 -> 54 Connection lost. Trying to reconnect...
22:08:50.492 -> 57 Signal Strength = 28
22:08:50.492 -> 144 Month is 
22:08:50.492 -> 4
22:08:50.492 -> 146 Day is 
22:08:50.492 -> 23
22:08:50.492 -> *************loop# 118*************
22:08:50.492 -> 54 Connection lost. Trying to reconnect...
22:08:50.492 -> 57 Signal Strength = 28
22:08:50.492 -> 144 Month is 
22:08:50.492 -> 4
22:08:50.492 -> 146 Day is 
22:08:50.492 -> 23
22:08:50.492 -> *************loop# 119*************
22:08:50.492 -> 54 Connection lost. Trying to reconnect...
22:08:50.492 -> 57 Signal Strength = 28
22:08:51.536 -> 144 Month is 
22:08:51.536 -> 4
22:08:51.536 -> 146 Day is 
22:08:51.536 -> 23
22:08:51.536 -> *************loop# 120*************
22:08:51.536 -> 54 Connection lost. Trying to reconnect...
22:08:51.536 -> 57 Signal Strength = 28
22:08:52.010 -> 144 Month is 
22:08:52.010 -> 4
22:08:52.010 -> 146 Day is 
22:08:52.010 -> 23
22:08:52.010 -> *************loop# 121*************
22:08:52.010 -> 54 Connection lost. Trying to reconnect...
22:08:52.010 -> 57 Signal Strength = 28
22:08:52.820 -> 144 Month is 
22:08:52.820 -> 4
22:08:52.820 -> 146 Day is 
22:08:52.820 -> 23
22:08:52.820 -> *************loop# 122*************
22:08:52.820 -> 54 Connection lost. Trying to reconnect...
22:08:52.820 -> 57 Signal Strength = 28
22:08:53.924 -> 144 Month is 
22:08:53.924 -> 4
22:08:53.924 -> 146 Day is 
22:08:53.924 -> 23
22:08:53.924 -> *************loop# 123*************
22:08:53.924 -> 54 Connection lost. Trying to reconnect...
22:08:53.924 -> 57 Signal Strength = 28
22:08:55.883 -> 144 Month is 
22:08:55.883 -> 4
22:08:55.883 -> 146 Day is 
22:08:55.883 -> 23
22:08:55.883 -> *************loop# 124*************
22:08:55.883 -> 54 Connection lost. Trying to reconnect...
22:08:55.883 -> 57 Signal Strength = 28
22:08:55.883 -> 144 Month is 
22:08:55.883 -> 4
22:08:55.883 -> 146 Day is 
22:08:55.883 -> 23
22:08:55.883 -> *************loop# 125*************
22:08:55.883 -> 54 Connection lost. Trying to reconnect...
22:08:55.883 -> 57 Signal Strength = 28
22:08:56.128 -> 144 Month is 
22:08:56.128 -> 4
22:08:56.128 -> 146 Day is 
22:08:56.128 -> 23
22:08:56.128 -> *************loop# 126*************
22:08:56.128 -> 54 Connection lost. Trying to reconnect...
22:08:56.128 -> 57 Signal Strength = 28
22:08:56.722 -> 144 Month is 
22:08:56.722 -> 4
22:08:56.722 -> 146 Day is 
22:08:56.722 -> 23
22:08:56.722 -> *************loop# 127*************
22:08:56.755 -> 54 Connection lost. Trying to reconnect...
22:08:56.755 -> 57 Signal Strength = 28
22:08:57.578 -> 144 Month is 
22:08:57.578 -> 4
22:08:57.578 -> 146 Day is 
22:08:57.578 -> 23
22:08:57.578 -> *************loop# 128*************
22:08:57.578 -> 54 Connection lost. Trying to reconnect...
22:08:57.578 -> 57 Signal Strength = 28
22:08:58.709 -> 144 Month is 
22:08:58.709 -> 4
22:08:58.709 -> 146 Day is 
22:08:58.709 -> 23
22:08:58.709 -> *************loop# 129*************
22:08:58.709 -> 54 Connection lost. Trying to reconnect...
22:08:58.709 -> 57 Signal Strength = 28
22:08:59.175 -> 144 Month is 
22:08:59.175 -> 4
22:08:59.175 -> 146 Day is 
22:08:59.175 -> 23
22:08:59.175 -> *************loop# 130*************
22:08:59.175 -> 54 Connection lost. Trying to reconnect...
22:08:59.175 -> 57 Signal Strength = 28
22:08:59.868 -> 144 Month is 
22:08:59.868 -> 4
22:08:59.868 -> 146 Day is 
22:08:59.868 -> 23
22:08:59.868 -> *************loop# 131*************
22:08:59.970 -> 54 Connection lost. Trying to reconnect...
22:08:59.970 -> 57 Signal Strength = 28
22:09:00.711 -> 144 Month is 
22:09:00.711 -> 4
22:09:00.711 -> 146 Day is 
22:09:00.711 -> 23
22:09:00.711 -> *************loop# 132*************
22:09:00.711 -> 54 Connection lost. Trying to reconnect...
22:09:00.711 -> 57 Signal Strength = 28
22:09:03.307 -> 144 Month is 
22:09:03.307 -> 4
22:09:03.307 -> 146 Day is 
22:09:03.307 -> 23
22:09:03.307 -> *************loop# 133*************
22:09:03.307 -> 54 Connection lost. Trying to reconnect...
22:09:03.307 -> 57 Signal Strength = 28
22:09:03.307 -> 144 Month is 
22:09:03.307 -> 4
22:09:03.307 -> 146 Day is 
22:09:03.307 -> 23
22:09:03.307 -> *************loop# 134*************
22:09:03.307 -> 54 Connection lost. Trying to reconnect...
22:09:03.307 -> 57 Signal Strength = 28
22:09:03.307 -> 144 Month is 
22:09:03.307 -> 4
22:09:03.307 -> 146 Day is 
22:09:03.307 -> 23
22:09:03.307 -> *************loop# 135*************
22:09:03.307 -> 54 Connection lost. Trying to reconnect...
22:09:03.307 -> 57 Signal Strength = 28
22:09:03.907 -> 144 Month is 
22:09:03.907 -> 4
22:09:03.907 -> 146 Day is 
22:09:03.907 -> 23
22:09:03.907 -> *************loop# 136*************
22:09:03.907 -> 54 Connection lost. Trying to reconnect...
22:09:03.907 -> 57 Signal Strength = 28
22:09:04.892 -> 144 Month is 
22:09:04.892 -> 4
22:09:04.892 -> 146 Day is 
22:09:04.892 -> 23
22:09:04.892 -> *************loop# 137*************
22:09:04.892 -> 54 Connection lost. Trying to reconnect...
22:09:04.892 -> 57 Signal Strength = 28
22:09:05.398 -> 144 Month is 
22:09:05.398 -> 4
22:09:05.398 -> 146 Day is 
22:09:05.398 -> 23
22:09:05.398 -> *************loop# 138*************
22:09:05.768 -> 54 Connection lost. Trying to reconnect...
22:09:05.768 -> 57 Signal Strength = 28
22:09:08.425 -> 144 Month is 
22:09:08.425 -> 4
22:09:08.425 -> 146 Day is 
22:09:08.425 -> 23
22:09:08.425 -> *************loop# 139*************
22:09:08.425 -> 54 Connection lost. Trying to reconnect...
22:09:08.425 -> 57 Signal Strength = 28
22:09:08.425 -> 144 Month is 
22:09:08.425 -> 4
22:09:08.425 -> 146 Day is 
22:09:08.425 -> 23
22:09:08.425 -> *************loop# 140*************
22:09:08.425 -> 54 Connection lost. Trying to reconnect...
22:09:08.425 -> 57 Signal Strength = 28
22:09:08.425 -> 144 Month is 
22:09:08.425 -> 4
22:09:08.425 -> 146 Day is 
22:09:08.425 -> 23
22:09:08.425 -> *************loop# 141*************
22:09:08.425 -> 54 Connection lost. Trying to reconnect...
22:09:08.425 -> 57 Signal Strength = 28
22:09:10.077 -> 144 Month is 
22:09:10.077 -> 4
22:09:10.077 -> 146 Day is 
22:09:10.077 -> 23
22:09:10.077 -> *************loop# 142*************
22:09:10.077 -> 54 Connection lost. Trying to reconnect...
22:09:10.077 -> 57 Signal Strength = 28
22:09:10.077 -> 144 Month is 
22:09:10.077 -> 4
22:09:10.077 -> 146 Day is 
22:09:10.077 -> 23
22:09:10.077 -> *************loop# 143*************
22:09:10.077 -> 54 Connection lost. Trying to reconnect...
22:09:10.077 -> 57 Signal Strength = 28
22:09:10.709 -> 144 Month is 
22:09:10.709 -> 4
22:09:10.709 -> 146 Day is 
22:09:10.709 -> 23
22:09:10.709 -> *************loop# 144*************
22:09:10.709 -> 54 Connection lost. Trying to reconnect...
22:09:10.709 -> 57 Signal Strength = 28
22:09:11.496 -> 144 Month is 
22:09:11.496 -> 4
22:09:11.496 -> 146 Day is 
22:09:11.496 -> 23
22:09:11.496 -> *************loop# 145*************
22:09:11.496 -> 54 Connection lost. Trying to reconnect...
22:09:11.496 -> 57 Signal Strength = 28
22:09:11.805 -> 144 Month is 
22:09:11.805 -> 4
22:09:11.805 -> 146 Day is 
22:09:11.805 -> 23
22:09:11.805 -> *************loop# 146*************
22:09:11.805 -> 54 Connection lost. Trying to reconnect...
22:09:11.805 -> 57 Signal Strength = 28
22:09:12.514 -> 144 Month is 
22:09:12.514 -> 4
22:09:12.514 -> 146 Day is 
22:09:12.514 -> 23
22:09:12.514 -> *************loop# 147*************
22:09:12.514 -> 54 Connection lost. Trying to reconnect...
22:09:12.514 -> 57 Signal Strength = 28
22:09:13.709 -> 144 Month is 
22:09:13.709 -> 4
22:09:13.709 -> 146 Day is 
22:09:13.709 -> 23
22:09:13.709 -> *************loop# 148*************
22:09:13.709 -> 54 Connection lost. Trying to reconnect...
22:09:13.709 -> 57 Signal Strength = 28
22:09:14.239 -> 144 Month is 
22:09:14.239 -> 4
22:09:14.239 -> 146 Day is 
22:09:14.239 -> 23
22:09:14.239 -> *************loop# 149*************
22:09:14.239 -> 54 Connection lost. Trying to reconnect...
22:09:14.239 -> 57 Signal Strength = 28
22:09:16.131 -> 144 Month is 
22:09:16.131 -> 4
22:09:16.131 -> 146 Day is 
22:09:16.131 -> 23
22:09:16.131 -> *************loop# 150*************
22:09:16.131 -> 54 Connection lost. Trying to reconnect...
22:09:16.131 -> 57 Signal Strength = 28
22:09:16.131 -> 144 Month is 
22:09:16.131 -> 4
22:09:16.131 -> 146 Day is 
22:09:16.131 -> 23
22:09:16.131 -> *************loop# 151*************
22:09:16.131 -> 54 Connection lost. Trying to reconnect...
22:09:16.131 -> 57 Signal Strength = 28
22:09:17.270 -> 144 Month is 
22:09:17.270 -> 4
22:09:17.270 -> 146 Day is 
22:09:17.270 -> 23
22:09:17.270 -> *************loop# 152*************
22:09:17.270 -> 54 Connection lost. Trying to reconnect...
22:09:17.270 -> 57 Signal Strength = 28
22:09:17.522 -> 144 Month is 
22:09:17.522 -> 4
22:09:17.522 -> 146 Day is 
22:09:17.522 -> 23
22:09:17.522 -> *************loop# 153*************
22:09:17.522 -> 54 Connection lost. Trying to reconnect...
22:09:17.522 -> 57 Signal Strength = 28
22:09:18.925 -> 144 Month is 
22:09:18.925 -> 4
22:09:18.925 -> 146 Day is 
22:09:18.925 -> 23
22:09:18.925 -> *************loop# 154*************
22:09:18.925 -> 54 Connection lost. Trying to reconnect...
22:09:18.925 -> 57 Signal Strength = 28
22:09:18.925 -> 144 Month is 
22:09:18.925 -> 4
22:09:18.925 -> 146 Day is 
22:09:18.925 -> 23
22:09:18.925 -> *************loop# 155*************
22:09:18.925 -> 54 Connection lost. Trying to reconnect...
22:09:18.925 -> 57 Signal Strength = 28
22:09:20.105 -> 144 Month is 
22:09:20.105 -> 4
22:09:20.105 -> 146 Day is 
22:09:20.105 -> 23
22:09:20.105 -> *************loop# 156*************
22:09:20.105 -> 54 Connection lost. Trying to reconnect...
22:09:20.105 -> 57 Signal Strength = 28
22:09:20.650 -> 144 Month is 
22:09:20.650 -> 4
22:09:20.650 -> 146 Day is 
22:09:20.650 -> 23
22:09:20.650 -> *************loop# 157*************
22:09:20.650 -> 54 Connection lost. Trying to reconnect...
22:09:20.650 -> 57 Signal Strength = 28
22:09:21.216 -> 144 Month is 
22:09:21.216 -> 4
22:09:21.216 -> 146 Day is 
22:09:21.216 -> 23
22:09:21.216 -> *************loop# 158*************
22:09:21.216 -> 54 Connection lost. Trying to reconnect...
22:09:21.216 -> 57 Signal Strength = 28
22:09:23.470 -> 144 Month is 
22:09:23.470 -> 4
22:09:23.470 -> 146 Day is 
22:09:23.470 -> 23
22:09:23.470 -> *************loop# 159*************
22:09:23.470 -> 54 Connection lost. Trying to reconnect...
22:09:23.470 -> 57 Signal Strength = 28
22:09:23.470 -> 144 Month is 
22:09:23.470 -> 4
22:09:23.470 -> 146 Day is 
22:09:23.470 -> 23
22:09:23.470 -> *************loop# 160*************
22:09:23.470 -> 54 Connection lost. Trying to reconnect...
22:09:23.470 -> 57 Signal Strength = 28
22:09:23.558 -> 144 Month is 
22:09:23.558 -> 4
22:09:23.558 -> 146 Day is 
22:09:23.558 -> 23
22:09:23.558 -> *************loop# 161*************
22:09:24.652 -> 54 Connection lost. Trying to reconnect...
22:09:24.652 -> 57 Signal Strength = 28
22:09:24.652 -> 144 Month is 
22:09:24.652 -> 4
22:09:24.652 -> 146 Day is 
22:09:24.652 -> 23
22:09:24.652 -> *************loop# 162*************
22:09:24.652 -> 54 Connection lost. Trying to reconnect...
22:09:24.652 -> 57 Signal Strength = 28
22:09:26.421 -> 144 Month is 
22:09:26.421 -> 4
22:09:26.421 -> 146 Day is 
22:09:26.421 -> 23
22:09:26.421 -> *************loop# 163*************
22:09:26.421 -> 54 Connection lost. Trying to reconnect...
22:09:26.421 -> 57 Signal Strength = 28
22:09:26.421 -> 144 Month is 
22:09:26.421 -> 4
22:09:26.421 -> 146 Day is 
22:09:26.421 -> 23
22:09:26.421 -> *************loop# 164*************
22:09:26.421 -> 54 Connection lost. Trying to reconnect...
22:09:26.421 -> 57 Signal Strength = 28
22:09:26.728 -> 144 Month is 
22:09:26.728 -> 4
22:09:26.728 -> 146 Day is 
22:09:26.728 -> 23
22:09:26.728 -> *************loop# 165*************
22:09:28.712 -> 54 Connection lost. Trying to reconnect...
22:09:28.712 -> 57 Signal Strength = 28
22:09:28.712 -> 144 Month is 
22:09:28.712 -> 4
22:09:28.712 -> 146 Day is 
22:09:28.712 -> 23
22:09:28.712 -> *************loop# 166*************
22:09:28.712 -> 54 Connection lost. Trying to reconnect...
22:09:28.712 -> 57 Signal Strength = 28
22:09:28.712 -> 144 Month is 
22:09:28.712 -> 4
22:09:28.712 -> 146 Day is 
22:09:28.712 -> 23
22:09:28.712 -> *************loop# 167*************
22:09:28.712 -> 54 Connection lost. Trying to reconnect...
22:09:28.712 -> 57 Signal Strength = 28
22:09:29.830 -> 144 Month is 
22:09:29.830 -> 4
22:09:29.830 -> 146 Day is 
22:09:29.830 -> 23
22:09:29.830 -> *************loop# 168*************
22:09:29.830 -> 54 Connection lost. Trying to reconnect...
22:09:29.830 -> 57 Signal Strength = 28
22:09:32.753 -> 144 Month is 
22:09:32.753 -> 4
22:09:32.753 -> 146 Day is 
22:09:32.753 -> 23
22:09:32.753 -> *************loop# 169*************
22:09:32.753 -> 54 Connection lost. Trying to reconnect...
22:09:32.753 -> 57 Signal Strength = 28
22:09:32.753 -> 144 Month is 
22:09:32.753 -> 4
22:09:32.753 -> 146 Day is 
22:09:32.753 -> 23
22:09:32.753 -> *************loop# 170*************
22:09:32.753 -> 54 Connection lost. Trying to reconnect...
22:09:32.753 -> 57 Signal Strength = 28
22:09:32.753 -> 144 Month is 
22:09:32.753 -> 4
22:09:32.753 -> 146 Day is 
22:09:32.753 -> 23
22:09:32.753 -> *************loop# 171*************
22:09:32.753 -> 54 Connection lost. Trying to reconnect...
22:09:32.753 -> 57 Signal Strength = 28
22:09:32.753 -> 144 Month is 
22:09:32.753 -> 4
22:09:32.753 -> 146 Day is 
22:09:32.753 -> 23
22:09:32.753 -> *************loop# 172*************
22:09:32.753 -> 54 Connection lost. Trying to reconnect...
22:09:32.753 -> 57 Signal Strength = 28
22:09:33.703 -> 144 Month is 
22:09:33.703 -> 4
22:09:33.703 -> 146 Day is 
22:09:33.703 -> 23
22:09:33.703 -> *************loop# 173*************
22:09:33.703 -> 54 Connection lost. Trying to reconnect...
22:09:33.703 -> 57 Signal Strength = 28
22:09:34.486 -> 144 Month is 
22:09:34.486 -> 4
22:09:34.486 -> 146 Day is 
22:09:34.486 -> 23
22:09:34.486 -> *************loop# 174*************
22:09:34.486 -> 54 Connection lost. Trying to reconnect...
22:09:34.486 -> 57 Signal Strength = 28
22:09:35.774 -> 144 Month is 
22:09:35.774 -> 4
22:09:35.774 -> 146 Day is 
22:09:35.774 -> 23
22:09:35.774 -> *************loop# 175*************
22:09:35.774 -> 54 Connection lost. Trying to reconnect...
22:09:35.774 -> 57 Signal Strength = 28
22:09:35.774 -> 144 Month is 
22:09:35.774 -> 4
22:09:35.774 -> 146 Day is 
22:09:35.774 -> 23
22:09:35.774 -> *************loop# 176*************
22:09:35.774 -> 54 Connection lost. Trying to reconnect...
22:09:35.774 -> 57 Signal Strength = 28
22:09:37.969 -> 144 Month is 
22:09:37.969 -> 4
22:09:37.969 -> 146 Day is 
22:09:37.969 -> 23
22:09:37.969 -> *************loop# 177*************
22:09:37.969 -> 54 Connection lost. Trying to reconnect...
22:09:37.969 -> 57 Signal Strength = 28
22:09:37.969 -> 144 Month is 
22:09:37.969 -> 4
22:09:37.969 -> 146 Day is 
22:09:37.969 -> 23
22:09:37.969 -> *************loop# 178*************
22:09:37.969 -> 54 Connection lost. Trying to reconnect...
22:09:37.969 -> 57 Signal Strength = 28
22:09:37.969 -> 144 Month is 
22:09:37.969 -> 4
22:09:37.969 -> 146 Day is 
22:09:37.969 -> 23
22:09:37.969 -> *************loop# 179*************
22:09:37.969 -> 54 Connection lost. Trying to reconnect...
22:09:37.969 -> 57 Signal Strength = 28
22:09:39.234 -> 144 Month is 
22:09:39.234 -> 4
22:09:39.234 -> 146 Day is 
22:09:39.234 -> 23
22:09:39.234 -> *************loop# 180*************
22:09:39.234 -> 54 Connection lost. Trying to reconnect...
22:09:39.234 -> 57 Signal Strength = 28
22:09:40.410 -> 144 Month is 
22:09:40.410 -> 4
22:09:40.410 -> 146 Day is 
22:09:40.410 -> 23
22:09:40.410 -> *************loop# 181*************
22:09:40.410 -> 54 Connection lost. Trying to reconnect...
22:09:40.410 -> 57 Signal Strength = 28
22:09:40.410 -> 144 Month is 
22:09:40.410 -> 4
22:09:40.410 -> 146 Day is 
22:09:40.410 -> 23
22:09:40.410 -> *************loop# 182*************
22:09:40.410 -> 54 Connection lost. Trying to reconnect...
22:09:40.410 -> 57 Signal Strength = 28
22:09:41.530 -> 144 Month is 
22:09:41.530 -> 4
22:09:41.530 -> 146 Day is 
22:09:41.530 -> 23
22:09:41.530 -> *************loop# 183*************
22:09:41.530 -> 54 Connection lost. Trying to reconnect...
22:09:41.530 -> 57 Signal Strength = 28
22:09:41.950 -> 144 Month is 
22:09:41.950 -> 4
22:09:41.950 -> 146 Day is 
22:09:41.950 -> 23
22:09:41.950 -> *************loop# 184*************
22:09:41.950 -> 54 Connection lost. Trying to reconnect...
22:09:41.950 -> 57 Signal Strength = 28
22:09:42.686 -> 144 Month is 
22:09:42.686 -> 4
22:09:42.686 -> 146 Day is 
22:09:42.686 -> 23
22:09:42.686 -> *************loop# 185*************
22:09:42.686 -> 54 Connection lost. Trying to reconnect...
22:09:42.686 -> 57 Signal Strength = 28
22:09:43.589 -> 144 Month is 
22:09:43.589 -> 4
22:09:43.589 -> 146 Day is 
22:09:43.589 -> 23
22:09:43.589 -> *************loop# 186*************
22:09:43.589 -> 54 Connection lost. Trying to reconnect...
22:09:43.589 -> 57 Signal Strength = 28
22:09:44.911 -> 144 Month is 
22:09:44.911 -> 4
22:09:44.911 -> 146 Day is 
22:09:44.911 -> 23
22:09:44.911 -> *************loop# 187*************
22:09:44.911 -> 54 Connection lost. Trying to reconnect...
22:09:44.911 -> 57 Signal Strength = 28
22:09:44.911 -> 144 Month is 
22:09:44.911 -> 4
22:09:44.911 -> 146 Day is 
22:09:44.911 -> 23
22:09:44.911 -> *************loop# 188*************
22:09:44.911 -> 54 Connection lost. Trying to reconnect...
22:09:44.911 -> 57 Signal Strength = 28
22:09:47.148 -> 144 Month is 
22:09:47.148 -> 4
22:09:47.148 -> 146 Day is 
22:09:47.148 -> 23
22:09:47.148 -> *************loop# 189*************
22:09:47.148 -> 54 Connection lost. Trying to reconnect...
22:09:47.148 -> 57 Signal Strength = 28
22:09:47.992 -> 144 Month is 
22:09:47.992 -> 4
22:09:47.992 -> 146 Day is 
22:09:47.992 -> 23
22:09:47.992 -> *************loop# 190*************
22:09:47.992 -> 54 Connection lost. Trying to reconnect...
22:09:47.992 -> 57 Signal Strength = 28
22:09:48.252 -> 144 Month is 
22:09:48.252 -> 4
22:09:48.252 -> 146 Day is 
22:09:48.252 -> 23
22:09:48.252 -> *************loop# 191*************
22:09:48.252 -> 54 Connection lost. Trying to reconnect...
22:09:48.252 -> 57 Signal Strength = 28
22:09:50.322 -> 144 Month is 
22:09:50.322 -> 4
22:09:50.322 -> 146 Day is 
22:09:50.322 -> 23
22:09:50.322 -> *************loop# 192*************
22:09:50.322 -> 54 Connection lost. Trying to reconnect...
22:09:50.322 -> 57 Signal Strength = 28
22:09:50.897 -> 144 Month is 
22:09:50.897 -> 4
22:09:50.897 -> 146 Day is 
22:09:50.897 -> 23
22:09:50.897 -> *************loop# 193*************
22:09:50.897 -> 54 Connection lost. Trying to reconnect...
22:09:50.897 -> 57 Signal Strength = 28
22:09:50.897 -> 144 Month is 
22:09:50.897 -> 4
22:09:50.897 -> 146 Day is 
22:09:50.897 -> 23
22:09:50.897 -> *************loop# 194*************
22:09:50.897 -> 54 Connection lost. Trying to reconnect...
22:09:50.897 -> 57 Signal Strength = 29
22:09:50.897 -> 144 Month is 
22:09:50.897 -> 4
22:09:50.897 -> 146 Day is 
22:09:50.897 -> 23
22:09:50.897 -> *************loop# 195*************
22:09:50.897 -> 54 Connection lost. Trying to reconnect...
22:09:50.897 -> 57 Signal Strength = 29
22:09:52.489 -> 144 Month is 
22:09:52.489 -> 4
22:09:52.489 -> 146 Day is 
22:09:52.489 -> 23
22:09:52.489 -> *************loop# 196*************
22:09:52.489 -> 54 Connection lost. Trying to reconnect...
22:09:52.489 -> 57 Signal Strength = 29
22:09:54.034 -> 144 Month is 
22:09:54.034 -> 4
22:09:54.034 -> 146 Day is 
22:09:54.034 -> 23
22:09:54.034 -> *************loop# 197*************
22:09:54.034 -> 54 Connection lost. Trying to reconnect...
22:09:54.034 -> 57 Signal Strength = 29
22:09:54.034 -> 144 Month is 
22:09:54.034 -> 4
22:09:54.034 -> 146 Day is 
22:09:54.034 -> 23
22:09:54.034 -> *************loop# 198*************
22:09:54.034 -> 54 Connection lost. Trying to reconnect...
22:09:54.034 -> 57 Signal Strength = 29
22:09:54.034 -> 144 Month is 
22:09:54.034 -> 4
22:09:54.034 -> 146 Day is 
22:09:54.034 -> 23
22:09:54.034 -> *************loop# 199*************
22:09:54.034 -> 54 Connection lost. Trying to reconnect...
22:09:54.034 -> 57 Signal Strength = 29
22:09:54.561 -> 144 Month is 
22:09:54.561 -> 4
22:09:54.561 -> 146 Day is 
22:09:54.561 -> 23
22:09:54.561 -> *************loop# 200*************
22:09:54.561 -> 54 Connection lost. Trying to reconnect...
22:09:54.561 -> 57 Signal Strength = 29
22:09:55.466 -> 144 Month is 
22:09:55.466 -> 4
22:09:55.466 -> 146 Day is 
22:09:55.466 -> 23

```

---

<div class="post-metadata">

**Author:** ![Hutkikz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hutkikz/32/218764_2.png) [@Hutkikz](https://forum.arduino.cc/u/Hutkikz)\
**Post date:** [April 23, 2023, 8:25pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/15 "2023-04-23T20:25:47Z")

</div>

I hear ya.  
I might be on to something.  
Try this:

```plaintext
#include <MKRGSM.h>
#include <TimeLib.h>

// GSM and GPRS instances
GSM gsmAccess;
GPRS gprs;
GSMScanner GSMScan;
GSMVoiceCall voiceCall;
GSM_SMS sms;

// Relay and LED pins
const int relayPin = 1;
char PINNUMBER [] = ""; // PIN-Code of the Simcard
const int ledPin = LED_BUILTIN;

// Whitelisted numbers
const char *whitelist[] = {"+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789"};
const int whitelistSize = sizeof(whitelist) / sizeof(whitelist[0]);

// Phone number to send text message
const char *textMessagePhoneNumber = "+00123456789";

// Pre-composed text message
const char *textMessage = "This is an automated message. I'm online.";

// Variables for text message sending interval
int lastSentMonth = -1;

bool connected = false;
unsigned long lastGSMCheck = 0;
unsigned long checkInterval = 60000; // Check connection every 30 seconds
unsigned long reconnectTimeout = 60000; // 30 seconds timeout

void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);
  while (!Serial); // wait for Serial to initialize so we don't miss any messages

  Serial.println("42 Booting.");
  delay(5000); // Give the GSM module some time to initialize
  connectToCarrier();
}

void loop() {
  static int loopCounter;
  Serial.print(" ************* loop# ");
  Serial.print(++loopCounter);
  Serial.println(" *************");

  // Check GSM connection
  if (gsmAccess.isAccessAlive()) {
    Serial.println("57 Connection stable");
  }
  else {
    digitalWrite(ledPin, LOW); // Turn LED off.
    Serial.println("61 Connection lost. Trying to reconnect...");
    connectToCarrier();
  }
  Serial.print("64 Signal Strength = ");
  Serial.println(GSMScan.getSignalStrength());
  checkForVoiceCall();
  checkForTextMessage();
  sendTextMessageEveryThreeMonths();
}

void connectToCarrier() {
  static bool connected = false;
  static int retries = 0;
  const int maxRetries = 5;

  while (!connected && retries < maxRetries) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      connected = true;
      digitalWrite(ledPin, HIGH); // Solid: connected
      Serial.print("80 GSM initialized. - ");
      Serial.println("Awaiting Call.");
      Serial.println("");
    } else {
      connected = false;
      Serial.print("85 Not connected retry# ");
      retries++;
      Serial.println(retries);
      delay(1000);
    }
  }

  if (retries >= maxRetries) {
    Serial.println("93 Failed to connect after maximum retries. Restarting the board.");
    NVIC_SystemReset();
  }
}

void checkForVoiceCall() {
  if (voiceCall.getvoiceCallStatus() == RECEIVINGCALL) {
    char phoneNumber[20];
    voiceCall.retrieveCallingNumber(phoneNumber, 20);

    bool isWhitelisted = false;
    for (int i = 0; i < whitelistSize; i++) {
      if (strcmp(phoneNumber, whitelist[i]) == 0) {
        isWhitelisted = true;
        break;
      }
    }

    voiceCall.hangCall();

    if (isWhitelisted) { // If whitelisted person calls, activate the relay.
      activateRelay();

      delay(10000);

      Serial.println("119 WhiteListed system reset");
      NVIC_SystemReset(); // I've tried the code with and without this line. I was trying whether it would be better to just restart the whole setup everytime some had called, it made no difference.
    }
  }
}

void checkForTextMessage() {
  if (sms.available()) {
    char phoneNumber[20];
    sms.remoteNumber(phoneNumber, 20);

    sms.flush(); // Flush the message
  }
}

void activateRelay() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(relayPin, HIGH);
    delay(2000);
    digitalWrite(relayPin, LOW);
    delay(250);
  }
}

void sendTextMessageEveryThreeMonths() {
  time_t currentTime = gsmAccess.getTime();
  int currentMonth = month(currentTime);
  int currentDay = day(currentTime);
  Serial.println("147 Month is ");
  Serial.println(currentMonth);
  Serial.println("149 Day is ");
  Serial.println(currentDay);

  if ((currentMonth - lastSentMonth) % 3 == 0 && currentDay == 1 && currentMonth != lastSentMonth) {
    Serial.print("153 Send Textmessage. Online.");

    sms.beginSMS(textMessagePhoneNumber);
    sms.print(textMessage);
    sms.endSMS();
    Serial.println("158 \nCOMPLETE!\n");

    lastSentMonth = currentMonth;
  }
}
```

---

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [April 23, 2023, 9:06pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/16 "2023-04-23T21:06:32Z")

</div>

Well that did something! It does stay connected quite stably I'd say. At least it establishes a connection and tries to maintain it!

It produced the following serial:

```plaintext
22:53:55.558 -> 42 Booting.
22:54:15.179 -> 80 GSM initialized. - Awaiting Call.
22:54:15.179 -> 
22:54:15.179 -> *************loop# 1*************
22:54:15.179 -> 57 Connection stable
22:54:15.179 -> 64 Signal Strength = 26
22:54:15.938 -> 147 Month is 
22:54:15.938 -> 4
22:54:15.938 -> 149 Day is 
22:54:15.938 -> 23
22:54:15.938 -> *************loop# 2*************
22:54:15.973 -> 57 Connection stable
22:54:15.973 -> 64 Signal Strength = 26
22:54:16.729 -> 147 Month is 
22:54:16.729 -> 4
22:54:16.729 -> 149 Day is 
22:54:16.729 -> 23
22:54:16.729 -> *************loop# 3*************
22:54:16.762 -> 57 Connection stable
22:54:16.762 -> 64 Signal Strength = 26
22:54:17.513 -> 147 Month is 
22:54:17.513 -> 4
22:54:17.513 -> 149 Day is 
22:54:17.513 -> 23
22:54:17.513 -> *************loop# 4*************
22:54:17.546 -> 57 Connection stable
22:54:17.546 -> 64 Signal Strength = 26
22:54:18.309 -> 147 Month is 
22:54:18.309 -> 4
22:54:18.309 -> 149 Day is 
22:54:18.309 -> 23
22:54:18.309 -> *************loop# 5*************
22:54:18.343 -> 57 Connection stable
22:54:18.343 -> 64 Signal Strength = 25
22:54:19.118 -> 147 Month is 
22:54:19.118 -> 4
22:54:19.118 -> 149 Day is 
22:54:19.118 -> 23
22:54:19.118 -> *************loop# 6*************
22:54:19.118 -> 57 Connection stable
22:54:19.118 -> 64 Signal Strength = 25
22:54:19.890 -> 147 Month is 
22:54:19.890 -> 4
22:54:19.890 -> 149 Day is 
22:54:19.890 -> 23
22:54:19.890 -> *************loop# 7*************
22:54:19.924 -> 57 Connection stable
22:54:19.924 -> 64 Signal Strength = 25
22:54:20.681 -> 147 Month is 
22:54:20.681 -> 4
22:54:20.681 -> 149 Day is 
22:54:20.681 -> 23
22:54:20.681 -> *************loop# 8*************
22:54:20.715 -> 57 Connection stable
22:54:20.715 -> 64 Signal Strength = 25
22:54:21.464 -> 147 Month is 
22:54:21.464 -> 4
22:54:21.464 -> 149 Day is 
22:54:21.464 -> 23
22:54:21.464 -> *************loop# 9*************
22:54:21.499 -> 57 Connection stable
22:54:21.499 -> 64 Signal Strength = 25
22:54:22.260 -> 147 Month is 
22:54:22.260 -> 4
22:54:22.260 -> 149 Day is 
22:54:22.260 -> 23
22:54:22.260 -> *************loop# 10*************
22:54:22.294 -> 57 Connection stable
22:54:22.294 -> 64 Signal Strength = 25
22:54:23.058 -> 147 Month is 
22:54:23.058 -> 4
22:54:23.058 -> 149 Day is 
22:54:23.058 -> 23
22:54:23.058 -> *************loop# 11*************
22:54:23.092 -> 57 Connection stable
22:54:23.092 -> 64 Signal Strength = 25
22:54:23.837 -> 147 Month is 
22:54:23.837 -> 4
22:54:23.837 -> 149 Day is 
22:54:23.837 -> 23
22:54:23.837 -> *************loop# 12*************
22:54:23.875 -> 57 Connection stable
22:54:23.875 -> 64 Signal Strength = 25
22:54:24.644 -> 147 Month is 
22:54:24.644 -> 4
22:54:24.644 -> 149 Day is 
22:54:24.644 -> 23
22:54:24.644 -> *************loop# 13*************
22:54:24.644 -> 57 Connection stable
22:54:24.644 -> 64 Signal Strength = 25
22:54:25.413 -> 147 Month is 
22:54:25.413 -> 4
22:54:25.413 -> 149 Day is 
22:54:25.413 -> 23
22:54:25.413 -> *************loop# 14*************
22:54:25.446 -> 57 Connection stable
22:54:25.446 -> 64 Signal Strength = 25
22:54:26.207 -> 147 Month is 
22:54:26.207 -> 4
22:54:26.207 -> 149 Day is 
22:54:26.207 -> 23
22:54:26.207 -> *************loop# 15*************
22:54:26.240 -> 57 Connection stable
22:54:26.240 -> 64 Signal Strength = 25
22:54:27.004 -> 147 Month is 
22:54:27.004 -> 4
22:54:27.004 -> 149 Day is 
22:54:27.004 -> 23
22:54:27.004 -> *************loop# 16*************
22:54:27.004 -> 57 Connection stable
22:54:27.004 -> 64 Signal Strength = 25
22:54:27.795 -> 147 Month is 
22:54:27.795 -> 4
22:54:27.795 -> 149 Day is 
22:54:27.795 -> 23
22:54:27.795 -> *************loop# 17*************
22:54:27.795 -> 57 Connection stable
22:54:27.795 -> 64 Signal Strength = 25
22:54:28.563 -> 147 Month is 
22:54:28.563 -> 4
22:54:28.563 -> 149 Day is 
22:54:28.563 -> 23
22:54:28.563 -> *************loop# 18*************
22:54:28.598 -> 57 Connection stable
22:54:28.598 -> 64 Signal Strength = 25
22:54:29.356 -> 147 Month is 
22:54:29.356 -> 4
22:54:29.356 -> 149 Day is 
22:54:29.356 -> 23
22:54:29.356 -> *************loop# 19*************
22:54:29.391 -> 57 Connection stable
22:54:29.391 -> 64 Signal Strength = 25
22:54:30.156 -> 147 Month is 
22:54:30.156 -> 4
22:54:30.156 -> 149 Day is 
22:54:30.156 -> 23
22:54:30.156 -> *************loop# 20*************
22:54:30.190 -> 57 Connection stable
22:54:30.190 -> 64 Signal Strength = 25
22:54:30.958 -> 147 Month is 
22:54:30.958 -> 4
22:54:30.958 -> 149 Day is 
22:54:30.958 -> 23
22:54:30.958 -> *************loop# 21*************
22:54:30.958 -> 57 Connection stable
22:54:30.958 -> 64 Signal Strength = 25
22:54:31.752 -> 147 Month is 
22:54:31.752 -> 4
22:54:31.752 -> 149 Day is 
22:54:31.752 -> 23
22:54:31.752 -> *************loop# 22*************
22:54:31.752 -> 57 Connection stable
22:54:31.752 -> 64 Signal Strength = 23
22:54:32.512 -> 147 Month is 
22:54:32.512 -> 4
22:54:32.512 -> 149 Day is 
22:54:32.512 -> 23
22:54:32.512 -> *************loop# 23*************
22:54:32.545 -> 57 Connection stable
22:54:32.545 -> 64 Signal Strength = 19
22:54:51.592 -> 119 WhiteListed system reset
22:54:54.327 -> 42 Booting.
22:55:13.644 -> 85 Not connected retry# 1
22:55:28.481 -> 80 GSM initialized. - Awaiting Call.
22:55:28.481 -> 
22:55:28.481 -> *************loop# 1*************
22:55:28.481 -> 57 Connection stable
22:55:28.481 -> 64 Signal Strength = 23
22:55:29.242 -> 147 Month is 
22:55:29.242 -> 4
22:55:29.242 -> 149 Day is 
22:55:29.242 -> 23
22:55:29.242 -> *************loop# 2*************
22:55:29.279 -> 57 Connection stable
22:55:29.279 -> 64 Signal Strength = 23
22:55:30.029 -> 147 Month is 
22:55:30.029 -> 4
22:55:30.029 -> 149 Day is 
22:55:30.029 -> 23
22:55:30.029 -> *************loop# 3*************
22:55:30.062 -> 57 Connection stable
22:55:30.062 -> 64 Signal Strength = 23
22:55:30.846 -> 147 Month is 
22:55:30.846 -> 4
22:55:30.846 -> 149 Day is 
22:55:30.846 -> 23
22:55:30.846 -> *************loop# 4*************
22:55:30.846 -> 57 Connection stable
22:55:30.846 -> 64 Signal Strength = 23
22:55:31.636 -> 147 Month is 
22:55:31.636 -> 4
22:55:31.636 -> 149 Day is 
22:55:31.636 -> 23
22:55:31.636 -> *************loop# 5*************
22:55:31.636 -> 57 Connection stable
22:55:31.636 -> 64 Signal Strength = 23
22:55:32.410 -> 147 Month is 
22:55:32.410 -> 4
22:55:32.410 -> 149 Day is 
22:55:32.410 -> 23
22:55:32.410 -> *************loop# 6*************
22:55:32.446 -> 57 Connection stable
22:55:32.446 -> 64 Signal Strength = 23
22:55:33.191 -> 147 Month is 
22:55:33.191 -> 4
22:55:33.191 -> 149 Day is 
22:55:33.191 -> 23
22:55:33.191 -> *************loop# 7*************
22:55:33.228 -> 57 Connection stable
22:55:33.228 -> 64 Signal Strength = 23
22:55:33.984 -> 147 Month is 
22:55:33.984 -> 4
22:55:33.984 -> 149 Day is 
22:55:33.984 -> 23
22:55:33.984 -> *************loop# 8*************
22:55:34.022 -> 57 Connection stable
22:55:34.022 -> 64 Signal Strength = 23
22:55:34.784 -> 147 Month is 
22:55:34.784 -> 4
22:55:34.784 -> 149 Day is 
22:55:34.784 -> 23
22:55:34.784 -> *************loop# 9*************
22:55:34.818 -> 57 Connection stable
22:55:34.818 -> 64 Signal Strength = 23
22:55:35.582 -> 147 Month is 
22:55:35.582 -> 4
22:55:35.582 -> 149 Day is 
22:55:35.582 -> 23
22:55:35.582 -> *************loop# 10*************
22:55:35.582 -> 57 Connection stable
22:55:35.582 -> 64 Signal Strength = 23
22:55:36.365 -> 147 Month is 
22:55:36.365 -> 4
22:55:36.365 -> 149 Day is 
22:55:36.365 -> 23
22:55:36.365 -> *************loop# 11*************
22:55:36.365 -> 57 Connection stable
22:55:36.365 -> 64 Signal Strength = 23
22:55:37.157 -> 147 Month is 
22:55:37.157 -> 4
22:55:37.157 -> 149 Day is 
22:55:37.157 -> 23
22:55:37.157 -> *************loop# 12*************
22:55:37.157 -> 57 Connection stable
22:55:37.157 -> 64 Signal Strength = 23
22:55:37.937 -> 147 Month is 
22:55:37.937 -> 4
22:55:37.937 -> 149 Day is 
22:55:37.937 -> 23
22:55:37.937 -> *************loop# 13*************
22:55:37.971 -> 57 Connection stable
22:55:37.971 -> 64 Signal Strength = 23
22:55:38.722 -> 147 Month is 
22:55:38.722 -> 4
22:55:38.722 -> 149 Day is 
22:55:38.722 -> 23
22:55:38.722 -> *************loop# 14*************
22:55:38.760 -> 57 Connection stable
22:55:38.760 -> 64 Signal Strength = 23
22:55:39.516 -> 147 Month is 
22:55:39.516 -> 4
22:55:39.516 -> 149 Day is 
22:55:39.516 -> 23
22:55:39.516 -> *************loop# 15*************
22:55:39.549 -> 57 Connection stable
22:55:39.549 -> 64 Signal Strength = 23
22:55:40.299 -> 147 Month is 
22:55:40.299 -> 4
22:55:40.299 -> 149 Day is 
22:55:40.299 -> 23
22:55:40.299 -> *************loop# 16*************
22:55:40.333 -> 57 Connection stable
22:55:40.333 -> 64 Signal Strength = 23
22:55:41.092 -> 147 Month is 
22:55:41.092 -> 4
22:55:41.092 -> 149 Day is 
22:55:41.092 -> 23
22:55:41.092 -> *************loop# 17*************
22:55:41.126 -> 57 Connection stable
22:55:41.126 -> 64 Signal Strength = 23
22:55:41.879 -> 147 Month is 
22:55:41.879 -> 4
22:55:41.879 -> 149 Day is 
22:55:41.879 -> 23
22:55:41.879 -> *************loop# 18*************
22:55:41.913 -> 57 Connection stable
22:55:41.913 -> 64 Signal Strength = 23
22:55:42.673 -> 147 Month is 
22:55:42.673 -> 4
22:55:42.673 -> 149 Day is 
22:55:42.673 -> 23
22:55:42.673 -> *************loop# 19*************
22:55:42.707 -> 57 Connection stable
22:55:42.707 -> 64 Signal Strength = 23
22:55:43.460 -> 147 Month is 
22:55:43.460 -> 4
22:55:43.460 -> 149 Day is 
22:55:43.460 -> 23
22:55:43.460 -> *************loop# 20*************
22:55:43.494 -> 57 Connection stable
22:55:43.494 -> 64 Signal Strength = 23
22:55:44.259 -> 147 Month is 
22:55:44.259 -> 4
22:55:44.259 -> 149 Day is 
22:55:44.259 -> 23
22:55:44.259 -> *************loop# 21*************
22:55:44.295 -> 57 Connection stable
22:55:44.295 -> 64 Signal Strength = 23
22:55:45.044 -> 147 Month is 
22:55:45.044 -> 4
22:55:45.044 -> 149 Day is 
22:55:45.044 -> 23
22:55:45.044 -> *************loop# 22*************
22:55:45.078 -> 57 Connection stable
22:55:45.078 -> 64 Signal Strength = 23
22:55:45.830 -> 147 Month is 
22:55:45.830 -> 4
22:55:45.830 -> 149 Day is 
22:55:45.830 -> 23
22:55:45.830 -> *************loop# 23*************
22:55:45.863 -> 57 Connection stable
22:55:45.863 -> 64 Signal Strength = 23
22:55:46.622 -> 147 Month is 
22:55:46.622 -> 4
22:55:46.622 -> 149 Day is 
22:55:46.622 -> 23
22:55:46.622 -> *************loop# 24*************
22:55:46.656 -> 57 Connection stable
22:55:46.656 -> 64 Signal Strength = 23
22:55:47.405 -> 147 Month is 
22:55:47.405 -> 4
22:55:47.405 -> 149 Day is 
22:55:47.405 -> 23
22:55:47.405 -> *************loop# 25*************
22:55:47.439 -> 57 Connection stable
22:55:47.439 -> 64 Signal Strength = 23
22:55:48.203 -> 147 Month is 
22:55:48.203 -> 4
22:55:48.203 -> 149 Day is 
22:55:48.203 -> 23
22:55:48.203 -> *************loop# 26*************
22:55:48.237 -> 57 Connection stable
22:55:48.237 -> 64 Signal Strength = 23
22:55:49.003 -> 147 Month is 
22:55:49.003 -> 4
22:55:49.003 -> 149 Day is 
22:55:49.003 -> 23
22:55:49.003 -> *************loop# 27*************
22:55:49.003 -> 57 Connection stable
22:55:49.003 -> 64 Signal Strength = 23
22:55:49.799 -> 147 Month is 
22:55:49.799 -> 4
22:55:49.799 -> 149 Day is 
22:55:49.799 -> 23
22:55:49.799 -> *************loop# 28*************
22:55:49.799 -> 57 Connection stable
22:55:49.799 -> 64 Signal Strength = 23
22:55:50.560 -> 147 Month is 
22:55:50.560 -> 4
22:55:50.560 -> 149 Day is 
22:55:50.560 -> 23
22:55:50.560 -> *************loop# 29*************
22:55:50.594 -> 57 Connection stable
22:55:50.594 -> 64 Signal Strength = 23
22:55:51.372 -> 147 Month is 
22:55:51.372 -> 4
22:55:51.372 -> 149 Day is 
22:55:51.372 -> 23
22:55:51.372 -> *************loop# 30*************
22:55:51.372 -> 57 Connection stable
22:55:51.372 -> 64 Signal Strength = 23
22:55:52.173 -> 147 Month is 
22:55:52.173 -> 4
22:55:52.173 -> 149 Day is 
22:55:52.173 -> 23
22:55:52.173 -> *************loop# 31*************
22:55:52.173 -> 57 Connection stable
22:55:52.173 -> 64 Signal Strength = 23
22:55:52.935 -> 147 Month is 
22:55:52.935 -> 4
22:55:52.935 -> 149 Day is 
22:55:52.935 -> 23
22:55:52.935 -> *************loop# 32*************
22:55:52.969 -> 57 Connection stable
22:55:52.969 -> 64 Signal Strength = 23
22:55:53.718 -> 147 Month is 
22:55:53.718 -> 4
22:55:53.718 -> 149 Day is 
22:55:53.718 -> 23
22:55:53.718 -> *************loop# 33*************
22:55:53.755 -> 57 Connection stable
22:55:53.755 -> 64 Signal Strength = 23
22:55:54.523 -> 147 Month is 
22:55:54.523 -> 4
22:55:54.523 -> 149 Day is 
22:55:54.523 -> 23
22:55:54.523 -> *************loop# 34*************
22:55:54.557 -> 57 Connection stable
22:55:54.557 -> 64 Signal Strength = 23
22:55:55.306 -> 147 Month is 
22:55:55.306 -> 4
22:55:55.306 -> 149 Day is 
22:55:55.306 -> 23
22:55:55.306 -> *************loop# 35*************
22:55:55.343 -> 57 Connection stable
22:55:55.343 -> 64 Signal Strength = 23
22:55:56.115 -> 147 Month is 
22:55:56.115 -> 4
22:55:56.115 -> 149 Day is 
22:55:56.115 -> 23
22:55:56.115 -> *************loop# 36*************
22:55:56.115 -> 57 Connection stable
22:55:56.115 -> 64 Signal Strength = 23
22:55:56.909 -> 147 Month is 
22:55:56.909 -> 4
22:55:56.909 -> 149 Day is 
22:55:56.909 -> 23
22:55:56.909 -> *************loop# 37*************
22:55:56.909 -> 57 Connection stable
22:55:56.909 -> 64 Signal Strength = 23
22:55:57.695 -> 147 Month is 
22:55:57.695 -> 4
22:55:57.695 -> 149 Day is 
22:55:57.695 -> 23
22:55:57.695 -> *************loop# 38*************
22:55:57.695 -> 57 Connection stable
22:55:57.695 -> 64 Signal Strength = 23
22:55:58.472 -> 147 Month is 
22:55:58.472 -> 4
22:55:58.472 -> 149 Day is 
22:55:58.472 -> 23
22:55:58.472 -> *************loop# 39*************
22:55:58.505 -> 57 Connection stable
22:55:58.505 -> 64 Signal Strength = 23
22:55:59.262 -> 147 Month is 
22:55:59.262 -> 4
22:55:59.262 -> 149 Day is 
22:55:59.262 -> 23
22:55:59.262 -> *************loop# 40*************
22:55:59.295 -> 57 Connection stable
22:55:59.295 -> 64 Signal Strength = 23
22:56:00.063 -> 147 Month is 
22:56:00.063 -> 4
22:56:00.063 -> 149 Day is 
22:56:00.063 -> 23

```

And I'm quite impressed. I tried calling it and it worked very well, and it even reset after it hung up. I think this did it, thank you! What do you say was the issue? I see the change in the `if (gsmAccess.isAccessAlive() != GSM_READY) {` line. Was that it you think?

I am very eager to give this board a try the couple of days and hope it will stay connected stably and reliably 😃

Thanks again a lot and I'll be sure to let you know the results of testing!

---

<div class="post-metadata">

**Author:** ![Hutkikz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hutkikz/32/218764_2.png) [@Hutkikz](https://forum.arduino.cc/u/Hutkikz)\
**Post date:** [April 23, 2023, 10:00pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/17 "2023-04-23T22:00:47Z")

</div>

The 2 problems I fixed are:

In the `connectToCarrier()` function the variables "connected" and "retries" needed to be [static](https://www.arduino.cc/reference/en/language/variables/variable-scope-qualifiers/static/) otherwise they are forgotten each time the function ends.

```plaintext
void connectToCarrier() {
  static bool connected = false;
  static int retries = 0;
  const int maxRetries = 5;

```

Yes, the big problem was that line.  
the `isAccessAlive()` function returns 1 or 0 and `GSM_READY` is equal to 3  
so I am surprised it worked at all. It was actually connected most of the time that was covered by the Serial monitor reports. I say most of the time because I think when it printed `retries` it actually was disconnected. Hopefully now it will properly reconnect.

Good Luck and yes, please let me know.  
Oh and here is the final version of the code( couple minor tweaks).

```plaintext
#include <MKRGSM.h>
#include <TimeLib.h>

// GSM and GPRS instances
GSM gsmAccess;
GPRS gprs;
GSMScanner GSMScan;
GSMVoiceCall voiceCall;
GSM_SMS sms;

// Relay and LED pins
const int relayPin = 1;
char PINNUMBER [] = ""; // PIN-Code of the Simcard
const int ledPin = LED_BUILTIN;

// Whitelisted numbers
const char *whitelist[] = {"+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789", "+00123456789"};
const int whitelistSize = sizeof(whitelist) / sizeof(whitelist[0]);

// Phone number to send text message
const char *textMessagePhoneNumber = "+00123456789";

// Pre-composed text message
const char *textMessage = "This is an automated message. I'm online.";

// Variables for text message sending interval
int lastSentMonth = -1;

bool connected = false;
unsigned long lastGSMCheck = 0;
unsigned long checkInterval = 60000; // Check connection every 30 seconds
unsigned long reconnectTimeout = 60000; // 30 seconds timeout

void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);
  while (!Serial); // wait for Serial to initialize so we don't miss any messages

  Serial.println("42 Booting.");
  delay(5000); // Give the GSM module some time to initialize
  connectToCarrier();
}

void loop() {
  static int loopCounter;
  Serial.print(" ************* loop# ");
  Serial.print(++loopCounter);
  Serial.println(" *************");

  // Check GSM connection
  if (gsmAccess.isAccessAlive()) {
    Serial.println("57 Connection stable");
  }
  else {
    digitalWrite(ledPin, LOW); // Turn LED off.
    Serial.println("61 Connection lost. Trying to reconnect...");
    connectToCarrier();
  }
  Serial.print("64 Signal Strength = ");
  Serial.println(GSMScan.getSignalStrength());
  checkForVoiceCall();
  checkForTextMessage();
  sendTextMessageEveryThreeMonths();
}

void connectToCarrier() {
  static bool connected = false;
  static int retries = 0;
  const int maxRetries = 5;

  while (!connected && retries < maxRetries) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      connected = true;
      digitalWrite(ledPin, HIGH); // Solid: connected
      Serial.print("80 GSM initialized. - ");
      Serial.println("Awaiting Call.");
      Serial.println("");
    } else {
      connected = false;
      Serial.print("85 Not connected retry# ");
      retries++;
      Serial.println(retries);
      delay(1000);
    }
  }

  if (retries >= maxRetries) {
    Serial.println("93 Failed to connect after maximum retries. Restarting the board.");
    NVIC_SystemReset();
  }
}

void checkForVoiceCall() {
  if (voiceCall.getvoiceCallStatus() == RECEIVINGCALL) {
    char phoneNumber[20];
    voiceCall.retrieveCallingNumber(phoneNumber, 20);

    bool isWhitelisted = false;
    for (int i = 0; i < whitelistSize; i++) {
      if (strcmp(phoneNumber, whitelist[i]) == 0) {
        isWhitelisted = true;
        break;
      }
    }

    voiceCall.hangCall();

    if (isWhitelisted) { // If whitelisted person calls, activate the relay.
      activateRelay();

      delay(10000);

      Serial.println("119 WhiteListed system reset");
      NVIC_SystemReset(); // I've tried the code with and without this line. I was trying whether it would be better to just restart the whole setup everytime some had called, it made no difference.
    }
  }
}

void checkForTextMessage() {
  if (sms.available()) {
    char phoneNumber[20];
    sms.remoteNumber(phoneNumber, 20);

    sms.flush(); // Flush the message
  }
}

void activateRelay() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(relayPin, HIGH);
    delay(2000);
    digitalWrite(relayPin, LOW);
    delay(250);
  }
}

void sendTextMessageEveryThreeMonths() {
  time_t currentTime = gsmAccess.getTime();
  int currentMonth = month(currentTime);
  int currentDay = day(currentTime);

  if ((currentMonth - lastSentMonth) % 3 == 0 && currentDay == 1 && currentMonth != lastSentMonth) {
    Serial.print("153 Send Textmessage. Online.");

    sms.beginSMS(textMessagePhoneNumber);
    sms.print(textMessage);
    sms.endSMS();
    Serial.println("158 \nCOMPLETE!\n");

    lastSentMonth = currentMonth;
  }
}
```

---

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [May 8, 2023, 1:06pm UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/18 "2023-05-08T13:06:14Z")

</div>

Hiya! So I've been using the board/sketch for two weeks now and it's been fairly stable in use. I've only had it malfunction three times now.

Each time the exact same thing happens: I would call the board and I would immediately hear repeated beeping. So the call gets neither picked up nor hung up. Normally my phone shows the "User Busy" screen but when it malfunctions it starts beeping and I'm still able to 'hang up' the call.

Only if I wait a minute or two the board functions properly again.

It doesn't depend on who's calling, and it seems to be at random (I can't see a pattern in time of day or anything else).

I think it loses connection? But somehow it seems to regain connection right when I start calling it which I think is a little peculiar.

Any idea what's going on/why it behaves this way?

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![Hutkikz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hutkikz/32/218764_2.png) [@Hutkikz](https://forum.arduino.cc/u/Hutkikz)\
**Post date:** [May 9, 2023, 12:26am UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/19 "2023-05-09T00:26:53Z")

</div>

Have it send a text every time it reconnects.  
The text should state the time of the disconnect and subsequent reconnect.

---

<div class="post-metadata">

**Author:** ![valley09](https://avatars.discourse-cdn.com/v4/letter/v/3be4f8/32.png) [@valley09](https://forum.arduino.cc/u/valley09)\
**Post date:** [May 11, 2023, 7:04am UTC](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373/20 "2023-05-11T07:04:15Z")

</div>

I’ll try this weekend, thank you!

[Next page](https://forum.arduino.cc/t/mkr-gsm-1400-phone-enabled-garage-opener-issues/1118373.md?page=2)
