Pages: [1]   Go Down
Author Topic: Wired Ethernet, Arduino Web Server problem  (Read 2176 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I am testing using an Arduino Duemilanove (328) as a wee web server. I have it working and the Arduino reacts to a request and sends out the webpage.

Here's it is:-
http://www.ianjohnston.com:1234

However, you'll see some corrupt html......and this is the problem, I don't know why it is happening. Certainly there is no problem with the html source in my sketch.
Funny thing is that if I modify the html by adding or deleting then the corruptness moves to a different area.....so it's not as I have a bad html tag or something.

I can't print my entire sketch as it won't fit. But here's the main loop and the sendpage.

You'll see there's 4 lines commented out (a form), and if I uncomment that then Arduino won't even startup....even before the web page is sent!

Any ideas?

PS. I'll be testing later on so you may see the server up and down etc as I starting troubleshooting this again.

Ian.

Code:
void loop() {

  Client client = server.available();
  if (client) { // now client is connected to arduino

    // read HTTP header request... so select what page client are looking for
    HTTP_DEF http_def = readHTTPRequest(client);

    if (http_def.pages > 0) {
          sendPage(client,http_def);
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
 
}

And,

Code:
void sendPage(Client client,struct HTTP_DEF http_def) {
if (http_def.pages==1) {

client.println("HTTP/1.1 200 OK");
//client.println("HTTP/1.0 200 OK\nServer: arduino\nCache-Control: no-store, no-cache, must-revalidate\nPragma: no-cache\nConnection: close\nContent-Type: text/html\n");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>IanJ's Arduino Web Server</title></head>");
client.print("\n<p>\n");
client.print("<table width=800 border=1>");
client.print("<tr><td align=middle colspan=3>");

client.print("<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td align=left width=200>");
//client.print("<form method=\"post\" NAME=\"refresh\" action=\"http://");
//client.print(Domain);
//client.print("\" NAME=\"id1\">");
//client.print("<button name=\"submit2\" value=\"button2\" type=\"submit\">Refresh</button></form>");
client.print("</td><td align=middle width=600><font size=+2><b>IanJ's Arduino Web Server</b></font></td>");
client.print("<td width=200>.</td></tr></table>");
            
client.print("</td></tr>");
client.print("<tr><td width=33% height=200 valign=top>");
client.print("<b>Stats:</b>");  
client.print("<br>");  
client.print("Uptime = "); client.print(days); client.print("days "); client.print(hours); client.print("hrs ");  client.print(minutes); client.print("mins ");  client.print(seconds); client.print("secs");
client.print("<br>");
client.print("<form method=\"post\" action=\"http://");
client.print(Domain);
client.print("id2\" NAME=\"id2\">");
client.print("Web count access's = ");
client.print(countEEPROM);
client.print(" ");
client.print("<BUTTON name=\"submit\" value=\"button\" type=\"submit\">Reset</button></form>");
client.print("</td><td width=33% valign=top>.");
client.print("</td><td width=33% valign=top>.");
client.print("</td></tr>");
client.print("<tr><td height=200 valign=top><b>Digital I/O:</b>");
client.print("<br>");
client.print("Ch.6 (IN)  = "); client.print(DI_6);
client.print("\n<br>\n");
client.print("Ch.7 (IN)  = "); client.print(DI_7);
client.print("\n<br>\n");
client.print("Ch.1 (OUT) = "); client.print(DO_Pin1);
client.print("</td><td valign=top>");
client.print("<b>10bit Analogue Inputs (Raw):</b>");
client.print("\n<br>\n");
client.print("Ch.0 = "); client.print(AI_Raw0);
client.print("\n<br>\n");
client.print("Ch.1 = "); client.print(AI_Raw1);
client.print("\n<br>\n");
client.print("Ch.2 = "); client.print(AI_Raw2);
client.print("\n<br>\n");
client.print("Ch.3 = "); client.print(AI_Raw3);
client.print("\n<br>\n");
client.print("Ch.4 = "); client.print(AI_Raw4);
client.print("<br>");
client.print("Ch.5 = "); client.print(AI_Raw5);
client.print("</td><td valign=top>");
client.print("<b>Other:</b>");
client.print("\n<br>\n");            
client.print("Ch.0 (Averaged) = "); client.print(AnaIY0);
client.print("\n<br>\n");            
client.print("\nFormula:<br>Yn=Yn-1+(1/k*(Xn-Yn-1))\n");
client.print("</td></tr>");
client.print("<tr><td align=middle colspan=3><i>by Ian Johnston</i></td></tr>");
client.print("</table>");
client.print("</head><html>");
}
}
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just noticed,

client.print("</head><html>");
should be:-
client.print("</head></html>");

But that shouldn't cause the problem.

Ian.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49080
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How big is your compiled sketch? I'm guessing that you are exceeding the Arduino's memory size limits, for either flash or SRAM.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just over 11k is reported when compiling.

Ian.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49080
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still worth taking a look at this:
http://www.faludi.com/2007/04/18/arduino-available-memory-test/
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

"Memory test results: 38 bytes free"

Oh dear!

Ian.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49080
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, dear! indeed. It seems that you've found the source of the problem.

You might be able to move some of the literal strings to PROGMEM.

http://www.arduino.cc/en/Reference/PROGMEM
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Already using PROGMEM for other stuff......looks like the wallet is gonna get a thrashing for an Arduino Mega....

Thanks for your help.

UPDATE:-

Well I stripped out some code and got the free mem up a good bit.....but still experiencing the problem.
I thought there may be some problems with Ethernet.h so found this tweak......and touchwood it's looking good so far.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235991468

Ian.
« Last Edit: January 26, 2010, 01:30:44 pm by IanJohnston » Logged

Pages: [1]   Go Up
Jump to: