Ethernet Shield Web Server All Pins Different names

Hi. My goal is to control all the pins i have spare from the Ethernet shield like 3 to 9, i want to have buttons in the the html and different names like “lights” “door” “siren” “etc”. Of course i care about the pins state so if i change PC or browser or just open the html (web server) after two days to know exactly the state of the pin.

i have a code to start i found a matrix way and a single way for one pin but the Q is can i make to work to my needs.

Thank you in Advance even if you don’t answer i know the time is precious to all of us, now days…

Nikos Pap.
Infrastructure Engineer T.E.


matrix way


#include <Ethernet.h>
#include <SPI.h>
//network NB: Pins 10, 11, 12 and 13 are reserved for Ethernet module. 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 10, 10 };
byte gateway[] = { 192, 168, 10, 254 };
byte subnet[] = { 255, 255, 255, 0 };

String inString = String(35);

String Led;

int led[] = {00, 2, 3, 4 , 5, 6, 7, 8, 9  }; //Led pins num 0 in array is not used
int numofleds = 8; //Number of Leds
String value[] = {"on","on","on","on","on","on","on","on","on"}; //startup all led are off

Server server(80);
String data;
void setup()
{
  Serial.begin(115200);
  Ethernet.begin(mac, ip, gateway, subnet); 
  server.begin();
  
 //set pin mode
  for (int j= 1; j < (numofleds + 1); j++){
    pinMode(led[j], OUTPUT);
  }
  Serial.println("Serial READY");
  Serial.println("Ethernet READY");
  Serial.println("Server READY");
  Serial.println("info @ Support-Plus");
  Serial.println("");
  Serial.println("www.support-plus.gr");
}

