Hi,
I'm creating a network connected light sensor. I've based the webserver component of it on examples and tutorials I've found. My problem is that about half the time it outputs a load of gibberish to the browser. It may work fine for some time then I get rubbish. I can't quite figure out any relationship between it and what the sketch is doing at the time.
I get stuff like this:
1 13:43:8
€Ø„&×Z¦dx«ëÕØHTTP/1.1 200 OK Content-Type: text/html mÑÖû¥ÇèÞÎíêè¥Í¯L¬Ã:ëbeYÈ߬öWïÄPúg™Ýa®d¢çÑóòÕ(СBÄ¿›iÂŒâ=£U&a¬²>l¨«¢gó‡û€X¸´³þ²‹HTTP/1.1 200 OK T(ÁÂ?ÑpùWtb0ªl/6¬( û‰ÔhÊ0¡Â&(¤AD5>l%¬òÃH?;(ÎQ¶ŒØÙ¹À˜ñÛȲ£ˆ¦l.A›ª¶e#µpqD?ÓŽAÚ«²×²3²þe‰; 4§Q‚ÔÙ,±.1)n,ÄkE,–Š€ò”TTŶ¤Èç¾{LÃ67Bˆ2::7Ã)[¢¾õÅÐ_°cPmœŒ'^»äûÅ"·lé •±"ËúĸßÞi€©;ÜêÁÀ·?%)’[ô4Q…
Current Light Power Content-Type: text/html < ent-Curre1rong>Current Light Power: 1.1662337779 w/m2
ccumulated Insolation: 13.0389604568 J/m2
UV: 1.2025973796 w/m2<
System Time: 25/8/2011 13:44:42
Current Light Power: 1.1662337779 w/m2 - 1
Accumulated Insolation: 124.0441284179 J/m2
The output should look like this:
System Time: 25/8/2011 13:47:56
Current Light Power: 1.1740260124 w/m2 - 1
Accumulated Insolation: 353.5269775390 J/m2
UV: 1.2000000476 w/m2 - 1
Here is the relevent section of webserver code, although I'll post the entire sketch in pastebin in a sec:
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html>");
client.println("<head>");
client.println("<title>Pyranometer and UV Meter</title>");
client.println("<meta http-equiv=\"refresh\" content=\"60\"> ");
client.println("</head>");
client.println("<body>");
// output the value of the light sensors
client.println("<p>");
client.print("<strong>System Time:</strong> ");
client.print(day());
client.print("/");
client.print(month());
client.print("/");
client.print(year());
client.print(" ");
client.print(hour());
client.print(":");
client.print(minute());
client.print(":");
client.print(second());
client.println();
client.print("
");
client.print("<strong>Current Light Power:</strong> ");
client.print(tsl1_energy2, DEC);
client.print(" w/m<sup>2</sup> - ");
client.print(tsl1_sens, DEC);
client.print("
");
client.print("<strong>Accumulated Insolation:</strong> ");
client.print(jouleCounter, DEC);
client.print(" J/m<sup>2</sup>");
client.print("
");
client.print("<strong>UV:</strong> ");
client.print(tsl2_energy2, DEC);
client.print(" w/m<sup>2</sup> - ");
client.print(tsl2_sens, DEC);
client.print("</p>");
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
// delay(1);
// close the connection:
client.stop();
}
Can anyone suggest where the problem may be coming from? Thanks,
David