MKR 1400 GSM - connect to network without hanging loop() process

Hello,

What I am trying to achieve is connection process to GSM/GPRS without hanging the loop() process. I tried number of libs and direct approach with millis timers but still cannot get what I need. Possibly because MKRGSM lib is stuffed with delays();

Anybody has found a way to do it?

This is my actual code responsible for the GSM part:

GPRS gprs;
GSM gsmAccess;
GSM_SMS sms;
GSMLocation location;

void setup()
{
  ConnGsmNetwork();
  location.begin();

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

void loop()
{
  if (tmGsmConnRetry.WhileRepeat(false)) // this is 10s tiimer
  {
    if(!g_gsmConnStatus)
      ConnGsmNetwork();
      
    if (location.available() == 0)
      location.begin();
  }
}

bool g_gsmConnStatus = false;

void ConnGsmNetwork()
{
  if (g_gsmConnStatus)
    return;

  if (gsmAccess.ready() == 0)
    g_gsmConnStatus = false;

  gprs.setTimeout(18000);
  gsmAccess.setTimeout(18000);

  // Start GSM connection
  if (g_gsmConnStatus == false) {
    if (gsmAccess.begin(g_PINNUMBER) == GSM_READY && (gprs.attachGPRS(g_GPRS_APN, g_GPRS_LOGIN, g_GPRS_PASSWORD) == GPRS_READY))
    {
      g_gsmConnStatus = true;
      Serial.println("GSM START SUCCESS!");
    }
    else
    {
      Serial.println("Connection failed");
      //delay(200);
    }
  }
}

I also tried async mode of gsmAccess.begin with false at third parameter but it did not work well, whenever I called gsmAccess.ready() it hands for short while.

Similar problem is with sms.available(), it slows down entire loop.

Hoping for some solution.

Use

GSM gsmAccess(true);

and read the serial monitor to debug and observe