Webserver crashes with all but simple HTML - Do I need to escape some chars?

So, I’m using the CC3000 Wifi shield with the Arduino Mega and the basic HTTP server example (Adafruit_CC3000_ClientRef), which works until I try to pass some actually useful HTML.

Specifically when connected instead of printing ‘Hello World’ I print the following which does work but its useless…

client.print(“

TEST

”);

I want to include some external jQuery libraries and such (loaded remotely) but I can’t even get the following tweak to work without crashing (restarting) the server.

client.print("<script src=“http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.js” type=“text/javascript”>

TEST

");

I’m missing something obvious again I think.

I'm missing something obvious again I think.

yes, posting your complete code per #7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html

Crashing is usually a memory issue. run a memory check at runtime.
use the F macro for static strings to save memory.

TEST

"));

I’ve taken the basic Adafruit webserver example with an LCD (shift register) and attempted to get it to output some more complex HTML. Memory should not be the issue here as I’m using the Ardiono Mega.

I’m changing only one line to stop the code from functioning passed the point of output

Works

client.print("<html><meta></meta><h1>TEST</h1></html>");

This does not

client.print("<html><head><script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.js\" type=\"text/javascript\"></script></head><h1>TEST</h1></html>");

HTTPServer_with_lcd_controller.ino (11.1 KB)

Well I still don’t know why that previous sketch didn’t work but I modified it to use fastprintln() as follows and it works just fine!

client.fastrprintln(F("<html>"));
client.fastrprintln(F("<head>"));
client.fastrprintln(F("<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.js\" type=\"text/javascript\"></script>"));
client.fastrprintln(F("<script src=\"http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.js\" type=\"text/javascript\"></script>"));
client.fastrprintln(F("<link rel=\"stylesheet\" href=\"http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css\" type=\"text/css\" />"));
client.fastrprintln(F("</head>"));
client.fastrprintln(F("<style>"));
client.fastrprintln(F("body {"));
client.fastrprintln(F("background:url('http://www.janetbaxterphotography.co.uk/img/s3/v8/p257690339-3.jpg')no-repeat center center fixed;"));
client.fastrprintln(F("-webkit-background-size: cover;"));
client.fastrprintln(F("-moz-background-size: cover;"));
client.fastrprintln(F("-o-background-size: cover;"));
client.fastrprintln(F("background-size: cover;"));
client.fastrprintln(F("padding: 20px;"));
client.fastrprintln(F("font-family: 'Droid Serif';"));
client.fastrprintln(F("font-size: 15px;"));
client.fastrprintln(F("line-height: 24px;"));
client.fastrprintln(F("color: #333;"));
client.fastrprintln(F("}"));
client.fastrprintln(F("input {"));
client.fastrprintln(F("color: #333;"));
client.fastrprintln(F("}"));
client.fastrprintln(F("#resting-temp {"));
client.fastrprintln(F("background: -webkit-linear-gradient(left, blue, red); /* For Safari 5.1 to 6.0 */"));
client.fastrprintln(F("background: -o-linear-gradient(right, blue, red); /* For Opera 11.1 to 12.0 */"));
client.fastrprintln(F("background: -moz-linear-gradient(right, blue, red); /* For Firefox 3.6 to 15 */"));
client.fastrprintln(F("background: linear-gradient(to right, blue, red); /* Standard syntax */"));
client.fastrprintln(F("}"));
client.fastrprintln(F("#container {"));
client.fastrprintln(F("padding: 20px;"));
client.fastrprintln(F("background:rgba(255,255,255,0.5);"));
client.fastrprintln(F("}"));
client.fastrprintln(F("#2 {"));
client.fastrprintln(F("padding: 20px;"));
client.fastrprintln(F("}"));
client.fastrprintln(F("</style>"));
client.fastrprintln(F("<script>"));
client.fastrprintln(F("$(function() {"));
client.fastrprintln(F(" $( \"#resting-temp\" ).slider({"));
client.fastrprintln(F("range: \"max\","));
client.fastrprintln(F("min: 10,"));
client.fastrprintln(F("max: 35,"));
client.fastrprintln(F("value: 21,"));
client.fastrprintln(F("slide: function(event, ui) {"));
client.fastrprintln(F("$(\"#temp\").val( ui.value );"));
client.fastrprintln(F("}"));
client.fastrprintln(F("});"));
client.fastrprintln(F("$(\"#temp\").val($( \"#resting-temp\" ).slider( \"value\" ));"));
client.fastrprintln(F("});"));
client.fastrprintln(F("</script>"));
client.fastrprintln(F("<body>"));
client.fastrprintln(F("<div id=\"container\">"));
client.fastrprintln(F("<div id=\"2\">"));
client.fastrprintln(F("<h1>Al9000 - Heating Control</h1>"));
client.fastrprintln(F("<p>Welcome to the Al900 control center. The current temperature is &deg;C.</p>"));
client.fastrprintln(F("<form method=\"get\">"));
client.fastrprintln(F("<div>"));
client.fastrprintln(F("<h2>Hot Water</h2>"));
client.fastrprintln(F("<p>On<input type=\"radio\" name=\"hotwater\" value=\"On\" />&nbsp;Off<input type=\"radio\" name=\"hotwater\" value=\"Off\" /></p>"));
client.fastrprintln(F("</div>"));
client.fastrprintln(F("<div>"));
client.fastrprintln(F("<h2>Heating</h2>"));
client.fastrprintln(F("<p>On<input type=\"radio\" name=\"heating\" value=\"On\" />&nbsp;Off<input type=\"radio\" name=\"heating\" value=\"Off\" /></p>"));
client.fastrprintln(F("</div>"));
client.fastrprintln(F("<div>"));
client.fastrprintln(F("<h2>Resting Temperature</h2>"));
client.fastrprintln(F("<p>"));
client.fastrprintln(F("<label for=\"temp\">Current Setting: </label><input type=\"text\" id=\"temp\" name=\"temp\" style=\"width:1.25em;border:0; font-weight:bold; background:none;\">&deg;C"));
client.fastrprintln(F("</p>"));
client.fastrprintln(F("<div id=\"resting-temp\"></div>"));
client.fastrprintln(F("</div>"));
client.fastrprintln(F("
"));
client.fastrprintln(F("<input style=\"uk-button\" type=\"submit\" value=\"save\" />"));
client.fastrprintln(F("</form>"));
client.fastrprintln(F("</div>"));
client.fastrprintln(F("</div>"));
client.fastrprintln(F("</body>"));
client.fastrprintln(F("</html>"));

Must be a peculiar bug with your ethernet shield.

Well I still don't know why that previous sketch didn't work but I modified it to use fastprintln() as follows and it works just fine!

It was NOT changing println() to fastprintln() that made the difference. It WAS using the F() macro.

PaulS many thanks for the clarification!

So, as I'm sure this will be helpful to others trying to create a webserver. You might find that your webserver intermittently stops working or that requests take a long time to complete. I fixed this by changing the CC3000 settings. Edit the file Adafruit_CC3000_Server.h and set MAX_SERVER_CLIENTS to 1. Fixed all my intermittent connectivity issues!

geedon: I fixed this by changing the CC3000 settings. Edit the file Adafruit_CC3000_Server.h and set MAX_SERVER_CLIENTS to 1. Fixed all my intermittent connectivity issues!

Which is probably a good indication that you're using too much RAM....

Regards, Ray L.

RayLivingston: Which is probably a good indication that you're using too much RAM....

Regards, Ray L.

I don't think its a memory issue as I can duplicate the issue with the most basic examples on the mega. Personally I believe its a limitation of the CC3000 and/or associated library. Luckily I need only 1 connection.