void loop()
{
  Client client = server.available();
  
  if(client){
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
     
      if(client.available()) {
      
        char c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (inString.length() < 35) {
            inString.concat(c);
         } 
        if (c == '\n' && current_line_is_blank) {
                    
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<html><body><form method=get>");
          client.println("<p>Led controller</p>");
         
         for(int i= 1; i < (numofleds + 1) ;i++){ 
           Led = String("led") + i;
           
          if(inString.indexOf(Led+"=on")>0 || inString.indexOf("all=on")>0){
            Serial.println(Led+"on");
            digitalWrite(led, HIGH);
            value = "off"; 
          }else if(inString.indexOf(Led+"=off")>0 || inString.indexOf("all=off")>0 ){          
            Serial.println(Led+"on");
            digitalWrite(led, LOW);
            value = "on";
          }
           client.println("
"+Led+"  <input type=submit name="+Led+" value="+value+">");
         }
         client.println("
All <input type=submit name=all value=on><input type=submit name=all value=off>");
         client.println("</from></html></body>");
          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    inString = "";
    client.stop();
  }
}

one led below


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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[]={192,168,0, 149};

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
Server server(80);

int LEDpin = 7;
String readString = String(30);
String state = String(3);

void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  
  //Sets the LEDpin as an output
  pinMode(LEDpin,OUTPUT);
  
  digitalWrite(LEDpin,LOW);
  state = "OFF";
}

void loop()
{
  // listen for incoming clients
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply

        if (readString.length() < 30) {
          readString.concat(c);
        }

        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          int LED = readString.indexOf("LED=");

          if (readString.substring(LED,LED+5) == "LED=T") {
            digitalWrite(LEDpin,HIGH);
            state = "ON";
          }
          else if (readString.substring(LED,LED+5) == "LED=F") {
            digitalWrite(LEDpin,LOW);
            state = "OFF";
          } 
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.print("LED is ");
          client.print(state);
          client.print("

");
          
          if (state == "ON") {
            client.println("<a href=\"./?LED=F\">Turn Off<a>");
          }
          else {
            client.println("<a href=\"./?LED=T\">Turn On<a>");
          }
          
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    readString = "";
    // close the connection:
    client.stop();
  }
}

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the # button above the posting area.

i have a code to start i found a matrix way and a single way for one pin but the Q is can i make to work to my needs.

There are a number of issues with that matrix code that I won't get into (yet). The real question is whether you understand what it is doing, and how what it is doing differs from what you want it to do.

If you understand the code, and how what it does differs from what you want it to do, you are 90% of the way to making it do what you want. The rest is trivial.

If you want, we can get into what is wrong with that code.

hi thanks for the replay, the think is i dont really care if it is a matrix or not, i notice that i cant do it in the matrix way this is the reason i am asking cause i am a n00b i am a civil engineer not a guru in C or html but i can handle it from the examples… so my goal is to make one big example of how to handle all the pins from sd via a html code - site. so i include that code just to ask you how i can do this ???

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Arduino Beta V1.0 </title>
</head>
<body>
<font face="arial">
<table width="480" height="640" border="1">
  <tr>
    <th height="78" colspan="3" scope="row" style="background-color:#FFA500">
      <h1><strong> Welcome to Ethernet Arduino Beta V1.0 ;)</strong></h1></th>
  </tr>
  <tr>
    <th height="116" scope="row" style="background-color:#FFD700"> <p><strong>Temperature</strong></p>
      <form name="TEMP" method="post" action="">
        <p></label><input type="radio" name="TEMP" value="LMC" id="LMC">LM35 C &nbsp;</label>
        
<label><input type="radio" name="TEMP" value="LMD" id="LMD">LM35 DZ</label>
        
<label><input type="radio" name="TEMP" value="BOTH" id="BOTH">Both</label></p>
      </form></th>
    <td width="141" style="background-color:#EEEEEE"><center><p><strong>LM35 C</strong></p>
    <h1><font color="#00FF00">   &#176C </font></h1>
      </p>
    </center></td>
    <td width="128" style="background-color:#EEEEEE"><center><p><strong>LM35 DZ</strong></p>
    <h1><font color="#00FF00">   &#176C </font></h1>
    </p>
    </center></td>
  </tr>
  <tr>
    <th height="315" scope="row" style="background-color:#FFD700">
    <p><strong>???? 1-4</strong></p>
      <form name="RELAY" method=get>
        <p>Led controller</p>
        
led1  <input type=submit name=led1 value=on> <input type=submit name=led1 value=off>
	
led2  <input type=submit name=led2 value=on> <input type=submit name=led2 value=off>
	
led3  <input type=submit name=led3 value=on> <input type=submit name=led3 value=off>
	
led4  <input type=submit name=led4 value=on> <input type=submit name=led4 value=off>
	
All   <input type=submit name=all  value=on> <input type=submit name=all  value=off>
</from>
     </form></th>
     <td colspan="2" style="background-color:#EEEEEE">
     <p>The <font face="arial">Led #1 is :</font></p>
     <p>The <font face="arial">Led #2 is :</font></p>
     <p>The <font face="arial">led #3 is :</font></p>
     <p>The <font face="arial">Led #4 is :</font></p></td>
  </tr>
  <tr>
    <th height="137" scope="row"style="background-color:#FFD700"><p>Movement Sensor PIR</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p></th>
    <td colspan="2" style="background-color:#EEEEEE"><p>&nbsp;</p></td>
  </tr>
  <tr>
    <th height="63" scope="row"style="background-color:#FFD700"><p>Smoke Sensor</p></th>
    <td colspan="2" style="background-color:#EEEEEE">
    <form name="SMOKER" method="post" action="">
      <label><input type="text" name="SR" id="SR"></label>ppm
    </form></td>
  </tr>
  <tr>
    <th width="177" height="101" scope="row"style="background-color:#FFD700"><p>Generar IR Sensor</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p></th>
    <td colspan="2" style="background-color:#EEEEEE">
    <form name="IRREDER" method="post" action="">
      <label><input type="text" name="IRR" id="IRR"></label>IR CODE
    </form>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <th height="23" colspan="3" scope="row"style="background-color:#FFA500"> Copyright © 2012 ALU Dev Team... @ <a target="_blank" href="http://www.support-plus.gr/">www.support-plus.gr</a></th>
</table>
</font>
</body>
</html>

This looks like HTML (take a look).

Please amend the post, copy your original code, and put that into code tags.

You can do that by hitting the # button above the posting area.

Or if it isn't supposed to be code, what is it? I'm confused.

mister nick the only thing you do is to play referee "do this , do that" dont forget i am FROM GREECE so i am GREEK it's not my mother lang and i am still trying to communicate and "rich up" my knowledge , so mister nick if you have something to say like a simple guide or correction yeap you are welcome.

but if you only do this just cause you have time to spent please its helpless.

Thanks in Advance this is only my opinion.

P.S. Yes this is the Final html code i like to use like a GUI Web site to control all my pins and read analog lm35 values and PIR and smoke sensor. this is my GOAL just to make i complete example fo others too cause i can learn from them more easy like common non programmer minds.

nikkpap: mister nick the only thing you do is to play referee "do this , do that" dont forget i am FROM GREECE so i am GREEK it's not my mother lang and i am still trying to communicate and "rich up" my knowledge , so mister nick if you have something to say like a simple guide or correction yeap you are welcome.

It's hard to forget something that you were never told, but that's another argument. There are plenty of people on these forums who are not native English speakers, but that's not a free pass to ignore instructions that are meant to help you communicate your issue. Nick was helping you, despite what you think.

The first principle in a forum is to respect the moderators; they're always trying to help. Nick is very knowledgable and helpful. Greek here, civil engineer, not a guru also.

Hi. My goal is to control all the pins i have spare from the Ethernet shield like 3 to 9, i want to have buttons in the the html and different names like "lights" "door" "siren" "etc". Of course i care about the pins state so if i change PC or browser or just open the html (web server) after two days to know exactly the state of the pin.

I suggest you start with very simple code to control the desired pins, saving their current statee change in a variable. Then work on returning their current state when requested.