Go Down

Topic: HTML Button Turn ON/OFF with Ethernet Wiznet (Read 24309 times) previous topic - next topic

arduinohtml

Hello, i'm needing a source code for HMTL Button to turn ON and turn OFF a port of arduino with Ethernet Wiznet...

bld

#1
Sep 13, 2011, 04:49 pm Last Edit: Sep 13, 2011, 04:53 pm by bld Reason: 1

Hello, i'm needing a source code for HMTL Button to turn ON and turn OFF a port of arduino with Ethernet Wiznet...

Do you expect someone to just make it for you, or do you plan on putting some effort in yourself too?

Have you tried searching?

I just did, and found some projects involving exactly this.

And lastly, it looks like you already asked it here too http://arduino.cc/forum/index.php/topic,72201.msg540477.html#msg540477 another language, but still, double posting only leads to more frustrations than results.
captain-slow.dk | non contagious!

sui

http://code.google.com/p/rc-switch/source/browse/tags/v1.2/examples/Webserver/Webserver.pde

arduinohtml

Thank you for the link, very helpful! Unlike other users who talk a lot but do not add anything.

bld


Thank you for the link, very helpful! Unlike other users who talk a lot but do not add anything.

By that, I guess you didn't do what I suggested, to search for it. If you had done that, you would have found what you needed too.

But well, easier to just have others do the work, instead of actually having to figure it out.
captain-slow.dk | non contagious!

arduinohtml

sui, I put this code in my ArduinoUno and is now available. To test I'm trying to turn off the digital port 13 (which already has an LED).
I changed the "int RCTransmissionPin = 7;" to 13 but did not work. You know how to do?

Tissy

arduinohtml - Like yourself I am very new to Arduinos and the programming environment having bought my first Arduino only 6 weeks ago.

There are many useful resources available within this forum, but i think you need to start at the begining and learn the basics before jumping in the deep end.  This will give you a good platform to learn from.

Within the Arduino programming environment, click on FILE, EXAMPLES, BASICS there you will find some basic examples and I suggest you start wit BLINK.

With these forums, its always best to post some code and ask for assistance so people can see what you are trying to achieve.

With the help of one board member particulalry, I have learnt an awful lot and been very appriciative, so there are good people on this forum.

zoomkat

Very simple web based gui for turning pin 4 on and off.

Code: [Select]

//zoomkat 9-5-11
//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html
//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 }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port

String readString;

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

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, 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
  Client 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=\"/?on\" target=\"inlineframe\">ON</a>");
          client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>");

          //client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
          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("on") >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="";

        }
      }
    }
  }
}

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

arduinohtml

Zoomkat, exactly what I needed to find my problem. I put this code on my Arduino and it worked. The problem is that Google Chrome, click the "OFF" it flashes the pin 4 and turn on again. Already IExplorer8 by clicking on "OFF" it really turns off pin 4 normally. How the browser works requests are generating this flaw in this code. Have you seen this problem?

zoomkat

Have you used the serial monitor to see if something different is being sent to the arduino from the different brousers?
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

arcom

Hi, as I've read this post, I' ve decided to start working on my Ethernet Shield.
I've tried out the code given by Zookmat.
It seems the Ethernet part of the code is working fine, but the led ( I used the PIN 13 one),
is not lighting up.
In serial monitor I receive this output:
servertest1
GET /?on HTTP/1.1

Led On
GET /?off HTTP/1.1

Led Off
GET /?on HTTP/1.1

Led On


Ofc I' ve written 13 where there was the 4 as pin.
Also the code seems correct, I don't find any apparent error, it just seems
Arduino is ignoring the instruction:

digitalWrite(13, HIGH);


zoomkat

Quote
It seems the Ethernet part of the code is working fine, but the led ( I used the PIN 13 one), is not lighting up.


I forget the reason, but I don't think you can use pin 13 with the ethernet library. If you look close at the pin 13 led, it appears to be turning on/off very rapidly. I test the setup just by connecting my multimeter to pin 4 and watch the voltage change when the buttons are used.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

tkbyd

Another worked example is at....

http://sheepdogguides.com/arduino/art5serv.htm

arcom

Great work Zoomkat,
indeed it works very fine, using other pins.
Thank to this now i can switch on/off my HVAC at home even if I'm at
work and I can restart my dsl router that unfortunately locks up too often at work.
Thanks.

bld


work and I can restart my dsl router that unfortunately locks up too often at work.

How are you going to contact it when the router is stalled?
captain-slow.dk | non contagious!

Go Up