Problem with MKR GSM using both GSM and GPRS

Hello!

I got a strange problem. I have an MKR GSM 1400 that I intend to use for gate opening. The idea is that anyone who want’s to pass through the gate will call a number, and their number is sent with an HTTP POST Request to a web API that checks if it’s a valid number for opening the gate.

I can’t however get the HTTP POST to work correctly. The weirdest part about it is that when I tried the same code in the GSM Client example (by replacing the HTTP GET-code in it) it worked. But the very same code won’t work in this code. What happens is that it either connects and then disconnects without printing anything (client.Available() returns 0 directly) or it connects and pretty much hangs on that very same spot without disconnecting.

The only thing I can think of that would be causing an issue is the fact that I’m using both GSM and GPRS in the almost same time, but even when adding a 10 second delay between hanging up the call and sending the POST, it doesn’t work. And as far as I can tell, it still connects to the server.

So if anyone has any idea what’s causing the trouble, please help!

#include <MKRGSM.h>
#include "arduino_secrets.h" 

//Setting up variables
GSM gsmAccess;
GSMVoiceCall vcs;
GSMClient client;
GSMScanner scanner;
GPRS gprs;

char server[] = SECRET_SERVER;
char path[] = SECRET_PATH;
char gateNumber[] = SECRET_GATENUMBER;
int port = 443;  
const char PINNUMBER[] = SECRET_PINNUMBER;
const char GPRS_APN[] = SECRET_APN;
char numtel[20];
bool callReceived = false;


void setup() {

  Serial.begin(9600);
  while (!Serial) {;}

  bool connected = false;

    //Connecting to cellular network
  while (!connected) {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, "", "") == GPRS_READY)) {
      connected = true;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  vcs.hangCall();

  Serial.println("Connected to cellular network");
}

void loop() {

  //If call has been recieved and number posted to web API
  
  if (callReceived && vcs.getvoiceCallStatus() == IDLE_CALL)
  {
    //Reading response from API
    if (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
    if (!client.available() && !client.connected())
    {
      Serial.println();
      Serial.println("Disconnecting!");
      client.stop();
      callReceived = false;
    }
  }
  else

  { 
    switch (vcs.getvoiceCallStatus()) {
      case IDLE_CALL: // Nothing is happening

        break;

      case RECEIVINGCALL:

        Serial.println("RECEIVING CALL");

        // Retrieve the calling number
        vcs.retrieveCallingNumber(numtel, 20);

        // Print the calling number
        Serial.print("Number:");
        Serial.println(numtel);
        vcs.hangCall();
        delay(10000);
        callReceived = true;
        CheckNumber(numtel); //Calling method to check number
        
        break;
    }
  }
}

void CheckNumber(char number[20])
{
  char packetData[150];
  Serial.println("connecting...");
  //Creating JSON with number for POST
  sprintf(packetData, "{\n\"AccessNumber\":\"%s\",\n\"Caller\":\"%s\"\n}\n", gateNumber, number);
  
  if (client.connect(server, port)) {

    //Creating HTTP POST Headers
    client.print(F("POST "));
    client.print(path);
    client.println(F(" HTTP/1.1"));

    client.print(F("Host: "));
    client.println(server);

    client.println(F("X-Remotebox_API_User: remotebox"));
    client.println(F("X-Remotebox_API_Password: success"));
    client.println(F("X-Remotebox_API_Store: 3"));
    client.println(F("User-Agent: Arduino/1.0"));
    client.println(F("Connection: close"));
    client.print(F("Content-Length: "));
    client.println(strlen(packetData));
    client.println(F("Content-Type: application/json"));
    client.println(F("Cache-Control: no-cache"));
    client.println();
    client.print(packetData);    
  } 
  else 
  {   
    Serial.println("connection failed");
  }
}