       m = BTMode;
     }
   }
+  else if (m == WaitMode) {
+    if (XBee.available()) {
+      if (XBeeReturnCount >= 1) {
+        XBeeReturnIDs[XBeeReturnCount*3-2] = ':';
+      }
+      readStringfromSerial(&XBee, message);
+      XBeeReturnIDs[XBeeReturnCount*3] = message[0];
+      XBeeReturnIDs[XBeeReturnCount*3+1] = message[1];
+      XBeeReturnCount++;
+    }
+    if (millis() - start_time > 1000) {
+      if (XBeeReturnCount > 0)
+        XBeeReturnIDs[XBeeReturnCount*3-1] = '\0';
+      else
+        XBeeReturnIDs[0] = '\0';
+      DEBUG_PRINT("IDs list:");
+      DEBUG_PRINTLN(XBeeReturnIDs);
+      DEBUG_PRINT("IDs counts:");
+      DEBUG_PRINTLN(XBeeReturnCount);
+      BT.print(XBeeReturnIDs);
+      m = BTMode;
+      BT.begin(57600);
+    }
+  }  
   delay(10);
 }
  BT.begin(57600);
  delay(300);
  m = BTMode;
  Serial.print("system begins");
}


int ledPin = 8;

struct XBeePacket XBeePacketArr[20];
char XBeeReturnIDs[20];
int XBeeReturnCount;

char message[50];
enum mode {
  BTMode,
  XBeeMode,
  WaitMode
};
mode m;
unsigned long start_time;

void setup()
{
