Buttons to webserver

I am trying to pass button pushes to my web based program. The code on the Arduino does work, however somehow it also requests the url when no button is pushed (false-positives?).

Here is my code:

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
IPAddress dnServer(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress ip(192, 168, 1, 15);

IPAddress server(192, 168 , 1, 2);

EthernetClient client;

int ledPin = 13;

unsigned long timer01 = 0;
unsigned long timer02 = 0;
unsigned long timer03 = 0;
unsigned long timer04 = 0;
unsigned long timer05 = 0;
unsigned long timer06 = 0;
unsigned long timer07 = 0;
unsigned long timer08 = 0;
unsigned long timer09 = 0;
unsigned long timer10 = 0;
unsigned long timer11 = 0;
unsigned long timer12 = 0;
unsigned long timer13 = 0;
unsigned long timer14 = 0;
unsigned long timer15 = 0;
unsigned long timer16 = 0;

void setup() 
{
//  Serial.begin(9600); 
  
  Ethernet.begin(mac, ip, dnServer, gateway, subnet);
  
  pinMode(ledPin, OUTPUT);  // declare LED as output
  
  pinMode(22, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(23, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(24, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(25, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(26, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(27, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(28, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(29, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(30, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(31, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(32, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(33, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(34, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(35, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(36, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(37, INPUT_PULLUP);    // declare pushbutton as input
}



void loop()
{
  if(millis()<1000) { timer01=0; }
  if(millis()<1000) { timer02=0; }
  if(millis()<1000) { timer03=0; }
  if(millis()<1000) { timer04=0; }
  if(millis()<1000) { timer05=0; }
  if(millis()<1000) { timer06=0; }
  if(millis()<1000) { timer07=0; }
  if(millis()<1000) { timer08=0; }
  if(millis()<1000) { timer09=0; }
  if(millis()<1000) { timer10=0; }
  if(millis()<1000) { timer11=0; }
  if(millis()<1000) { timer12=0; }
  if(millis()<1000) { timer13=0; }
  if(millis()<1000) { timer14=0; }
  if(millis()<1000) { timer15=0; }
  if(millis()<1000) { timer16=0; }
  
  int val01 = digitalRead(22);  // read input value
  int val02 = digitalRead(23);  // read input value
  int val03 = digitalRead(24);  // read input value
  int val04 = digitalRead(25);  // read input value
  int val05 = digitalRead(26);  // read input value
  int val06 = digitalRead(27);  // read input value
  int val07 = digitalRead(28);  // read input value
  int val08 = digitalRead(29);  // read input value
  int val09 = digitalRead(30);  // read input value
  int val10 = digitalRead(31);  // read input value
  int val11 = digitalRead(32);  // read input value
  int val12 = digitalRead(33);  // read input value
  int val13 = digitalRead(34);  // read input value
  int val14 = digitalRead(35);  // read input value
  int val15 = digitalRead(36);  // read input value
  int val16 = digitalRead(37);  // read input value


  if (val01 == LOW && (millis()-timer01)>5000) { timer01=millis(); passToServer("1"); } 
  if (val02 == LOW && (millis()-timer02)>5000) { timer02=millis(); passToServer("2"); } 
  if (val03 == LOW && (millis()-timer03)>5000) { timer03=millis(); passToServer("3"); } 
  if (val04 == LOW && (millis()-timer04)>5000) { timer04=millis(); passToServer("4"); } 
  if (val05 == LOW && (millis()-timer05)>5000) { timer05=millis(); passToServer("5"); } 
  if (val06 == LOW && (millis()-timer06)>5000) { timer06=millis(); passToServer("6"); } 
  if (val07 == LOW && (millis()-timer07)>5000) { timer07=millis(); passToServer("7"); } 
  if (val08 == LOW && (millis()-timer08)>5000) { timer08=millis(); passToServer("8"); } 
  if (val09 == LOW && (millis()-timer09)>5000) { timer09=millis(); passToServer("9"); } 
  if (val10 == LOW && (millis()-timer10)>5000) { timer10=millis(); passToServer("10"); } 
  if (val11 == LOW && (millis()-timer11)>5000) { timer11=millis(); passToServer("11"); } 
  if (val12 == LOW && (millis()-timer12)>5000) { timer12=millis(); passToServer("12"); } 
  if (val13 == LOW && (millis()-timer13)>5000) { timer13=millis(); passToServer("13"); } 
  if (val14 == LOW && (millis()-timer14)>5000) { timer14=millis(); passToServer("14"); } 
  if (val15 == LOW && (millis()-timer15)>5000) { timer15=millis(); passToServer("15"); } 
  if (val16 == LOW && (millis()-timer16)>5000) { timer16=millis(); passToServer("16"); } 

//  Serial.println(millis());  

}


void passToServer(String button) 
{
  if (client.connect(server, 80)) 
  {
    String getstring = "GET /buttons.php?b=" + button + " HTTP/1.1";
//    Serial.println(getstring);
    client.println(getstring);
    client.println("Host: 192.168.1.2");
    client.println("User-Agent: button-server");
    client.println("Connection: close");
    client.println();
    client.stop();
  } 
}

Quite new with Arduino.. Am I doing something wrong?

xone86:
Quite new with Arduino.. Am I doing something wrong?

I think you are missing to read the server response.

client.println(); // here you are finished sending the server request
// here you should read the server response
client.stop(); // here you kill the TCP connection

At least you should wait for the response header lines (or timeout), even of you are not interested in the evaluation of the server response code like "200 OK" or something.

  pinMode(22, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(23, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(24, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(25, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(26, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(27, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(28, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(29, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(30, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(31, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(32, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(33, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(34, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(35, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(36, INPUT_PULLUP);    // declare pushbutton as input
  pinMode(37, INPUT_PULLUP);    // declare pushbutton as input

How about a for loop?
How about a for loop?
How about a for loop?
How about a for loop?
How about a for loop?
How about a for loop?
How about a for loop?
How about a for loop?
How about a for loop?

  if(millis()<1000) { timer01=0; }
  if(millis()<1000) { timer02=0; }
  if(millis()<1000) { timer03=0; }
  if(millis()<1000) { timer04=0; }
  if(millis()<1000) { timer05=0; }
  if(millis()<1000) { timer06=0; }
  if(millis()<1000) { timer07=0; }
  if(millis()<1000) { timer08=0; }
  if(millis()<1000) { timer09=0; }
  if(millis()<1000) { timer10=0; }
  if(millis()<1000) { timer11=0; }
  if(millis()<1000) { timer12=0; }
  if(millis()<1000) { timer13=0; }
  if(millis()<1000) { timer14=0; }
  if(millis()<1000) { timer15=0; }
  if(millis()<1000) { timer16=0; }

Where did the 1000 come from? Why not (properly) initialize the variables in setup() (or accept the fact that the compiler initialized them for you)?

You REALLY need to look at the state change detection example. And, the for statement reference page. And get rid of the stupid String usage. Completely unnecessary. You can easily use char * in place of String most places. Where you can't, you don't need Strings.

Am I doing something wrong?

Many things. Read jurs's post, too.