       incoming += char(incomingByte);
     }
     
-    delay(10);
+    // give a chance for each byte to make it to the stream
+    delay(1);
   }
   
   if (incoming != "") {
-    // Serial.print(incoming);
-    if (incoming == "{\"message\":\"status\"}") {
+    if (incoming == "{\"method\":\"status\"}") {
       status();
+    } else if (incoming == "{\"method\":\"version\"}") {
+      version();
     } else { 
-      error("unknown message");
+      error("unknown method");
     }
   }
-  
+}
+
+
+void checkAllSensors() {
   for (int i=22; i<54; i++) {
-    //read the pushbutton value into a variable
-    states[i] = digitalRead(i);
-    
-    //print out the value of the pushbutton
-    if (states[i] != lastStates[i]) {
-      outputState(i, EGRESS);
-      lastStates[i] = states[i];
-    }
+    inputStatus(i, true);
   }
   
   digitalWrite(13, digitalRead(22));
-}  
-
-void outputState(int i, int type) {
-  Serial.print("{\"type\":\"");
-  Serial.print(TYPES[type]);
-  Serial.print("\",\"id\":");
-  Serial.print(i);
-  Serial.print(",\"state\":");
-  Serial.print(states[i]);
-  Serial.print(",\"millis\":");
-  Serial.print(millis());
-  Serial.println("}");
+  
+  // just a little bit of delay to debounce
+  delay(10);
 }
 
 

}


// Return an error messagse
void error(String message) {
  Serial.print("{\"error\":\"");

const String VERSION = "0.1.0";

const int EGRESS = 0;
const int MOTION = 1;
const int TRIP   = 2;
