Here is part three of the " Home_Control " sketch:
else if (readString.indexOf("value_x=") > 0) //
{
if (readString.indexOf("up") > 0){ // UP button in app
string_x = "up"; // not used at this time
} // in loop() x increases every second
if (readString.indexOf("stop") > 0){ // STOP button in app
string_x = "stop"; // in loop() stop increasing x
}
if (readString.indexOf("down") > 0){ // Down button in app
string_x = "reset"; //
} // in loop() reset x to zero
Serial.print("x: "); // serial monitor prints this
Serial.println(string_x); // serial monitor fills in the value of the string_x
client.print (content_main_top); // app's turn to start printing value
client.print("x: "); // app prints X at header
client.print(string_x); // app prints the actual string value
;//client.print("<meta http-equiv=refresh content=1,url=/?status_refresh>"); // webview in the android app refresh after 1 second and calls url ip:port/status_refresh
}
else if (readString.indexOf("status_refresh") > 0){ //
Serial.print("x: "); // print the X: into the serial monitor
Serial.println(x); // print this value into the serial monitor next to X:
client.print (content_main_top); // app's turn to start printing value
client.print("x: "); // print the value x to the android app
client.print(x);
;//client.print("<meta http-equiv=refresh content=1,url=/?status_refresh>"); // ask the app to refresh every second
}
else if (readString.indexOf("value_y") > 0) // read value from the first "$" to the second "$"
{
int first_S = readString.indexOf("$"); //
String string = readString.substring(first_S + 1,(readString.indexOf("$", first_S + 1)));
Serial.print(string); //
if(string == "+"){
y++; //
}
else if(string == "-"){
y--; //
}
else{
y = string.toInt(); //
}
Serial.print("y: "); // print on serial monitor
Serial.println(y); // print value of Y
client.print (content_main_top); // print on app header
client.print("y: "); // print the value of Y
client.print(y); //
}
else if (readString.indexOf("value_z=") > 0) // read values seperated by ","
{
int comma;
String string = readString.substring((readString.indexOf("=")+1),(comma = (readString.indexOf(","))));
int a = string.toInt();
string = readString.substring((comma + 1),(comma = (readString.indexOf(",", (comma + 1)))));
int b = string.toInt();
string = readString.substring((comma + 1),(comma = (readString.indexOf(",", (comma + 1)))));
int c = string.toInt();
Serial.print("a, b, c: ");
Serial.print(a);
Serial.print(b);
Serial.println(c);
client.print (content_main_top);
client.print("a, b, c: ");
client.print(a);
client.print(b);
client.print(c);
}
/************************* Example 1 **************************/
else if (Ib == (Iq+1))
{
char carray[5];
readString.toCharArray( carray,5,(Ib+1));
Serial.println(carray);
valueB = atof(carray);
Serial.print("B is now: ");
Serial.println(valueB);
client.print (content_main_top);
client.print("B is now: ");
client.print(valueB);
}
else if (Ic == (Iq+1))
{
char carray[5];
readString.toCharArray( carray,5,(Ic+1));
Serial.println(carray);
valueC = atof(carray);
Serial.print("C is now: ");
Serial.println(valueC);
client.print (content_main_top);
client.print("C is now: ");
client.print(valueC);
}
else
{
char carray[2]; // Bob changed to 3
readString.toCharArray( carray,3,(Iq+1)); // change to 3 if 10th button added Bob Oct 14,2013
RecievedString = atoi(carray);
switch (RecievedString) {
case 1:
action(1, client);
break;
case 2:
action(2, client);
break;
case 3:
action(3, client);
break;
case 4:
action(4, client);
break;
case 5:
action(5, client);
break;
case 6:
action(6, client);
break;
case 7:
action(7, client);
break;
case 8:
action(8, client);
break;
case 9:
action(9, client);
break;
case 10:
action(10, client);
break;
case 11:
action(11, client);
break;
case 20:
action(20, client);
break;
case 21:
action(21, client);
break;
case 22:
action(22, client);
break;
case 23:
action(23, client);
break;
case 24:
action(24, client);
break;
default:
action(100, client);
break;
}
}
delay(1); //
client.stop();
readString="";
client.read();
client.read();
}
action(404, client); //no "?" found so print a 404 error
}
delay(1); //
client.stop();
readString="";
client.read();
client.read();
}