Home Autiomation via APP + Physical buttons

Morning guys, i'm trying to make a home automation system.
I already have the APP (Which works, btw), but now i'm trying to expand the system to be controlled with physical buttons.

Can someone lend me a hand with this?

Thanks in advance.

The APP sends the function ?led31 (not GET31, as in the image)

#include <SPI.h>
#include <Ethernet.h>

int led1 = 31;
int led2 = 33;
int led3 = 35;
int led4 = 37;
int but1 = 51;

int LEDST1;

int statusled1;
int statusled2;
int statusled3;
int statusled4;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 111 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;

void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(but1, INPUT);
Ethernet.begin(mac, ip);//, gateway, subnet);
server.begin();
delay(1000);
}

void loop()
{
button();
web ();
verif();
}

void web() {

EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

if (readString.length() < 100) {
readString += c;
}

if (c == '\n') {

if (readString.indexOf("?led31") >0){
LEDST1 = !LEDST1;
}

client.println("");

if (LEDST1 == HIGH){
client.println("LED -1- ON");
}
else {
client.println("LED -1- OFF");
}
client.println("
");

client.println("");
delay(1);
client.stop();
readString="";

}
}
}
}
}

void button()
{
if (!digitalRead(but1))
{
LEDST1= !LEDST1;
// digitalWrite(led1,LEDB1);
while(!digitalRead(but1));
delay (30);
}
}

void verif()
{
if (LEDST1)
{
digitalWrite(led1, HIGH);
}
else
{
digitalWrite(led1,LOW);
}
}

Led_Web3.ino (1.92 KB)

HI gimenes,

i don´t think that you will be satisfied with the button reading the way you implemented it.
if you press it, it will light up the led, if you let go, the led will go off.
you should store the old reading into a variable just have a look at the "Debounce" sample which comes with the Arduino IDE. I think you should try it this way...