Keypad not working with ethernet

I apologise in advance as I am new to both arduino and C. I believe this is a coding error but cannot see it.

In one of our hackdays I was trying to create a little fingerprint attendance system - I know it’s been done before. I’m running the sketch on an uno r3 with the HanRun ethernet shield, a 4x4 matrix keypad and generic fingerprint reader.

Everything works well, but will not connect to the net once the keypad has been used until it’s reset.

I’d appreciate anyhelp you can give. Here is the sketch (in 2 parts due to the length):

Part 1:

#include <SPI.h>
#include <Ethernet.h>
#include <Keypad.h>
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int8_t id;
int dtype = 0; //type 0 = idle, 1 = register, 2 = cloud enroll 
byte digitCount = 0;
int myInt = 0;
int userid = 0;
const byte rows = 4; //four rows
const byte cols = 4; //three columns
char keys[rows][cols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[rows] = {15,14,9,8}; //connect to the row pinouts of the keypad
byte colPins[cols] = {7,6,5,16}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xEE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(139,162,199,199);  // numeric IP for Google (no DNS)
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)

char server[] = "rubicon2.thehonest.agency";    // name address for Google (using DNS)
//char server[] = "www.google.com";    // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
EthernetClient client;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  
  
  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
    finger.getTemplateCount();
     Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
     id = finger.templateCount;
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

}

uint8_t modeselect(void) {
      int num = dtype;
      char customKey = keypad.getKey();
      if(customKey == 'A'){
      num = 1;
      } else if(customKey == 'B'){
        num = 2;
      } else if(customKey == '*'){
        num = 0;
      }
      //uint8_t num = 1;
      return num;
  }  


void loop() {
  
  dtype = modeselect();
  
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    //Serial.print("disconnecting.");
    //client.stop();

    // do nothing forevermore:
    //while (true);
  }


  if(dtype == 0){
    getFingerprintIDez();
    delay(50);
    
  } else if(dtype == 1){
  Serial.print("Enter your code");
  char Key = keypad.getKey();
      if (Key >= '0' && Key <= '9'){
         Serial.println(Key);
           myInt = (myInt * 10) + Key -'0';
                      Serial.println(myInt);

           digitCount++;
         if (digitCount == 4) {
           Serial.print("You entered: ");
           Serial.println(myInt);
           userid = myInt;
           dtype = 0;
           //post login to url
               if (client.connect(server, 80)) {
           Serial.println("connected");
            client.print("POST /fingerprint.php?src=3&mode=log&user=");
            client.print(9);
            //client.print(myInt);
            client.println(" HTTP/1.1");
           client.println("Host: 139.162.199.112");
            client.println("User-Agent: Arduino");
            client.println("Accept: text/html");
            client.println("Connection: close");
            client.println();
            }
           digitCount = 0;
           myInt = 0;
         }
       }
  } else if(dtype == 2){
  //Serial.println("Ready to enroll a fingerprint!");
  //Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
  char Key = keypad.getKey();
      
      if (Key >= '0' && Key <= '9'){
         Serial.println(Key);
           myInt = (myInt * 10) + Key -'0';
           digitCount++;
         if (digitCount == 4) {
           Serial.print("You entered: ");
           Serial.println(myInt);
           userid = myInt;
           Serial.print("Enrolling ID #");
            Serial.println(userid);
            Serial.print("into slot");
            Serial.println(id);
            while (!  getFingerprintEnroll() );
           digitCount = 0;
           myInt = 0;
         }
       }
  }
  
}

Part 2:

uint8_t getFingerprintEnroll() {
  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }
  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  Serial.print("Creating model for #");  Serial.println(id);
  
  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
  
  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
    
    if (client.connect(server, 80)) {
      Serial.println("connected");
      client.print("POST /fingerprint.php?src=3&mode=register&local=");
      //client.print(id);
      client.print(9);
      client.print("&user=");
      client.print(1);
      //client.print(userid);
      client.println(" HTTP/1.1");
     client.println("Host: rubicon2.thehonest.agency");
      client.println("User-Agent: Arduino");
      client.println("Accept: text/html");
      client.println("Connection: close");
      client.println();
    } else {
      // if you didn't get a connection to the server:
      Serial.println("connection failed");
    }
    dtype = 0;
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence); 

  return finger.fingerID;
}

int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;
  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;
  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  //mysql
  if (client.connect(server, 80)) {
    Serial.println("connected");
      client.print("POST /fingerprint.php?src=3&mode=log&local=");
      client.print(9);
      //client.print(finger.fingerID);
      client.println(" HTTP/1.1");
     client.println("Host: rubicon2.thehonest.agency");
      client.println("User-Agent: Arduino");
      client.println("Accept: text/html");
      client.println("Connection: close");
      client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  
  return finger.fingerID; 
}
char server[] = "rubicon2.thehonest.agency";    // name address for Google (using DNS)

Complete nonsense. That is NOT the address of google.

const byte rows = 4; //four rows
const byte cols = 4; //three columns

When you have useless comments, you MUST make them accurate, useless comments.

Your POST request is NOT complete. It looks like a GET request with no data.

Haha thanks - they're relics from the example. I will endeavour to add accurate useless comments in future! ;-)

I have actually tried it with Google, but the same 'connection failed' message appears.

I have tried GET and POST requests too.

I'll create a simpler sketch for debugging and try and find where it goes wrong