Web Switch

I need source code for web switch

Any suggestion for the source code.

Thanks and advanced

Some simple web server code.

//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 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);

  //enable serial data print 
  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; 

        //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\r\n\r\n");
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");

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

          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'>");          


          //stopping client

          ///////////////////// 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


Unknown28: I need source code for web switch

Any suggestion for the source code.

In Message http://forum.arduino.cc/index.php?topic=322364.msg2247138#msg2247138 I have included a file attachment on request of a guy who requested a similar code.

Unfortunately nobody wrote any comment about the code I posted, not even the guy who requested it.

Please give it a try, if you like.

no any other codes sir ?

Unknown28: no any other codes sir ?

You've gotten two examples plus the web server example that comes with the Arduino IDE.

So, yeah, no more until you get off your butt and try them and explained why they are not sufficient.

Unknown28: no any other codes sir ?

Have you tried the forum google search in the upper right side of this page?

this is a situation sir The codes i'll first we used is limited only she can function so i can finds a different code to try. that's why i'm asking codes for web switch i want to try any codes for that.

It may be difficult to help you for the reason(s) indicated by a checked box (*) below:

() You posted without reading any threads, including the first one, "How to use this forum - please read". () You posted a program without reading the second thread, "Read this before posting a programming question". () You have not clearly stated the problem that you are actually experiencing. () You haven't said what hardware your program is using. () Instead of your complete code, you have only provided snippets of code for analysis, thus creating a Mensa puzzle. () Your question has nothing whatsoever to do with the forum subject category. () Your technical writing style is almost unintelligible (even though English is your native language). () You obviously don't believe in reading standard manuals or online reference materials that have the answer to your question. () You are presenting the work of others as if it is your own. () You insist that you have a hardware problem when it is obviously a software problem. () You insist that you have a software problem when it is obviously a hardware problem. () Your very first program is 7,532 lines long and you just tested it for the first time because you continually massaged it to compile correctly. () Your 7,532 line program is full of undocumented magic numbers like 0x48383838929 and mysterious variables like lx, _foo89, and puppyChow. () The control flow of your program would make Mr. Spock cry. () You believe that the computer should understand what you meant, not what you wrote. () You are blaming the problems that you caused on the IDE/compiler/C++ standard/etc. () You are trying to get other people to write your program for you for free. () You are trying to learn to program by trial and error. () You need to learn to program without asking for help every 2 minutes. () You ask for help, but don't process the replies mentally. () You ask for help, but then act defensive or smug when the advice that is given contradicts your beliefs. () You believe that pleading, begging or whining will motivate people to help you. () After way too many helpful replies, you still don't get it.

Self evaluation: 1-3 check marks: Noob 4-8 check marks: Will never learn 9+ check marks: Toronto Maple Leafs fan

i'm very sorry sir.

Unknown28: i'm very sorry sir.

It's not too late to pursue reply #1 and #2, develop some code and post it here. Then you will get help. Most people who come here do.

Edit - actually, post it in the programming help forum, not this one...

Sir the second is not related to the web switch, can u give another one. please!

See reply #4

i'm using arduino with ethernet shield and relay.

How do you plan on developing a switch with one port? Are you certain it is a switch you want?

A switch, as in a packet switch, or a switch as in an electrical switch? Too bad you didn't tell us 2 weeks ago.

zoomkat gave him the answer for an electrical switch in reply #1. I'm just pulling the OP's chain. ;)

look at this files sir this our code and my problem is my code. i’ll try to use another code.

scode2.txt (57.7 KB)

It seems to me that you have what you are looking for in “scode2.txt”. What is your question?

he could have limited function, that's why i always ask other source code to try.

look at this files sir this our code and my problem is my code. i'll try to use another code.

7 below: