UIPethernet and MFR522 not working together

Is there any issues using these two libraries together that would cause it to not connect to the network?

I have two other arduinos with all the same code for the network/mqtt working fine, but this one keeps refusing to connect.

I've tried changing to to the newer ethernetenc library, but that doesn't work either. The only thing I can think of at the moment is possibly due to the memory usage, as the code does take up a lot more memory than the others that are working.

what enc28j60 module do you use? are the working arduinos same with same enc28j69 modules?

Yes, they're all the same - these ones https://www.amazon.co.uk/gp/product/B07V3F5S2M/ref=ppx_yo_dt_b_asin_title_o09_s00?ie=UTF8&th=1

And these are the RFID cards - https://www.amazon.co.uk/gp/product/B074S9FZC5/ref=ppx_yo_dt_b_asin_title_o03_s02?ie=UTF8&psc=1

I've double (and triple) checked the connections, and all parts of the code for the networking have been copied from the working ones, just with the mac and ip addresses changed.
They're sharing the SI, SO and Sck pins, but that should be fine shouldn't it?

This one just doesn't seem to want to connect - it doesn't appear in the client list on the router and shows an rc=-2 error in the serial monitor.

is the mac address unique?

Yes. They didn't come with mac addresses, so I made them up changing just the last digit for each one.

so do the troubleshooting. do the modules work separately with their basic examples?

The modules work themselves, yes. I haven't tried them with example codes, but I have switched them between other units/codes that are working. It must be something in the coding/setup between the ethernet and MFRC522.

This is the code:

#include <SPI.h>
#include <MFRC522.h>
#include <UIPEthernet.h>
#include <PubSubClient.h>

const byte mac[] = {0x74, 0x69, 0x69, 0x2D, 0x30, 0x33};
const IPAddress IP(192, 168, 0, 108);
const IPAddress serverIP(192, 168, 0, 101);

const byte numReaders = 3;
const byte ssPins[] = {2, 3, 4};
const byte resetPin = 9;
int LEDpins[] = {A1, A2, A3};
int numLEDs = 3;
MFRC522 mfrc522[numReaders];
const String correctIDs[] = {"9a8760aa", "5a665caa", "ea8860aa"};
String currentIDs[numReaders];
const byte lockPin = A0;

// Callback function header
void callback(char* topic, byte* payload, unsigned int length);

EthernetClient ethClient;
PubSubClient MQTTclient(ethClient);

void callback(char* topic, byte* payload, unsigned int length) {

  /*  Serial.print("Message arrived [");
    Serial.print(topic);
    Serial.print("] ");
    for (int i = 0; i < length; i++) {
      Serial.print((char)payload[i]);
    }
    Serial.println();
  */
  byte* p = (byte*)malloc(length + 1);
  memcpy(p, payload, length);
  p[length] = 0;

  //  MQTTclient.publish("toHost/switches", p, length);

  //  Serial.println("checking");

  if (strcmp(p, "SOLVE") == 0) {
    onSolve();
  }
  else if (strcmp(p, "RESET") == 0) {
    onReset();
  }
  //  Serial.println("check done");

  free(p);
  //  Serial.println("memory cleared");

}


void reconnect() {
  // Loop until we're reconnected
  while (!MQTTclient.connected()) {
    //    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (MQTTclient.connect("monkeys")) {
      //      Serial.println("connected");
      // Once connected, publish an announcement...
      MQTTclient.publish("toHost/monkeys", "connected");
      // ... and resubscribe
      MQTTclient.subscribe("lab/monkeys");
      MQTTclient.subscribe("lab/all");
    }
    else {
      Serial.print("failed, rc=");
      Serial.print(MQTTclient.state());
      Serial.println(" try again in 5 seconds");
      //     MQTTclient.publish("lab/monkeys", "connection failed");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(lockPin, OUTPUT);
  digitalWrite(lockPin, LOW);
  SPI.begin();
  MQTTclient.setServer(serverIP, 1883);
  MQTTclient.setCallback(callback);

  //  Serial.println("Connecting to network");
  if (Ethernet.begin(mac) == 0) {
    Ethernet.begin(mac, IP);
  }
  Serial.print("Connected! IP address: ");
  Serial.println(Ethernet.localIP());

  for (uint8_t i = 0; i < numReaders; i++) {
    mfrc522[i].PCD_Init(ssPins[i], resetPin);
    mfrc522[i].PCD_SetAntennaGain(MFRC522::PCD_RxGain::RxGain_max);
    Serial.print(F("Reader #"));
    Serial.print(i);
    Serial.print(F(" initialised on pin "));
    Serial.print(String(ssPins[i]));
    Serial.print(F(". Antenna strength: "));
    Serial.print(mfrc522[i].PCD_GetAntennaGain());
    Serial.print(F(". Version : "));
    mfrc522[i].PCD_DumpVersionToSerial();

    delay(100);
  }

  for (int i = 0; i < numLEDs; i++) {
    pinMode(LEDpins[i], OUTPUT);
  }

}


void loop() {
  // put your main code here, to run repeatedly:
  boolean puzzleSolved = true;
  boolean changedValue = false;

  if (!MQTTclient.connected()) {
    reconnect();
  }
  MQTTclient.loop();


  for (uint8_t i = 0; i < numReaders; i++) {
    mfrc522[i].PCD_Init();
    String readRFID = "";

    if (mfrc522[i].PICC_IsNewCardPresent() && mfrc522[i].PICC_ReadCardSerial()) {
      readRFID = dump_byte_array(mfrc522[i].uid.uidByte, mfrc522[i].uid.size);
    }

    if (readRFID != currentIDs[i]) {
      changedValue = true;
      currentIDs[i] = readRFID;
    }

    if (currentIDs[i] != correctIDs[i]) {
      puzzleSolved = false;
      digitalWrite(LEDpins[i], LOW);
    }
    else {
      digitalWrite(LEDpins[i], HIGH);
    }

    mfrc522[i].PICC_HaltA();
    mfrc522[i].PCD_StopCrypto1();
  }

  /*if(changedValue) {
    for (uint8_t i=0; i<numReaders; i++) {
      Serial.print(F("Reader #"));
      Serial.print(String(i));
      Serial.print(F(" on Pin #"));
      Serial.print(String((ssPins[i])));
      Serial.print(F(" detected tag: "));
      Serial.println(currentIDs[i]);
    }
    Serial.println(F("---"));
    }*/

  if (puzzleSolved) {
    MQTTclient.publish("toHost/monkeys", "solved");
    //Serial.println("solved");
    onSolve();
  }

}


void onSolve() {
  //  Serial.println (F("Puzzle Solved"));
  digitalWrite(lockPin, HIGH);

  if (!MQTTclient.connected()) {
    reconnect();
  }
  MQTTclient.loop();

}


void onReset() {
  delay(1000);
  asm volatile ("jmp 0");
}


String dump_byte_array(byte *buffer, byte bufferSize) {
  String read_rfid = "";
  for (byte i = 0; i < bufferSize; i++) {
    read_rfid = read_rfid + String(buffer[i], HEX);
  }
  return read_rfid;
}
[/code]