Hey Everyone new to the arduino still because I do not use it at all but picked up the Ethernet shield to play with have been having fun with it but have run into a problem... My code times out so i can never get to it from a web browser if I use simple html like 2 lines it works but anything more just times out...
Please let me know what you think is wrong
// Define Libraries required
#include <Ethernet.h>
#include <WString.h> // TextString Library
#include <Wire.h>
#include <BlinkM_funcs.h> // BlinkM Library
#define blinkm_addr 0x00 // Set BlinkM Address here
// Setup for Web Server Mac, IP, Gateway, Subnet, and Port
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Mac Address needs to be Unique
byte ip[] = { 192, 168, 6, 177 }; // IP Address
byte gateway[] = { 192, 168, 6, 1 }; // Gateway
byte subnet[] = { 255, 255, 255, 0 }; // Subnet
char c;
String inString = String(255); //Sting Length of URL
Server server(80); // Set Webserver Port
void setup()
{
//Gets the Server running with Setting set above
Ethernet.begin(mac, ip, gateway, subnet); // Setup Ethernet Connection
server.begin(); // Start Server
BlinkM_beginWithPower(); // Setup BlinkM
BlinkM_stopScript( blinkm_addr ); // Set BlinkM Definition
}
// Converts Hex to RGB (a really cheap strtol(s,NULL,16))
#include <ctype.h>
uint8_t toHex(char hi, char lo)
{
uint8_t b;
hi = toupper(hi);
if( isxdigit(hi) ) {
if( hi > '9' ) hi -= 7; // software offset for A-F
hi -= 0x30; // subtract ASCII offset
b = hi<<4;
lo = toupper(lo);
if( isxdigit(lo) ) {
if( lo > '9' ) lo -= 7; // software offset for A-F
lo -= 0x30; // subtract ASCII offset
b = b + lo;
return b;
}
}
return 0;
}
void loop()
{
Client client = server.available();
if (client) {
boolean current_line_is_blank = true; // an http request ends with a blank line
inString = "";
while (client.connected()) {
if (client.available()) {
// read the first 25 characters from the URL
for(int z = 0; z < 25; z++)
{
c = client.read();
inString.append(c);
}
int PosOfE = inString.indexOf("="); // Now find where our = begins
String hexColor = String(6); // Now Read The 6 Characters
hexColor = inString.substring((PosOfE + 7), (PosOfE + 1)); //Find The Hex Color Code
int red = toHex(hexColor[0], hexColor[1]); // Find Color code for Red: ??0000
int green = toHex(hexColor[2], hexColor[3]); // Find Color code for Green: 00??00
int blue = toHex(hexColor[4], hexColor[5]); // Find Color code for Blue: 0000??
BlinkM_fadeToRGB( blinkm_addr, red, green, blue ); // Set the Color to the BlinkM
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
client.println("HTTP/1.1 200 OK"); // send a standard http response header
client.println("Content-Type: text/html"); // Content is HTML
client.println();
// Start of Custom HTML Code
client.println("<head><script src='http://techiscool.com/js/cp/script.js' type=text/javascript></script><title>Arduino Blinkm Color Picker</title></head>");
client.println("<body><center>
<table style='padding: 25px 20px 0px 16px; border:1px solid #000; background-color:96919F'><tr><td>");
client.println("<form action='index.html' method='get'>");
client.println("<input name='MyColor' id='MyColor' class='color' value='' />");
client.println("<input type='submit' value='Change Color' style='font-size:2em; width:12em' />");
client.println("</form></td></tr></table>
</center>");
client.println("<script type='text/javascript'>");
client.println("var hex = location.search.split('=');");
client.println("document.getElementById('MyColor').value = hex[1];");
client.println("document.bgColor = hex[1];");
client.println("</script></body>");
//End of Custom HTML Code
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = false;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1); // How long we wait for the Browser to Download the HTML
client.stop(); // Finished with Everything
}
Thank everyone for you time