Here is part two of the " Home_Control " sketch:
void loop()
{
checkEthernetClient();
// Do you stuff here like;
// digitalWrite(channel, y);
// analogWrite(ledPin, blue_value );
//------------------- Function working with X from Example layout 2 of the android app --------------//
nowtime = millis(); // store the time
if (abs(nowtime - lastTime) >= 100) // if more than 100 milliseconds elapsed sinds last time (0.1 second)
{
if (string_x == "up") x++; // increase the value
if (string_x == "stop") ; // stop increasing x
if (string_x == "down") x = 0; // reset value x to zero
lastTime = nowtime; // store the time to compare next cycle
}
//------------------- **************************************************************** --------------//
}
void checkEthernetClient()
{
EthernetClient client = server.available(); // check for module connection
if (client)
{
boolean sentHeader = false; // header received
boolean currentLineIsBlank = true; // a command is being received
while (client.connected())
{
if (client.available())
{
if(!sentHeader){
client.println("HTTP/1.1 200 OK"); // appears on android app
client.println("Content-Type: text/html"); // eg.
client.println(); //
sentHeader = true; //
readString=""; //
Serial.println(); // command appears on serial monitor
}
char c = client.read();
//if (DEBUG5) Serial.write(c); // bob uncommented to see what debug is printed / needs to be defined
if(readString.indexOf('\n') < 1)
{
readString.concat(c); //
}
if (c == '\n' && currentLineIsBlank) {
//Serial.print(readString);
if (readString.indexOf("GET") >= 0){
Serial.print(readString); //
Serial.println();
int Is = readString.indexOf("/"); //
int Iq = readString.indexOf("?"); //
int Ic = readString.indexOf("c"); //
int Ib = readString.indexOf("b"); //
int IR = readString.indexOf("R"); //
int IG = readString.indexOf("G"); //
int IB = readString.indexOf("B"); //
if(readString.indexOf("?") > 1)
{
/************************* Example 2 **************************/
// All functions have diferent methods to get the value from the recieved string.
// Choose which one suits your needs
if (readString.indexOf("Blue=") > 0) // blue seekbar send value on every change while sliding over it
{
char carray[5]; // build an array to store the string containing the value
readString.toCharArray( carray,5,(readString.indexOf("=")+1)); // read the string after $ and store it in the array
valueblue = atoi(carray); // convert the Array TO Int
valueblue =map( atoi(carray),0,255,0,255);
Serial.print("BenchLight is now: "); // print this on serial monitor
Serial.println(valueblue); // print the integer value to serial
analogWrite(benchLight, valueblue); // Bob added to get bar light to dim OCT 12,2013
client.print (content_main_top); // set the background an text color of the webview in the app
client.print("BenchLight is now: "); // print this on header of android app
client.print(valueblue); // print the integer value to the android application header
}
else if (readString.indexOf("Red=") > 0) // CURIO LIGHT now working Oct 24,2013
{
char carray[5];
readString.toCharArray( carray,5,(readString.indexOf("=")+1)); // not being used at this time
valuered = atoi(carray); //
valuered =map( atoi(carray),0,255,0,255);
Serial.print("CurioLight is now: "); //
Serial.println(valuered); //
analogWrite(curioLight, valuered);
client.print (content_main_top); //
client.print("CurioLight is now: "); //
client.print(valuered); //
}
else if (readString.indexOf("Green=") > 0) // CURIO LIGHT now working Oct 24,2013
{
char carray[5];
readString.toCharArray( carray,5,(readString.indexOf("=")+1)); // not being used at this time
valuegreen = atoi(carray); //
valuegreen =map( atoi(carray),0,255,0,255);
Serial.print("BarLight is now: "); //
Serial.println(valuegreen); //
analogWrite(barLight, valuegreen);
client.print (content_main_top); //
client.print("BarLight is now: "); //
client.print(valuegreen); //
}