Zoomkat is fabulous, but doesnt work for 7 button!

I have been working on the zoomkat code that he sent me. it's a great code and my problem is that I can have it work with 4 Button relay, but it does not work for 7 relays. to be correct thought, that when I add 7 relay code for the webpage the relays or LEDs do not response. but if I leave it with only 4 LED and relays it works just fine.
I have included the 1st code that is for 4 LEDs or relays, which works just fine, but the 2nd one that is for 7 relays/LEDs but none of them response. please look and see what I"m missing.

1st 4 LED code:

//zoomkat 12-08-12
//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a '
//address will look like http://192.168.1.70:80 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// Google Code Archive - Long-term storage for Google Code Project Hosting.

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 70 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80);; //server port

String readString;

//////////////////////

void setup(){

pinMode(5, OUTPUT); //pin selected to control
pinMode(6, OUTPUT); //pin selected to control
pinMode(7, OUTPUT); //pin selected to control
pinMode(8, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(9600);
Serial.println("server text box test1"); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string
readString += c;
//Serial.print(c);
}

//if HTTP request has ended
if (c == '\n') {

///////////////
Serial.println(readString); //see what was captured

//now output HTML data header

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();

client.println("");
client.println("");
client.println("");
client.println("");
client.println("JAVA Page");
client.println("");
client.println("");
client.println("

JAVA

");
client.println("
");
client.println("
");
client.println(""); //uses IP/port of web page

client.println("Enter Code:
");
client.println("
");
client.print("<input type=submit value='5 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='5 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.print("<input type=submit value='6 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='6 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.print("<input type=submit value='7 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='7 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.print("<input type=submit value='8 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='8 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.println("");
client.println("");
client.println("");

delay(1);
//stopping client
client.stop();

/////////////////////
if(readString.indexOf("5") >0)//checks for on
{
digitalWrite(5, HIGH); // set pin 5 high
Serial.println("Led On");
}
if(readString.indexOf("50") >0)//checks for off
{
digitalWrite(5, LOW); // set pin 5 low
Serial.println("Led Off");
}

if(readString.indexOf("6") >0)//checks for on
{
digitalWrite(6, HIGH); // set pin 6 high
Serial.println("Led 6 On");
}
if(readString.indexOf("60") >0)//checks for off
{
digitalWrite(6, LOW); // set pin 6 low
Serial.println("Led 6 Off");
}

if(readString.indexOf("7") >0)//checks for on
{
digitalWrite(7, HIGH); // set pin 7 high
Serial.println("Led On");
}
if(readString.indexOf("70") >0)//checks for off
{
digitalWrite(7, LOW); // set pin 7 low
Serial.println("Led Off");
}

if(readString.indexOf("8") >0)//checks for on
{
digitalWrite(8, HIGH); // set pin 8 high
Serial.println("Led On");
}
if(readString.indexOf("80") >0)//checks for off
{
digitalWrite(8, LOW); // set pin 8 low
Serial.println("Led Off");
}
//clearing string for next read
readString="";

}
}
}
}
}

now the 2nd code with 7 LEDs:

//zoomkat 12-08-12
//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a '
//address will look like http://192.168.1.70:80 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// Google Code Archive - Long-term storage for Google Code Project Hosting.

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 70 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80);; //server port

String readString;

//////////////////////

void setup(){

pinMode(3, OUTPUT); //pin selected to control
pinMode(4, OUTPUT); //pin selected to control
pinMode(5, OUTPUT); //pin selected to control
pinMode(6, OUTPUT); //pin selected to control
pinMode(7, OUTPUT); //pin selected to control
pinMode(8, OUTPUT); //pin selected to control
pinMode(9, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(9600);
Serial.println("server text box test1"); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string
readString += c;
//Serial.print(c);
}

//if HTTP request has ended
if (c == '\n') {

///////////////
Serial.println(readString); //see what was captured

//now output HTML data header

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();

client.println("");
client.println("");
client.println("");
client.println("");
client.println("JAVA Page");
client.println("");
client.println("");
client.println("

JAVA

");
client.println("
");
client.println("
");
client.println(""); //uses IP/port of web page

client.println("Enter Code:
");
client.println("
");
client.print("<input type=submit value='3 Garage ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='3 Garage OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.print("<input type=submit value='4 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='4 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.print("<input type=submit value='5 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='5 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.print("<input type=submit value='6 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='6 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.print("<input type=submit value='7 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='7 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.print("<input type=submit value='8 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='8 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.print("<input type=submit value='9 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='9 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");
client.println("");
client.println("");
client.println("");

delay(1);
//stopping client
client.stop();

/////////////////////
if(readString.indexOf("3") >0)//checks for on
{
digitalWrite(3, HIGH); // set pin 3 high
Serial.println("Led On");
}
if(readString.indexOf("30") >0)//checks for off
{
digitalWrite(3, LOW); // set pin 3 low
Serial.println("Led Off");
}

if(readString.indexOf("4") >0)//checks for on
{
digitalWrite(4, HIGH); // set pin 4 high
Serial.println("Led On");
}
if(readString.indexOf("40") >0)//checks for off
{
digitalWrite(4, LOW); // set pin 4 low
Serial.println("Led Off");
}

if(readString.indexOf("5") >0)//checks for on
{
digitalWrite(5, HIGH); // set pin 5 high
Serial.println("Led On");
}
if(readString.indexOf("50") >0)//checks for off
{
digitalWrite(5, LOW); // set pin 5 low
Serial.println("Led Off");
}

if(readString.indexOf("6") >0)//checks for on
{
digitalWrite(6, HIGH); // set pin 6 high
Serial.println("Led 6 On");
}
if(readString.indexOf("60") >0)//checks for off
{
digitalWrite(6, LOW); // set pin 6 low
Serial.println("Led 6 Off");
}

if(readString.indexOf("7") >0)//checks for on
{
digitalWrite(7, HIGH); // set pin 7 high
Serial.println("Led On");
}
if(readString.indexOf("70") >0)//checks for off
{
digitalWrite(7, LOW); // set pin 7 low
Serial.println("Led Off");
}

if(readString.indexOf("8") >0)//checks for on
{
digitalWrite(8, HIGH); // set pin 8 high
Serial.println("Led On");
}
if(readString.indexOf("80") >0)//checks for off
{
digitalWrite(8, LOW); // set pin 8 low
Serial.println("Led Off");
}

if(readString.indexOf("TurnOn") >0)//checks for on
{
digitalWrite(9, HIGH); // set pin 9 high
Serial.println("Led On");
}
if(readString.indexOf("TurnOff") >0)//checks for off
{
digitalWrite(9, LOW); // set pin 9 low
Serial.println("Led Off");
}

//clearing string for next read
readString="";

}
}
}
}
}

(I understand that having one or 7 buttons does not make any difference as far as entering the right code for each LED, but it's nice to have them)

one thing I tried and worked was that when I add only PinCodes and digitalwrites for extra 3 codes, they work, but when I add the buttons for it they wont respond anymore:

client.print("<input type=submit value='9 ON' style=width:100px;height:45px onClick=location.href='/?on8;'>");
client.print("<input type=submit value='9 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>");
client.println("
");

(I guess this makes a difference? but why? it shouldnt)

Thank you in advance.

Zoomkat's server code is just ok as long as it is not exposed to the internet.

Use the F() function to keep all those static strings in program memory.

         client.println(F("HTTP/1.1 200 OK"));
         client.println(F("Content-Type: text/html"));
         // and so on...

The below shows your four button code with the web page bundled in an F() macro to save memory space. Easy to do using the web page source.

//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a '
//address will look like http://192.168.1.70:80 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 70 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString;

//////////////////////

void setup(){

 pinMode(5, OUTPUT); //pin selected to control
 pinMode(6, OUTPUT); //pin selected to control
 pinMode(7, OUTPUT); //pin selected to control
 pinMode(8, OUTPUT); //pin selected to control
 //start Ethernet
 Ethernet.begin(mac, ip, gateway, gateway, subnet);
 server.begin();

 //enable serial data print
 Serial.begin(9600);
 Serial.println("server text box test1"); // so I can keep track of what is loaded
}

void loop(){
 // Create a client connection
 EthernetClient client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();

       //read char by char HTTP request
       if (readString.length() < 100) {

         //store characters to string
         readString += c;
         //Serial.print(c);
       }

       //if HTTP request has ended
       if (c == '\n') {

         ///////////////
         Serial.println(readString); //see what was captured

         //now output HTML data header

client.print(F(
"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
"<HTML>"
"<HEAD>"
"<meta name='apple-mobile-web-app-capable' content='yes' />"
"<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />"
"<TITLE>JAVA Page</TITLE>"
"</HEAD>"
"<BODY>"
"<H1>JAVA</H1>"
"<hr />"
"
"
"<FORM ACTION='/' method=get >"
"Enter Code: <INPUT TYPE=TEXT NAME='LED' VALUE='' SIZE='25' MAXLENGTH='50'>
"
"
"
"<input type=submit value='5 ON' style=width:100px;height:45px onClick=location.href='/?on8;'><input type=submit value='5 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>
"
"<input type=submit value='6 ON' style=width:100px;height:45px onClick=location.href='/?on8;'><input type=submit value='6 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>
"
"<input type=submit value='7 ON' style=width:100px;height:45px onClick=location.href='/?on8;'><input type=submit value='7 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>
"
"<input type=submit value='8 ON' style=width:100px;height:45px onClick=location.href='/?on8;'><input type=submit value='8 OFF' style=width:100px;height:45px onClick=location.href='/?off9;'>
"
"</FORM>"
"</BODY>"
"</HTML>"));

         delay(1);
         //stopping client
         client.stop();

         /////////////////////
         if(readString.indexOf("5") >0)//checks for on
         {
           digitalWrite(5, HIGH);    // set pin 5 high
           Serial.println("Led On");
         }
         if(readString.indexOf("50") >0)//checks for off
         {
           digitalWrite(5, LOW);    // set pin 5 low
           Serial.println("Led Off");
         }
         
         if(readString.indexOf("6") >0)//checks for on
         {
           digitalWrite(6, HIGH);    // set pin 6 high
           Serial.println("Led 6 On");
         }
         if(readString.indexOf("60") >0)//checks for off
         {
           digitalWrite(6, LOW);    // set pin 6 low
           Serial.println("Led 6 Off");
         }
         
         if(readString.indexOf("7") >0)//checks for on
         {
           digitalWrite(7, HIGH);    // set pin 7 high
           Serial.println("Led On");
         }
         if(readString.indexOf("70") >0)//checks for off
         {
           digitalWrite(7, LOW);    // set pin 7 low
           Serial.println("Led Off");
         }
         
         if(readString.indexOf("8") >0)//checks for on
         {
           digitalWrite(8, HIGH);    // set pin 8 high
           Serial.println("Led On");
         }
         if(readString.indexOf("80") >0)//checks for off
         {
           digitalWrite(8, LOW);    // set pin 8 low
           Serial.println("Led Off");
         }
         //clearing string for next read
         readString="";

       }
     }
   }
 }
}

Pin 4 is connected to the SD Card slot of the Ethernet Shield. Make sure you don't install an SD card if you use Pin 4 for anything else.

Looks like you've done a lot of copy and pasting but forgetting to change 8 and 9 to the relevant values.

I just looked at the eight button code and it seems that the presence of "TurnOn" and "TurnOff" is being used to control all the pins.

HI zoomkat.
yes that fixed it.

and yes i knew about then turnon and turnoff, i had changed them already but forgot to change them here.

and yes those 8 and 9 values are fixed.
it works fine now.

now why wouldn't it be ok to expose it to internet. if I have a specific code for each button, it would be like a password no?

I have had problems finding/writing a code that is webpage protected and same time can control 8 relays.
I could do it up to 4. (which makes me think, maybe I should use the f code)
thank you

davejava:
now why wouldn't it be ok to expose it to internet.

I think ST means that zk's code as-is, fails ST's test where he can lock your router by bombarding it with some stuff, the technicalities of which are way beyond me.

ST broke my implementation of zk's code, but provides a few lines of code that make it resilient to such attacks.

You can see my server here, it's powered up as I type this, no guarantees from our national utility though. (That's another story altogether.....)

thanks for all the info.

I have one problem with this though,
although I mentioned that it now works fine, to my surprise just turning on and off LEDs work fine.

but when I attach it to Relay 8 channel, all the lights are on initially. after 5 seconds or so the whole system turns off then turns back on

but it does respond to the command when it's on. but why it turns on and off ?

but when I attach it to Relay 8 channel, all the lights are on initially. after 5 seconds or so the whole system turns off then turns back on

One weakness of your page could be that you send a new page for every request, possibly even one for the favorite icon browsers routinely send. The below may also be causing strange behaviors. When you send a "50", both conditions would be met. Also, how are you powering your relays?

         /////////////////////
         if(readString.indexOf("5") >0)//checks for on
         {
           digitalWrite(5, HIGH);    // set pin 5 high
           Serial.println("Led On");
         }
         if(readString.indexOf("50") >0)//checks for off
         {
           digitalWrite(5, LOW);    // set pin 5 low
           Serial.println("Led Off");
         }

how could I fix that then?

I'm getting power from the arduino for the relay.

Measure the arduino +5v pin voltage when the relays are energized. Below is some simple server code that uses an embeded frame to collect anything sent from the botton request, and the status 204 to tell the browser not to refresh the page.

//zoomkat 10-6-13
//simple button GET with iframe code
//open serial monitor to see what the arduino receives
//use the ' instead of " in html ilnes 
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //ethernet shield mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino IP in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString; 

//////////////////////

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

          //now output HTML data header
             if(readString.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 204 Zoomkat");
               client.println();
               client.println();  
             }
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          
          client.println("<a href='/?on1' target='inlineframe'>ON</a>"); 
          client.println("<a href='/?off' target='inlineframe'>OFF</a>"); 

          client.println("<IFRAME name=inlineframe style='display:none'>");          
          client.println("</IFRAME>");

          client.println("</BODY>");
          client.println("</HTML>");
             }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on1") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

the 204 code didnt work. still blinks

voltage is 4.7-4.8

Did you correct the possible code issue mentioned in reply #10? I suggest you change your code to use commands like "5on" for 5 on and "5offf" for 5 off.

         /////////////////////
         if(readString.indexOf("5on") >0)//checks for on
         {
           digitalWrite(5, HIGH);    // set pin 5 high
           Serial.println("Led On");
         }
         if(readString.indexOf("5off") >0)//checks for off
         {
           digitalWrite(5, LOW);    // set pin 5 low
           Serial.println("Led Off");
         }

yes.
still does not work. still turns on/off.

strange

solved.

figured it out.

I've been chuckling ever since this thread started, every time I see "zoomkat is fabulous" pop up in my list of threads.