Pages: [1]   Go Down
Author Topic: Web browser control  (Read 1405 times)
0 Members and 1 Guest are viewing this topic.
Namibia, Walvis Bay
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Persistance pays off
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm new to Arduino, although I have experience with industrial and marine automation and control. Also a bit of Pascal background.

My problem is simple, I have connected my arduino to my network with the ethernet shield and used the examples to view the data in a web browser, etc. I want to toggle a LED from my web browser, just put it on and off, but my lack of programming knowledge makes this extremely difficult! I have searched for examples but find them difficult to understand.

Thanks in advance for any help! (details please....Thanks again :-[)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 633
Posts: 34514
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure what you are specifically asking for here.
Have you got an example code that does this?
Most Ethernet shields do come with one that will toggle an LED from a web browser.
Best bet is if you get some code, post it or post a link to it and say what you don't understand about it or ask if someone can modify it to do ... what ever you want.
Logged

Namibia, Walvis Bay
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Persistance pays off
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My apologies, here is the code from an example I use. I have slightly modified it to display an input box with a send button. If the input box contains the character "1", and the send button is pressed, the LED on my PIN 9 should switch on. I just don't know how to "read" the character in the input box.

Code:
#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[] = { 10,200,1,245 };

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

void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
}


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 (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          
client.println("<FORM>");
client.println("<TR>");
client.println("<TD><NOBR>Digital State: <INPUT NAME=""digitalin"" SIZE=4></NOBR></TD>");
client.println("<TD><INPUT TYPE=BUTTON OnClick=""digitalin(this.form);"" VALUE=""Send""></TD>");
client.println("</TR>");
client.println("</FORM>");



          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("<br />");
          }
          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(5);
    // close the connection:
    client.stop();
  }
}


Thanks for the reply
« Last Edit: November 04, 2010, 08:02:13 am by edenlgx » Logged

Holland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 439
Arduino likes cookies too
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you edit your post and put the code inside [ code]code here[ /code] tags? (minus the space, obviously)

Also, what ethernet shield do you use? there are 3 floating around to my knowledge, one easier than the other.
Logged

Namibia, Walvis Bay
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Persistance pays off
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use the Arduino ETHShield SD
Logged

Oxford, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Edenlgx,
I have been thinking about this as well - I can't decide whether I need to configure the Arduino as a client or a server. I wanted the page to be in synch with the Arduino - so LED on - page button on - I guess the Arduino would have to serve a different page depending on it's state
Any thoughts?
Pete
Logged

Holland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 439
Arduino likes cookies too
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The difference between client and server is easy...

If you want to ask it about things -> server
If you want it to ask something from something else -> client

Though there are plenty of projects conceivable that would use both methods (they are combineable).
As for ethernet shield, perhaps a link to the product will be more helpful.
I myself have a DFRobot ethernet shield, which uses the wiz5100 chip, there are two other variants that use cheaper chips.. which use a different library than the default one shipped with the IDE.
Logged

Namibia, Walvis Bay
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Persistance pays off
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Link to the Shield I use

http://arduino.cc/en/Main/ArduinoEthernetShield
Logged

Pages: [1]   Go Up
Jump to: