Automation works with Ethernet library but not with UIPEthernet library

I have been using the code below for some time on an ethernet enabled UNO clone and it has been working fine. Recently I repurposed a functioning home built board with the same processor (ATMEGA 328) and used the code below. The only change between the UNO code and the home-build code is to change Ethernet.h to UIPEthernet.h when the library is included.

The system reads the commands to operate relays and works perfectly in that direction. When a sensor operates, the changed input (on MCP port B) should trigger an update up to the server with a new input status. That direction, which works with the Ethernet library version, doesn’t work with the UIPEthernet option.

Could someone help me find why it works with Ethernet, but not with UIPEthernet?

/* 27/7/2019 This program reads MCP port B and sends updates to inputlogger.php. It also reads client calls from smesvr and operates relays on portA.

#include <UIPEthernet.h>                         // Changed for test
#include <Wire.h>                                    // Required to support I2C. Wire is the serial comms library.
#include <SPI.h>                                      // Required to support the ENC28j60 which is an SPI device          

// These register addresses correspond to IOCON.BANK = 0 (default) - Table 1-4 page 9 of MCP23017 datasheet
const byte  mcp_address = 0x22;                     // I2C Address of MCP23017 Hex 22 = jumpers 010         
const byte  GPIOA = 0x12;                           // Port A register
const byte  GPIOB = 0x13;                           // Port B register
const byte  IODIRA = 0x00;                          // Port A direction register IODIRA
const byte  IODIRB = 0x01;                          // Port B direction register IODIRB
const byte  GPPUB = 0x0d;                           // Port B PULLUPS register (default = off (0))

byte mac[] = {0x61, 0x6f, 0x6d, 0x63, 0x70, 0x78};  // 61 6f 6d 63 70 78 - aomcpx
String command;                                     // Value of server request to change relay state
byte current;                                       // Saves value of current output state (relays) to test for changes
byte inputByte;                                     // Real time value of input state
byte inputStateByte =0;                             // Saves value of current input state to test for changes

EthernetServer server (80);                         // Instantiate server for recieving calls from php to set relays
EthernetClient client;                              // Instantiate client to send data to SMEServer database
IPAddress ip(192, 168, 1, 190);                     // UDP is switched off, so DCHP won't work, so we use a fixed address.  

void setup() {
  setupMCP();                                       // Setup the MCP Control registers
  Ethernet.begin(mac, ip);                          // Start the Ethernet connection
  server.begin();                                   // Start the server
  command = "255";                                  // Preset relays off
}

void loop(){
  readClient();                                     // Read any server request
  outControl(command);                              // Update relay settings
  testInputState();                                 // Check if inputs changed and write if they did
}

void readClient() {                                 // Read the incoming string from the client and extract string data
  String clientString;
  EthernetClient client = server.available();       // Create a client connection
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (clientString.length() < 100) {
          clientString += c;
        }
        if (c == '\n') {
          client.write("HTTP/1.0 200 OK");
          delay(1);
          client.stop();
        }}}
    command = clientString.substring(17, 20);       // These values are specific to the packed string sent in the form: GET /out?command=127&port=1 (17(1), 18(2), 19(7) not20(&))
  }
}

int outControl(String command) {                    // In this routine, the command sent by the server is integrated with the current relay state and relays set.
  int relaybyte = command.toInt();                  // First convert string command to int
  byte changebyte = relaybyte;                      // then save as byte (there is no single step option)
  
  // Find out what's already set/unset and combine with what we want to add
  readRegister(GPIOA);                              // Read the Port value (current relay settings)
  byte newbyte;                                     // To hold output value calculated below
  switch (changebyte) {
    case 127:
      newbyte = current & changebyte;               // Off -> Bitwise AND with curent value
      break;
    case 0:
      newbyte = current & changebyte;               // All off -> Bitwise AND with curent value
      break;
    case 255:
      newbyte = current | changebyte;               // All On -> Bitwise OR with current value
      break;
    default:
      if (changebyte > 128) {
        newbyte = current & changebyte;             // Off -> Bitwise AND with current value
      } else {
        newbyte = current | changebyte;             // On -> Bitwise OR with current value
      }
  }
  writeRegister(GPIOA, newbyte);                    // Set the new condition on relays
}

// Write inputs if changed
void testInputState (){
  inputByte = readRegister(GPIOB);                  // Read port B inputs
  if (inputByte != inputStateByte) {                // Compare new input to existing state. If same no action.
   writeInputsPhp("GPIOB", inputByte);              // It's changed so write new state to data base
   inputStateByte = inputByte;                     // Store the new state as the existing state
  }
}

// Write MCP Port Register Value
int writeRegister(byte regPort, byte regValue) {
  Wire.beginTransmission(mcp_address);
  Wire.write(regPort);
  Wire.write(regValue);
  Wire.endTransmission();
}

// Read MCP Port Register Value
byte readRegister(byte regPort) {
  Wire.beginTransmission(mcp_address);
  Wire.write(regPort);
  Wire.endTransmission();
  delay(50);
  Wire.requestFrom(0x22, 1);                        // can't use mcp_adddress here - library issue? I think it works but returns a compile error. 
  current = Wire.read();
  return (current);
}

//Setup MCP device ports
void setupMCP () {
  Wire.begin();                                     // Join i2c bus (address optional for master)
  writeRegister(IODIRA, 0x00);                      // Set port A as outputs
  writeRegister(IODIRB, 0xff);                      // Set Port B as inputs
  writeRegister(GPIOA, 0xff);                       // Set Port A pins on (relays off)
  writeRegister(GPPUB, 0xff);                       // Set Port B (weak - 100k) pullups
}

// Connect to the server, open PHP remotelogger page, send data, disconnect.
void writeInputsPhp(String port, byte value) {
  if (client.connect("192.168.1.100", 7634)) {
    client.print( "GET /datalogger/inputlogger.php?data1=");
    client.print(port);
    client.print( "&&data2=");    
    client.println(value);
    client.println( "Connection: close" );
    client.println();
    client.println();
    client.stop();
  }
}

what server is it? you don't have HTTP/1.x part in the GET request,

try client.connect(IPAddress(192,168,1,100), 7634)

Just to be sure: does your new board use the ENC28J60 Ethernet controller?

Thanks Pert - yes the ethernet controller is the ENC28J60.

Thanks Juraj. The server is a private Apache server on my network and the request works as is if the Ethernet library is used. Surely the client connect request using the String client.connect("192.168.1.100", 7634) is equivalent to client.connect(IPAddress(192,168,1,100), 7634). I'm happy to change and test, but what do you think is the difference?

steve_mcdonald:
Thanks Juraj. The server is a private Apache server on my network and the request works as is if the Ethernet library is used. Surely the client connect request using the String client.connect("192.168.1.100", 7634) is equivalent to client.connect(IPAddress(192,168,1,100), 7634). I'm happy to change and test, but what do you think is the difference?

DNS. string is hostname and the library will resolve it over DNS

Thanks Juraj. I have changed the connect string according to your advice and I have started receiving the database updates, so I believe you were right on the mark. If you have patience, can you explain a little more why that has worked?

steve_mcdonald:
Thanks Juraj. I have changed the connect string according to your advice and I have started receiving the database updates, so I believe you were right on the mark. If you have patience, can you explain a little more why that has worked?

did you turn off UDP support in the UIPEthernet library?
you have a comment in your sketch "UDP is switched off, so DCHP won't work, so we use a fixed address."
DNS uses UDP too.
if you call connect with a string as first parameter, it is treated as hostname and resolved over DNS

Yep I see that now - thanks for helping out. I have turned UDP off. That’s why the string was not being resolved. Your advice has solved the problem and your explanation has helped me learn.
Thank you again.