Cannot Upload the Web Page

Hi
I am working on a simple project which try to control a TV via Internet.
I changed the sketch written by someone from Arduino team to suit my application as below.

==============xxx=========================================

//simple button GET server code to control servo and arduino pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html
//for use with W5100 based ethernet shields
//Powering a servo from the arduino usually DOES NOT WORK.
//note that the below bug fix may be required
// Google Code Archive - Long-term storage for Google Code Project Hosting.

#include <SPI.h>
#include <Ethernet.h>
#include "sharpircode.h"

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 72 }; // ip in lan
byte gateway[] = { 192, 168, 1, 254 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString;

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

void setup(){

pinMode(8, OUTPUT); //IR LED

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//the pin for the servo co
//enable serial data print
Serial.begin(9600);
Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
EthernetClient 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

client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();

client.println("");
client.println("");
client.println("");
client.println("");
client.println("");
client.println("Home Automation");
client.println("");
client.println("");
client.println("

Home Automation

");
client.println("
");
client.println("
");

client.println("<a href="/?TVon"">TV On");
client.println("<a href="/?TVoff"">TV Off
");
client.println("
");

client.println("<a href="/?Volup"">Vol Up");
client.println("<a href="/?Voldn"">Vol Dn
");
client.println("
");

client.println("");
client.println("");

delay(1);
//stopping client
client.stop();

///////////////////// control arduino pin

// control TV
if(readString.indexOf("?TVon") >0)//checks for on
{

SendSharpOn();

client.println("");
}
// control TV Volume
if(readString.indexOf("?Volup") >0)//checks for on
{

SendSharpVolUp();
client.println("");
}

if(readString.indexOf("?Voldn") >0)//checks for down
{

SendSharpVolDn(); // if this function is uploaded together with above two function, cannot open web page
client.println("");
}

//clearing string for next read
readString="";

}
}
}
}
}

void pulseIR(long microsecs) {
// we'll count down from the number of microseconds we are told to wait

cli(); // this turns off any background interrupts

while (microsecs > 0) {
// 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(8, HIGH); // this takes about 3 microseconds to happen
delayMicroseconds(10); // hang out for 10 microseconds
digitalWrite(8, LOW); // this also takes about 3 microseconds
delayMicroseconds(10); // hang out for 10 microseconds

// so 26 microseconds altogether
microsecs -= 26;
}

sei(); // this turns them back on
}
void SendSharpOn() {
// This is the code for Sharp TV, for others use the tutorial
// to 'grab' the proper code from the remote

for(int i=0; i<100 ; i++){
pulseIR(sharpon[i*2+0]);
delayMicroseconds(sharpon[i*2+1]);
}
}

void SendSharpVolUp() {
// This is the code for Sharp TV, for others use the tutorial
// to 'grab' the proper code from the remote

for(int i=0; i<100 ; i++){
pulseIR(sharpvolup[i*2+0]);
delayMicroseconds(sharpvolup[i*2+1]);
}
}
void SendSharpVolDn() {

for(int i=0; i<100 ; i++){
pulseIR(sharpvoldn[i*2+0]);
delayMicroseconds(sharpvoldn[i*2+1]);
}
}

============================ sharpircode.h =======================
int sharpon[]={

320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 45320,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 43240,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 45740,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 0};

int sharpvolup[]={
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 46380,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 42180,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 1720,
320, 720,
320, 46740,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 740,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 42580,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 46740,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 0};

int sharpvoldn[]={
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 45320,
320, 1720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 43220,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 45740,
320, 1740,
320, 720,
320, 720,
320, 720,
320, 720,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 720,
320, 1740,
320, 1740,
320, 1740,
320, 720,
320, 1740,
320, 0};

When I upload the sketch with SendSharpOn() and SendSharpVolUp(), I can open the web page and function are working.

However, when I upload all 3 function together, then I cannot open the web page.
Error message says that server did not response. Other web browser says that time out.

I try to fix the problems by using different IP address, it doesn't.

I think there is a bug in the program.
Will it be Ethernet library bug? Or SPI bug? Because there is a note at the top of the sketch but I have no idea how to do.

Anybody encounter such problem before and solution?

Thanks

That code has some format errors in it. There was a bit of confusion on the IDE v1.0 Ethernet.begin() format. The client sketch code here downloads Google home page every 10 seconds.

Don't do that to Google too long, only as a test. Then change to your server ip.

This is server sketch code. It will convert two form inputs to integers, then sends them over the serial monitor.

edit: I had to find my a link to the server code. No sense posting it twice.

When I upload the sketch with SendSharpOn() and SendSharpVolUp(), I can open the web page and function are working.

However, when I upload all 3 function together, then I cannot open the web page.
Error message says that server did not response. Other web browser says that time out.

I try to fix the problems by using different IP address, it doesn't.

If one or two functions are OK, but three is not, then the problem is that you have run out of memory. You will need to move some of those massive arrays into PROGMEM.

I'd give serious consideration to learning how to get rid of the String class, to. It is very inefficient in how it handles memory allocation. People were writing text processing applications for 40 years before the String class came along. You can, too.

SurferTim
Thank you for your reply. I wait for your link if it may help solve my problem.
When I open your second link, I saw a zoomkat's post in which I came to know that his sketch is the one I used and modified to suit my application.
Now I am happy to know the original sketch writer and might get help from him.

zoomkat, please help me if you can. Because I work based on your sketch. :smiley:

PaulS
Thanks for comments. But I noticed that after compiling, binary sketch size if 15006 bytes of 32256 max. Is it still not enough memory? Sorry I have limited knowledge of programming. I know only cut and paste, simple modification.
If it is memory problem, please give me more hint how to do. I also try to search how to improve memory because I need to add more function like Chennel Up/Down and DVD players function.

Thanks advance.

zoomkat, please help me if you can. Because I work based on your sketch.

The best thing to do is start with simple code that works for basic internet interaction, and slowly modify it until it breaks. Then figure out what is causing the code to not work. My arduino pc is currently down so I can't do any arduino code tinkering/testing.

Hi zoomkat
Nice to hear from you.
You are right. I started from simple code (your code) and modified it. I even can play with 10 buttons and it works.
I tested IR signal separately and combine them now.
As I said earlier, with 2 function, it works. Then started with 3 functions and above. I don't think it is coding problem as it is simple and works. I think it is a bug in the library. That is the case, it is beyond my capability.
Too bad your pc is down, otherwise you will know my problem.
Anyway I am still trying to solve this problem.

Thanks.