Ethernet and mains trigger

    delay(5);  //slow looping to allow buffer to fill with next character

This

is

a

piss-

poor

way

to

read

all

the

data.

Spin in a while loop, while the client is connected.
In that while loop, use the while loop to read all the data AS SOON AS IT ARRIVES.

The inner while loop loop will start and stop many times. The outer while loop will end as soon as the server has sent the complete response.

Speaking of piss-poor, your code looks like it was typed by a drunken monkey. Use Tools + Auto Format to sober that monkey up.

the check is done if the mains is pulled out, or if the ethernet module recieves a 1

What is the mains powering?

ledconnect and leddisconnect names might mean something to you. They mean less than nothing to me.

checking, val, x, etc. might mean something to you. They mean less than nothing to me.