Arduino Nano IoT 33 WifiNina Library not working with interrupt

When I trigger the isr-function through pin21, the program stops because of "wifiClient.println("test");

I figured out, that the problem has to be the WifiNina library in combination with the interrupt.
When I use the WiFi101 library on the MKR1000 it works. When I use the WifiNina library on the Nano IoT 33 it doesn't.
I also tried things like outsourcing the wireless communication out of the isr() in another function, use wifiClient.write() instead of .print(), ...

Without using an interrupt, wifiClient.println(...) works normally.

This is my code:

#include <SPI.h>
#include <WiFiNINA.h>
//#include <WiFi101.h>


// WiFi credentials
char ssid[] = "TP-Link_8754";
char pass[] = "86912587";

// Laptop address
char server[] = "192.168.0.101";
int port = 80;

// Wifi client
WiFiClient wifiClient;


// Interrupt pin
const byte interruptPin = 21;

// Interrupt state
volatile byte state = LOW;

// Interrupt counter
static int counter = 0;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Connect to WiFi
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print("Connecting to WiFi network...");
    WiFi.begin(ssid, pass);
    delay(1000);
  }

  // Configure interrupt pin as input with pull-down resistor
  pinMode(interruptPin, INPUT_PULLDOWN);

  // Enable interrupt
  attachInterrupt(digitalPinToInterrupt(interruptPin), isr, CHANGE);
}

void loop() {
  // Connect to Socket if not connected
  if (!wifiClient.connected()) {
    Serial.print("Connecting to Socket...");

    if (wifiClient.connect(server, port)) {
      Serial.println("connected!");
    } else {
      Serial.println(" retrying in 2 seconds...");
      delay(2000);
      return;
    }
  }

}

// Interrupt service routine
void isr() {
wifiClient.println("test");
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.