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.
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,
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("
");
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("
");
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("
");
client.print("Ch.6 (IN) = "); client.print(DI_6);
client.print("\n
\n");
client.print("Ch.7 (IN) = "); client.print(DI_7);
client.print("\n
\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
\n");
client.print("Ch.0 = "); client.print(AI_Raw0);
client.print("\n
\n");
client.print("Ch.1 = "); client.print(AI_Raw1);
client.print("\n
\n");
client.print("Ch.2 = "); client.print(AI_Raw2);
client.print("\n
\n");
client.print("Ch.3 = "); client.print(AI_Raw3);
client.print("\n
\n");
client.print("Ch.4 = "); client.print(AI_Raw4);
client.print("
");
client.print("Ch.5 = "); client.print(AI_Raw5);
client.print("</td><td valign=top>");
client.print("<b>Other:</b>");
client.print("\n
\n");
client.print("Ch.0 (Averaged) = "); client.print(AnaIY0);
client.print("\n
\n");
client.print("\nFormula:
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>");
}
}