MKR1400 very unstable!

I'm using the MKR1400 board to connect to a google sheet website to read some status to in turn control a valve. I started off by using the WebSSLClient example on the arduino website, and changed bits of the code there to be suitable too me. The sketch:

/*
  Web client

 This sketch connects to a website using SSL through a MKR GSM 1400 board. Specifically,
 this example downloads the URL "http://www.arduino.cc/asciilogo.txt" and
 prints it to the Serial monitor.

 Circuit:
 * MKR GSM 1400 board
 * Antenna
 * SIM card with a data plan

 created 8 Mar 2012
 by Tom Igoe
*/

// libraries
#include <MKRGSM.h>

// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[]     = "0000";
// APN data
const char GPRS_APN[]      = "live.vodafone.com";
const char GPRS_LOGIN[]    = "";
const char GPRS_PASSWORD[] = "";

// initialize the library instance
GSMSSLClient client;
GPRS gprs;
GSM gsmAccess(true);

// URL, path and port (for example: example.org)
//https://docs.google.com/spreadsheets/d/e/2PACX-1vTGo-MBWS65ko8gkKepC3f7yvrvi30uf23cyG8Ru7lcJ3G3dvA-lDsP9Bgz-mzCjeibH8iwtr5vNrxx/pubhtml
//https://spreadsheets.google.com/feeds/list/1qTB5u_esXD89DcOqTvGB4zkbU9N6KlvKyaZjyvl0I0Y/od6/public/basic?alt=json
//char server[] = "docs.google.com";
//char path[] = "/spreadsheets/d/e/2PACX-1vTGo-MBWS65ko8gkKepC3f7yvrvi30uf23cyG8Ru7lcJ3G3dvA-lDsP9Bgz-mzCjeibH8iwtr5vNrxx/pubhtml";
char server[] = "spreadsheets.google.com";
char path[] = "/feeds/list/1qTB5u_esXD89DcOqTvGB4zkbU9N6KlvKyaZjyvl0I0Y/od6/public/basic?alt=json";
int port = 443; // port 443 is the default for HTTPS

uint8_t open_pin = 0;
uint8_t close_pin = 1;

void setup() {

  //initialize the digital pins and set them all to low
  //pinMode(open_pin, OUTPUT);           // set pin to OUTPUT
  //pinMode(close_pin, OUTPUT);           // set pin to OUTPUT
  //digitalWrite(open_pin, LOW);
  //digitalWrite(close_pin, HIGH);
  
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Starting Arduino web client.");
  // connection state
  bool connected = false;

  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while (!connected) {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, port)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.print("GET ");
    client.print(path);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    //client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

String rec = "";
void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    rec += c;
    
  }

  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    Serial.println(rec);
    int idx = rec.indexOf("KLEP: ");
    Serial.println(idx);
    idx += 6;
    String status = rec.substring(idx, idx+4);
    Serial.println(status);
    if (status == "OPEN"){
      
    }
    // do nothing forevermore:
    for (;;)
      ;
  }
}


void set_state(bool open){
  //Set the motor state by setting the states of the open and close pin
  //The pins may NEVER be high at the same time
  //The pins will be set to LOW first, and then the required pin will be set to high

  digitalWrite(open_pin, LOW);
  digitalWrite(close_pin, LOW);

  if (open){
    digitalWrite(open_pin, HIGH);
  } else {
    digitalWrite(close_pin, HIGH);
  }
  
  delay(5000);

  digitalWrite(open_pin, LOW);
  digitalWrite(close_pin, LOW);
}

Let me start off by saying that the code does function if the GSM does it's job. I have had successfull runs where the connection is made and data is received.

When I run this code the GSM is VERY unstable. below I have provided a debug-log of the GSM communication. As you can see the code stops at "+CREG: 0,1 OK", just as the connection is established.

Starting Arduino web client.
⸮AT

OK
AT+IPR=921600

OK
AT

OK
AT+UPSV=3

OK
AT+CPIN?

ERROR
AT+CPIN?

+CPIN: SIM PIN

OK
AT+CPIN="0000"

OK
AT+CMGF=1

OK
AT+UDCONF=1,1

OK
AT+CTZU=1

OK
AT+UDTMFD=1,2

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,0

OK
AT+CREG?

+CREG: 0,1

OK

This is not the only places it hangs. It sometimes also hangs just as i posted the request to open the connection to "spreadsheet.google.com". It just stops...

Also just as the bytes are received it sometimes hangs.

Lastly let me point out that the device is powered by a stabalized power source of 5VDC @ 5A(max). I also tried 4.1V@2A (no idea why that would improve things, but yeah).

I hope someone has had this same issue and has some clue as to why this happens!

This information might be helpful to you: