Ajax inputs hanging

Hello everyone, i am not new to the arduino world but i am fairly new to the web interfacing with the arduino.

I'm currently trying to renovate a really old project of my dad's that includes controlling several relays over the internet. He was doing it via remote desktop and an old PLC but we decided to make it prettier and smarter so i started incorporating it with arduino.

After many many mishaps and unfortunate events...i finally have a working entity which i designed on an arduino UNO + Ethernet shield. The problem is that the UNO has way less digital pins than what i need so i needed to move over to the Mega. This is where things get weird........

The point of the project is that there are 7 input pins that control the relays and 14 output pins that monitor the system. Those 14 outputs are being printed on the website using Ajax. Everything works fine on the UNO but when i move over to the Mega the 14 States are not printed at all...

Any suggestions of why could this be ??

MyTry.ino (14.4 KB)

index.txt (5.71 KB)

The point of the project is that there are 7 input pins that control the relays

So you write to 7 inputs and

and 14 output pins that monitor the system.

read from 14 outputs. Very strange...

                        // send web page
                        webFile = SD.open("index.htm");        // open web page file
                        if (webFile) {
                            while(webFile.available()) {
                                client.write(webFile.read()); // send web page to client
                            }
                            webFile.close();
                        }

Sending the web page one character per packet is incredibly slow.

  int dist;  
 digitalWrite(3, LOW); // Set the trigger pin to low for 2uS
 delay(2);
 digitalWrite(3, HIGH); // Send a 10uS high to trigger tRAnging
 delay(10);
 digitalWrite(3, LOW); // Send pin low again
 dist = pulseIn(2, HIGH); // Read in times pulse

You should read what the return type from pulseIn() is, and store the value in the correct type variable.

What do your Serial.print()s tell you is happening?

Yes there are 7 peripherals that i switch on and off, but 14 different switches that i read...what is strange about that?

It is slow but it works...

The return type has nothing to do with what hangs the program though...

The Serial.print()s are not showing something out of the ordinary...

Yes there are 7 peripherals that i switch on and off

So, they are outputs (from the Arduino's perspective).

but 14 different switches that i read

So, they are inputs (from the Arduino's perspective).

what is strange about that?

Nothing, if you think you write to inputs and read from outputs, as you said. Personally, I think doing that is strange.

oops i just realized what i was writing hehe... yes you are right 100% i got confused! Do you have any suggestions as to what the problem could be though ? I am testing as we speak and still haven't figured it out at all...