Anybody else have the iPhone app NetIO - A.K.A. NetIO Controller

I really like this application. My problem is that it works with AVR boards too, and the dev doesn't even do Arduino. I managed to take an Ard example from another user that he posted on his site and adapt it to Arduino 1.0. I was pretty stoked considering that was my second sketch ever...the first was Blink.

My project is nearing completion. I really need some help though. I have emailed back and forth with the developer for quite a while now, but because he doesn't know Arduino he can't just look at my sketch.

Two customizable attributes to the buttons and labels are called sends and reads. Sends sends a string that you can program the sketch to react to. The app requires a simple response, any will do. Reads also sends a strings, but it displays the response on a button or label.

The reads attributes in my JSON config file (thats the file you setup to design the app layout and the strings you want to send and such) display randomly. What I mean by that is the responses end up in the wrong places. For a very basic (cuz I could write a book explaining all the details I have gone through here) example - 2 labels. Both with refresh intervals of 500 milliseconds (does not matter if they are different, probelm still occurs). Reads attributes = Temp - PhotoCell. First should receive a temperature like 76F. Second should receive a number with a percentage symbol like 44%. Open the app and see = 44% & 76F. Next refresh = 76F & 44%. Next = 44% & 44%. Next = 44% & 76F. Next = [blank] & 44%. Next = 76F & OK. And so on. The OK is what I have for the response for all the strings that don't display the response, like D9H (digital 9 high, this is all configurable by the user). The OK shows if you tap a button near enough to the interval (refresh) of the reads attributes. So basically the responses go where ever the funk they want, if they even show up to class that day [blank]. /:

I know that my json config is good because the developer has gone over it with a fine tooth comb. A little insight into it, my sketch, and I'm gonna sit back and pray all you fellas can help me out here. I'm about to pull my hair out...I got my Mother's hairline (thank God) so no sense in getting a discount at the barber like my Father does. He he he [:

The app automatically appends a newline (\n I think, I'm new to this) to every type of string it sends. It apparently waits for a response before moving on and can place in its cue up to 30 strings. I went reound and round with the dev insisting that was not working properly. It seems logical considering how the responses jump all around the screen(s)/page(s) in the app. I also tried to blame it on the following characteristic. Same thing the other way. It requires a newline thing at the end, but the developer tells me that using client.println() is adequate because it automatically appends the string with just such a separator (lingo may be inaccurate, I'm a noob). So the problem must be in my sketch.

I went ahead and put the code that I think is relevant in bold. There are a ton of comments in here that are for my own personal use. There also may be code in there that require some other code...I'm not done yet. I am a total noob guys. This is my second sketch, please be gentle with me...I'm sensitive! :fearful: I'm kidding, but just that last part. I enthusiastically welcome constructive criticism...so long as its constructive.

Thanks for your time,
Joey

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

Have you tried using a (while) loop instead of an (if) that way it doesn't read bot of them and your apps refresh rate doesn't get data half way through a loop. The while loop would leave that portion of the loop till the app has read that information.