   sendOne();
   sendZero();
   sendZero();
-  sendZero();*/ 
-  delay(2000);   
+  sendZero();
+  */
+  //
+  //fopen("/tmp/robocmd","r");
+  //sendCommand(0x8E); //0x88 high5 0x8E fart
+  int maxfsize=500;
+  
+  system("curl https://blazing-fire-1158.firebaseio.com/robosapien.json > /tmp/robocmd.txt");
+  char *cmdStr = (char*)malloc(maxfsize + 1);
+  FILE *lockFile = fopen("/tmp/robolock", "r");
+  if(!lockFile)
+  {
+    FILE *cmdFile = fopen("/tmp/robocmd.txt", "rb");
+    if(cmdFile)
+    {
+      fseek(cmdFile, 0, SEEK_END);
+      long fsize = ftell(cmdFile);
+      if(fsize<3)
+      {
+        fclose(cmdFile);
+        Serial.println("File length too short. Size in bytes is: ");
+        Serial.println(fsize);
+      }
+      else
+      {
+        fseek(cmdFile, 1, SEEK_SET); //avoid leading quote
+    
+        fread(cmdStr, fsize, 1, cmdFile);
+        fclose(cmdFile);
+    
+        cmdStr[fsize] = 0;
+        cmdStr[fsize-1] = 0; //delete trailing quote
+        
+        int cmdInt=atoi(cmdStr);
+        
+        Serial.println("Command Number");
+        Serial.println(cmdInt);
+        if(cmdInt)
+        {
+          Serial.println("Executing Command");
+          sendCommand(cmdInt); //0x88 high5 0x8E fart
+          Serial.println("Command Executed, erasing command from firebase");
+          system("curl -X PUT -d '\"0\"' https://blazing-fire-1158.firebaseio.com/robosapien.json");
+          Serial.println("Command erased");
+        }
+      }
+    }
+  }
 }

 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
const int led = 2; //using external LED

const int boardLED=13;

// the loop routine runs over and over again forever:
void loop() {            // wait for a second
  //digitalWrite(led, HIGH);  
  //
  /*
  sendHeader();
  //wave is 0x88
