Here is my sketch. Had to remove all non-essential parts because its too long.
It wouldn't make the one part bold so I took that out.
Thanks again!
//------------------------------------------------------------------BEGINNING void setup()
void setup(){
pinMode(ceilingLight, OUTPUT);
pinMode(lamp, OUTPUT);
pinMode(siren, OUTPUT);
pinMode(toneSpeaker, OUTPUT);
//PIN 4 RESERVED - SD Card - HOPE TO IMPLEMENT A FILE SERVER SOON! :]
pinMode(5, OUTPUT);
pinMode(squareLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(irLEDs, OUTPUT);
// PINS 10, 11, 12, 13 RESERVED FOR ETHERNET SHIELD. I know, I know...I should have typed <int ethernetShieldPins[5] = {10, 11, 12, 13;}> My first programming Joke. HA? Pfff, Nah. [:
pinMode(pirSensor, INPUT);
pinMode(15, INPUT); //make analog later
//pinMode(16, INPUT);
//pinMode(17, INPUT);
pinMode(18, INPUT); //TEMPORARY, WILL BE ANALOG
Ethernet.begin(mac, ip);
iPhoneAppServer.begin(); // start the server
Serial.begin(115200); //for debug
}
//--------------------------------------------------------------------------------END void setup()
//--------------------------------------------------------------------------------BEGINNING void loop()
void loop()
{
int index = 0;
char Remote[BUFSIZ]; // Remote -> Buffer which holds string received from iPhone App or other client.
EthernetClient client = iPhoneAppServer.available();
//Remainder of server code INCLUDING STRINGS Tx/Rx & ACTIONS COMMANDED are at the end of loop()
if(SysStatus == armed)
{
if(digitalRead(18) == HIGH && PhCStatus == armed && PhCMsgSent == false)
{
smtp();
PhCStatus = breached;
PhCMsgSent = true;
digitalWrite(siren, HIGH);
delay(1500);
digitalWrite(siren, LOW);
}
if(digitalRead(pirSensor) == HIGH && PIRStatus == armed && PIRMsgSent == false)
{
smtp();
PIRStatus = breached;
PIRMsgSent = true;
digitalWrite(siren, HIGH);
delay(1500);
digitalWrite(siren, LOW);
}
}
//--------------------------------------------------------------BEGINNING of if(client)
if (client) {
if (client.connected()) {//--------------------BEGINNING of if(client.connected)
while (client.available()) {
char c = client.read();
Serial.print(c); // Print string data received from iPhone App to the serial monitor.
if (c != '\n' && c != '\r'){ // This just means that the Arduino has not received a linefeed or a carriage return, so we have it keep reading the incoming string.
Remote[index] = c;
delay(3);
index++;
if (index >= BUFSIZ) index = BUFSIZ -1;
continue;
}
Remote[index] = 0;
}
if (strstr(Remote, "NetIO Requesting Link")) { // Initial send from App
client.println("OK");
}
//................ABOVE STRINGS ARE Tx/Rx OF INITIAL SEND.........................
//............BEG CORE OF SEND RECEIVE ACTIONS AND RESPONSES......................
//................NetIO requires response to all strings (or it may crash, dev->"3 second timeout")..........
//###########Home page of Net IO################
if (strcmp (Remote, "PhC") == 0)
{
client.println(analogRead(A4)); //Change to <var name> when PhotoCell is hooked up, light measurements taken, and analogRead mapped to <var name>
}else client.println("Fuck Knows\n");
if (strstr(Remote, "Temp"))
{
client.println("Farenheit 76.4"); //When temp sensor arrives, change to change to display temperature nice
}
//###########Alarm page of Net IO###############
//SYSTEM
if (strstr(Remote, "SysStatus"))
{
if (SysStatus == disarmed) client.println("System is not Active");
if (SysStatus == armed) client.println("System is Active");
if (SysStatus == breached) client.println("BREACH");
}
if (strstr(Remote, "ToggleSys"))
{
client.println("OK");
if (SysStatus == disarmed) SysStatus = armed;
if (SysStatus == armed) SysStatus = disarmed;
if (SysStatus == breached) SysStatus = disarmed;
}
if (strstr(Remote, "ResetSys"))
{
client.println("OK");
PhCMsgSent = false;
PIRMsgSent = false;
// IRMsgSent = false;
// LNMsgSent = false;
SysStatus = disarmed;
}
//PHOTOCELL
if (strstr(Remote, "PhCStatus"))
{
if (PhCStatus == disarmed) client.println("Light detection is not Active");
if (PhCStatus == armed) client.println("Light detection is Active"); // "(...)All Clear(...)" ???
if (PhCStatus == breached) client.println("BREACH");
}
if (strstr(Remote, "TogglePhC"))
{
client.println("OK");
if (PhCStatus == disarmed) PhCStatus = armed;
if (PhCStatus == armed) PhCStatus = disarmed;
if (PhCStatus == breached) PhCStatus = disarmed;
}
if (strstr(Remote, "ResetPhC"))
{
client.println("OK");
PhCMsgSent = false;
PhCStatus = disarmed;
}
//PASSIVE INFRARED
if (strstr(Remote, "PIRStatus"))
{
if (PIRStatus == disarmed) client.println("Motion detection is Disarmed");
if (PIRStatus == armed) client.println("Motion detection is Armed"); // "(...)All Clear(...)" ???
if (PIRStatus == breached) client.println("BREACH: Motion has been detected");
}
if (strstr(Remote, "TogglePIR"))
{
client.println("OK");
if (PIRStatus == disarmed) PIRStatus = armed;
if (PIRStatus == armed) PIRStatus = disarmed;
if (PIRStatus == breached) PIRStatus = disarmed;
}
if (strstr(Remote, "ResetPIR"))
{
client.println("OK");
PIRMsgSent = false;
PIRStatus = disarmed;
}
// DIGITAL WRITE COMMANDS BY PORT # FOR "LAB" PAGE. [15 PORTS - 0 to 14 (Apr12,12)]
if (strstr(Remote, "D0H")) {
client.println("OK");
digitalWrite(0, HIGH);
}
if (strstr(Remote, "D0L")) {
client.println("OK");
digitalWrite(0, LOW);
}
if (strstr(Remote, "D1H")) {
client.println("OK");
digitalWrite(1, HIGH);
}
if (strstr(Remote, "D1L")) {
client.println("OK");
digitalWrite(1, LOW);
}
if (strstr(Remote, "D2H")) {
client.println("OK");
digitalWrite(2, HIGH);
}
if (strstr(Remote, "D2L")) {
client.println("OK");
digitalWrite(2, LOW);
}
if (strstr(Remote, "D3H")) {
client.println("OK");
digitalWrite(3, HIGH);
}
if (strstr(Remote, "D3L")) {
client.println("OK");
digitalWrite(3, LOW);
}
if (strstr(Remote, "D5H")) {
client.println("OK");
digitalWrite(5, HIGH);
}
if (strstr(Remote, "D5L")) {
client.println("OK");
digitalWrite(5, LOW);
}
if (strstr(Remote, "D6H")) {
client.println("OK");
digitalWrite(6, HIGH);
}
if (strstr(Remote, "D6L")) {
client.println("OK");
digitalWrite(6, LOW);
}
if (strstr(Remote, "D7H")) {
client.println("OK");
digitalWrite(7, HIGH);
}
if (strstr(Remote, "D7L")) {
client.println("OK");
digitalWrite(7, LOW);
}
if (strstr(Remote, "D8H")) {
client.println("OK");
digitalWrite(8, HIGH);
}
if (strstr(Remote, "D8L")) {
client.println("OK");
digitalWrite(8, LOW);
}
if (strcmp (Remote, "D9H") == 0) {
client.println("OK");
digitalWrite(9, HIGH);
}
if (strstr(Remote, "D9L")) {
client.println("OK");
digitalWrite(9, LOW);
}
if (strstr(Remote, "D14H")) {
client.println("OK");
digitalWrite(14, HIGH);
}
if (strstr(Remote, "D14L")) {
client.println("OK");
digitalWrite(14, LOW);
}
} //-------------------------------------------END of if(client.connected)
} //--------------------------------------------------------- END of if(client)
} //-----------------------------------------------------------------------------END of void loop()
//@@@@@@@@@@@@@@@@@@@@ BEG of emailFunction() @@@@@@@@@@@@@@@@@@@@@@
/*removed this because it was full of my personal info and I'm too tired to edit it line by line*/
}
//@@@@@@@@@@@@@@@@@@@@ END of emailFunction() @@@@@@@@@@@@@@@@@@@@@@
// END OF SKETCH
// fin
// the end
// go home
// ok, you can stay
// no need to cry
// I said stop crying
// want a lollie?
// ok, here's a lollie (*thought=what, am I british now?) {*thought=syntax error. expected '{' token after you gave me a lollie}
// note to self...staying up all night coding is bad for one's psyche
// at least I spelled psyche correctly, I checked