BT module help

Hey guys so here is my problem. My sketch is set to receive commands from a Bluetooth app i created with AI2. I also have a push button witch will do the same just as a backup. Everything works as advertised I just cant figure out how to get my app to reflect the current state of my device if the push button is used. For example if i turn it on with the app then off with the button my app still reflects as on. Any help would be greatly appreciated. I also attached my block setup in AI2

boolean debug = true;

#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <SoftwareSerial.h>
SoftwareSerial BTserial(0, 1); // RX | TX
// Connect the HC-06 TX to the Arduino RX.
// Connect the HC-06 RX to the Arduino TX

// max length of command is 20 chrs
const byte numChars = 20;
char receivedChars[numChars];
boolean newData = false;

// constants won't change.
const int downbutton = 2;       // downbutton to pin 2
const int upbutton = 3;         // upbutton to pin 3
const int relay1 =   7;         // relay1 to pin 7
const int relay2 =   6;         // relay2 to pin 6
const int relay3 =   5;         //   relay3 to pin 5
const int relay4 =   4;         // relay4 to pin 4
const int accpi =   8;           // car acc power in to pin 8

// variables will change:read for input values
int buttonState2 = 0;
int buttonState3 = 0;
int accps = 0;
int relay4s = 0;

void setup() {

  Serial.begin(9600);
  Serial.println("<Arduino is ready>");
  BTserial.begin(57600);

    pinMode(accpi, INPUT);
    pinMode(upbutton, INPUT);         // sets the downbutton pin as input
    pinMode(downbutton, INPUT);       // sets the downbutton pin as input
    pinMode(relay1, OUTPUT);       // sets the relay pin as output
    pinMode(relay2, OUTPUT);       // sets the relay pin as output
    pinMode(relay3, OUTPUT);       // sets the relay pin as output
    pinMode(relay4, OUTPUT);       // sets the relay pin as output
    pinMode(13, OUTPUT);           // set pin 13 as an output so we can use LED to monitor sleep status

  digitalWrite(relay1, LOW);     // Prevents relays from starting up engaged
    digitalWrite(relay2, LOW);     // Prevents relays from starting up engaged
    digitalWrite(relay3, LOW);     // Prevents relays from starting up engaged
    digitalWrite(relay4, LOW);     // Prevents relays from starting up engaged
}



void loop() {

  digitalWrite(13, HIGH);      // turn pin 13 LED on
    buttonState3  =  digitalRead(upbutton);         //   read the state of the upbutton
    buttonState2  =  digitalRead(downbutton);       //    read the state of the downbutton
  accps = digitalRead(accpi);                     //   read the state of the accps
  relay4s = digitalRead(relay4);

  if (accps == HIGH && buttonState2 == HIGH && relay4s == LOW) {
        // turn relay 3/4 on w/ relay 1 on for 16 sec:
        digitalWrite(relay3, HIGH);
        digitalWrite(relay4, HIGH);
        digitalWrite(relay1, HIGH);  
        delay(5000);
      
  }

    if (accps == HIGH && buttonState3 == HIGH && relay4s == HIGH) {
        // turn relay 3 off w/ relay 2/4 on for 16 sec then off:
        digitalWrite(relay3, LOW);
        digitalWrite(relay2, HIGH);
        delay (5000);
        digitalWrite(relay4, LOW);
      
  }

    if (accps == LOW && relay4s == HIGH) {
        // when accp is off for 3 mins turn relay 3 off w/ relay 2/4 off after 16 secs:
        delay(5000); //add0
        digitalWrite(relay3, LOW);
        digitalWrite(relay2, HIGH);
        delay(5000);
        digitalWrite(relay4, LOW);
  }

  if (buttonState2 == LOW || buttonState3 == LOW) {
    // sets relay 1/2 to off if no switches are pressed:
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, LOW);
  }



  if (BTserial.available() > 0)     {
    recvWithStartEndMarkers();
  }

  if (newData) {
    parseData();
  }

  if (accps == LOW) {
    // Stay awake for 1 second, then sleep.
    delay(1000);
    sleepNow();
  }
}


void parseData()
{
  newData = false;
  if (debug) {
    Serial.println( receivedChars );
  }
  if (receivedChars[0] == 'O'  && receivedChars[1] == 'N' && accps == HIGH && relay4s == LOW )  {
    // turn relay 3/4 on w/ relay 1 on for 16 sec:
    digitalWrite(relay3, HIGH);
    digitalWrite(relay4, HIGH);
    digitalWrite(relay1, HIGH);  
    delay(5000);
    BTserial.print("ON");
  }
  if (receivedChars[0] == 'O'  && receivedChars[1] == 'F' && accps == HIGH && relay4s == HIGH )  {
    digitalWrite(relay3, LOW);
    digitalWrite(relay2, HIGH);
    delay (5000);
    digitalWrite(relay4, LOW);
  }

}


void recvWithStartEndMarkers()
{

  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  if (BTserial.available() > 0)
  {
    rc = BTserial.read();
    if (recvInProgress == true)
    {
      if (rc != endMarker)
      {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else
      {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}

void rupt(void) {
  // just wake from sleep
}

void sleepNow(void) {
    
    // Choose our preferred sleep mode
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  // Enable interrupt
  attachInterrupt(0, rupt, HIGH);
  // pin 2
  attachInterrupt(1, rupt, HIGH);
  // pin 3

    // Set sleep enable (SE) bit:
    sleep_enable();

    digitalWrite(13, LOW);       // turn LED off to indicate sleep

    // Put the device to sleep:
    sleep_mode();

    // Upon waking up, sketch continues from this point.
    sleep_disable();
}

Using software serial on pins 0,1 is not usually a good idea.

Yea ive seen that but im stuck using them for now untill i can find a bluetooth sheild with pins that go past 7. My relay board uses 4-7 and need 2/3 for my inturrpt pins.

Perhaps I should rephrase that.

Using software serial on pins 0,1, particularly if in defiance of what you have already read, is a very stupid idea.

Do not expect results that are anything but fatal, and do not expect assistance from anybody until you have rectified this absurd situation.

One possible solution to your problem is to use pins 0,1 for hardware serial like everybody else does. Using software serial is never a very good idea at the best of times anyway, and running it at 57600 like you propose is usually fatal.

Thank you for the info. I didnt relize it would be that bad. I used a jumper and now my pins are 10/11.

I used a jumper and now my pins are 10/11.

And that resolved your problem? Great.

Well solves the issue of not blowing up my board by using pin 0/1. Still need some help with my original issue.

For example if i turn it on with the app then off with the button my app still reflects as on.

So, where, in the code that deals with the switch, do you tell the app that the switch state changed?

Thats what im unsure about . After the button code is complete would it be as easy as writing BTserial.print ("OFF") to send an off text back to the app?

After the button code is complete would it be as easy as writing BTserial.print ("OFF") to send an off text back to the app?

Isn't that what you do if the bluetooth device gets a command to turn the LED off? Try it, and see.

EvoX:
Well solves the issue of not blowing up my board by using pin 0/1.

Well perhaps I was a bit fast and loose with the word "fatal". I guess "futile" is more appropriate.