Arduino Nano 33 IoT disconnects after a minute using WiFi

Hi,

I'm writing a code that helps to control servos using TouchOSC. So I decided to try out receiving data using the OSCMessage library from CNMAT. The thing is, it works for the first minute, but then it throws me the status WL_NO_MODULE. Which it indicates that it failed to communicate with the ESP32 of the board.

Also, I'm using an I2C servo controller, and the board is working as an Access Point.

It kind of works with longer delays, but the response for the servos would be delayed or roughly slow. Anyway to know what's happening?

Here is my code:

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <WiFiNINA.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>

#define USMIN  600
#define USMAX  2300 
#define SERVO_FREQ 50 

WiFiUDP Udp;
OSCErrorCode error;
long timed = millis();
const IPAddress outIp(192, 168, 4, 255);
const unsigned int outPort = 10000;
const unsigned int localPort = 12000;
char ssid[] = "Noaki";
char pass[] = "Nojoaki2";
int status = WL_IDLE_STATUS;
int servos[4];
float servoPulse[4] = {USMIN, USMIN, USMIN, USMIN};
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

void setup() {
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  Serial.print("Creating access point named: ");
  Serial.println(ssid);


  status = WiFi.beginAP(ssid, pass);
  if (status != WL_AP_LISTENING) {
    Serial.println("Creating access point failed");
    while (true);
  }
  delay(5000);
  printWiFiStatus();

  Udp.begin(localPort);

  pwm.begin();
  pwm.setOscillatorFrequency(27000000);
  pwm.setPWMFreq(SERVO_FREQ);

  delay(10);
}

void srv(OSCMessage &msg, int addressOffset) {
  for (int i = 0; i < 4; i++) {
    String temp = "/" + (String)(i + 1) + "/1";
    char tempArray[5];
    temp.toCharArray(tempArray, 5);
    if (msg.fullMatch(tempArray, addressOffset)) {
      servos[i] = int(msg.getFloat(0));
    }
  }
}

void loop() {
  OSCMessage msg;
  int size = Udp.parsePacket();
  Serial.println(size);
  if (size > 0) {
    while (size--) {
      msg.fill(Udp.read());  
    }
    if (!msg.hasError()) {
      msg.route("/servos", srv);
    } else {
      error = msg.getError();
      Serial.print("error: ");
      Serial.println(error);
    }
  }
  delay(10);
  for (int i = 0; i < 4; i++) {
    if (servos[i] == 1) {
      servoPulse[i] += 100;
      if (servoPulse[i] > USMAX) {
        servoPulse[i] = USMAX;
      }
    }
    else {
      servoPulse[i] -=  30;
      if (servoPulse[i] < USMIN) {
        servoPulse[i] = USMIN;
      }
    }
    pwm.writeMicroseconds(i, int(servoPulse[i]));
  }
  delay(10);
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("ERROR");
    while(true);
  }
  delay(10);
}

void printWiFiStatus() {
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
}

Thanks!