   case CONNECTED:
 
     // temporarily for debugging 
+    digitalWrite(ledStatusPin, HIGH);
     delay(10000);
     state = IDLE;
     break;

      	Serial.println("[CONNECTED] entering state");

      	// turn on the ligth to indicate
      	digitalWrite(ledPin, HIGH);

      	state = CONNECTED;
      }

}

int readXBeeString (char *strArray) {
  Serial.print("start read XBee: ");
  int i = 0;
  if(!XBee.available()) {
    return -1;
    // delay(100);
  }
  while (XBee.available()) {
    strArray[i] = XBee.read();
    i++;
  }
  strArray[i] = '\0';
  Serial.print("read XBee: ");
  Serial.println(strArray);
  return i;
  
  
  // sendMsg(XBeeInString);
}

void readXBeeDeviceId() {
  delay(1000);

  memset(XBeeInString, 0, 50);
  Serial.println("sending +++");
  XBee.print("+++");
  delay(3000);
  // Serial.println("reading...");
  readXBeeString(XBeeInString);
  // Serial.println(XBeeInString);
  
  delay(1000);
  
  memset(XBeeInString, 0, 50);
  Serial.println("sending ATMY");
  XBee.print("ATMY\r");
  delay(3000);
  readXBeeString(XBeeInString);

  // deviceId = XBeeInString[];
  int id = atoi(XBeeInString);
  // string_copy(deviceId, XBeeInString, 0, 1);

  if(id<10) { //append 0 at beginning
    Serial.println("id<10");
    deviceId[0] = '0';
    char a[2];
    itoa(id, a, 10);
    deviceId[1] = a[0];
  } else {
    itoa(id, deviceId, 10);  
  }
  
  Serial.print("my devide ID: ");
  Serial.println(deviceId);  
}
