Pages: [1]   Go Down
Author Topic: Need help with webserver  (Read 734 times)
0 Members and 1 Guest are viewing this topic.
Buena Vista, CO
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I'm trying to set up a webserver which accepts comands fron the internet. I used
as an example the program at

http://www.charmcitynetworks.com/techblog/web-controlled-window-air-conditioner-using-and-arduino/

my code:

Code:
#include <[color=#CC6600]SPI[/color].h>
#include <[color=#CC6600]Ethernet[/color].h>
#define BUFSIZ 100
[color=#CC6600]byte[/color] mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
[color=#CC6600]byte[/color] ip[] = {192,168,0,14};
[color=#CC6600]Server[/color] server(80);
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
  [color=#CC6600]Ethernet[/color].[color=#CC6600]begin[/color](mac, ip);
  server.[color=#CC6600]begin[/color]();
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600);
}
[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()
{
  [color=#CC6600]char[/color] clientline[BUFSIZ];
  [color=#CC6600]char[/color] c;
  [color=#CC6600]int[/color] index = 0;
  [color=#CC6600]int[/color] stat = 0;
  [color=#7E7E7E]// listen for incoming clients[/color]
  [color=#CC6600]Client[/color] client = server.[color=#CC6600]available[/color]();
  [color=#CC6600]if[/color] (client)
  {
    [color=#CC6600]boolean[/color] currentLineIsBlank = [color=#CC6600]true[/color];
    [color=#CC6600]while[/color] (client.[color=#CC6600]connected[/color]())
    {
      [color=#CC6600]if[/color] (client.[color=#CC6600]available[/color]())
      {
        [color=#CC6600]char[/color] c = client.[color=#CC6600]read[/color]();
        [color=#CC6600]if[/color] (c != [color=#006699]'\n'[/color] && c != [color=#006699]'\r'[/color]) {
          clientline[index] = c;
          index++;
          [color=#CC6600]if[/color] (index >= BUFSIZ)
            index = BUFSIZ -1;
          [color=#CC6600]continue[/color];
        }
        clientline[index] = 0;
        [color=#CC6600]if[/color] (strstr(clientline, [color=#006699]"GET / "[/color]) != 0)
        {
          [color=#7E7E7E]// send a standard http response header[/color]
          client.[color=#CC6600]println[/color]([color=#006699]"HTTP/1.1 200 OK"[/color]);
          client.[color=#CC6600]println[/color]([color=#006699]"Content-Type: text/html"[/color]);
          client.[color=#CC6600]println[/color]();
          client.[color=#CC6600]println[/color]([color=#006699]"<html>"[/color]);
          client.[color=#CC6600]println[/color]([color=#006699]"<body>"[/color]);
          client.[color=#CC6600]print[/color]([color=#006699]"<FORM action=\"http://192.168.0.14/\" >"[/color]);
          client.[color=#CC6600]print[/color]([color=#006699]"<INPUT type=\"hidden\" name=\"status1\" value=\"1\">"[/color]);
          client.[color=#CC6600]print[/color]([color=#006699]"<INPUT type=\"submit\" value=\"Led On\"> </FORM>"[/color]);
          client.[color=#CC6600]print[/color]([color=#006699]"<FORM action=\"http://192.168.0.14/\" >"[/color]);
          client.[color=#CC6600]print[/color]([color=#006699]"<INPUT type=\"hidden\" name=\"status0\" value=\"0\">"[/color]);
          client.[color=#CC6600]print[/color]([color=#006699]"<INPUT type=\"submit\" value=\"Led Off\"> </FORM>"[/color]);
          [color=#CC6600]break[/color];
        }         
        [color=#CC6600]else[/color] [color=#CC6600]if[/color] (strstr(clientline, [color=#006699]"status0"[/color]) != 0)
        {
         [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](clientline);
         doZero;
          [color=#CC6600]break[/color];
        }
        [color=#CC6600]else[/color] [color=#CC6600]if[/color] (strstr(clientline, [color=#006699]"status1"[/color]) != 0)
        {
         [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](clientline);
          doOne;
          [color=#CC6600]break[/color];
        }
         [color=#CC6600]else[/color]
        {
          client.[color=#CC6600]println[/color]([color=#006699]"HTTP/1.1 404 Not Found"[/color]);
          client.[color=#CC6600]println[/color]([color=#006699]"Content-Type: text/html"[/color]);
          client.[color=#CC6600]println[/color]();
        }
      }
    }
    [color=#CC6600]delay[/color](1);
    client.[color=#CC6600]stop[/color]();
  }
}
[color=#CC6600]void[/color] doZero()
{
}
[color=#CC6600]void[/color] doOne()
{
}


it works somewhat, using my test program shows two buttons. The Serial monitor shows that clicking
the on button gives:

GET /?status1=1 HTTP/1.1

and clicking the off button gives:

GET /?status1=0 HTTP/1.1

The problem is that the browser then gives error message

The connection was reset

and browser address line is

http://192.168.0.14/?status1=1  or 0

what I need is to reload 192.168.0.14, how do I do that?

Jim
Logged

8000ft above the average

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you re-copy your code from the IDE please? Don't use the copy for forum option, as it puts all those color tags in, and makes it impossible to read.
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might get better results if you post this question in one of the other forum areas.  My guess would be to try the Networking, Protocols, and Devices area.

Don
Logged

Buena Vista, CO
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might get better results if you post this question in one of the other forum areas.  My guess would be to try the Networking, Protocols, and Devices area.

Don

Would the moderator of this forum move this to Networking, Protocols, and Devices

Jim
Logged

8000ft above the average

Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i might be able to help you on this...

so you want to clidk on a button and then do something else? like move to another weppage or update values?
Logged


Pages: [1]   Go Up
Jump to: