 }
 
 void loop() {
-  if (millis() > nextSampleTime) {
-    measure_temp();
-    compensate_temp_ph();
-    measure_ph();
-    measure_orp();
-    measure_wifi();
-    nextSampleTime = millis() + SAMPLE_INTERVAL;
-    soc = lipo.getSOC();
-  }
-  if(millis() > nextSleepTime) {
-    Particle.publish("waterdata", water_data(), PRIVATE);
-    if(soc <= 10)
-      sleepInterval = 60 * 15;
-    else if(soc <= 20)
-      sleepInterval = 60 * 10;
-    else
-      sleepInterval = 60 * 5;
-    nextSleepTime = millis() + (sleepInterval * 1000) + WAKE_INTERVAL;
-    executeRequest(PH_ADDRESS,"Sleep");
-    executeRequest(ORP_ADDRESS,"Sleep");
-    digitalWrite(POWER, LOW);
-    System.sleep(SLEEP_MODE_DEEP,sleepInterval);
+  if (!calibrationmode) {
+    if (millis() > nextSampleTime) {
+      measure_temp();
+      compensate_temp_ph();
+      measure_ph();
+      measure_orp();
+      measure_wifi();
+      nextSampleTime = millis() + SAMPLE_INTERVAL;
+      soc = lipo.getSOC();
+    }
+    if(millis() > nextSleepTime) {
+      Particle.publish("waterdata", water_data(), PRIVATE);
+      if(soc <= 10)
+        sleepInterval = 60 * 15;
+      else if(soc <= 20)
+        sleepInterval = 60 * 10;
+      else
+        sleepInterval = 60 * 5;
+      nextSleepTime = millis() + (sleepInterval * 1000) + WAKE_INTERVAL;
+      executeRequest(PH_ADDRESS,"Sleep");
+      executeRequest(ORP_ADDRESS,"Sleep");
+      digitalWrite(POWER, LOW);
+      System.sleep(SLEEP_MODE_DEEP,sleepInterval);
+    }
   }
 }
 
 String water_data() {
   return String::format("{\"temperature\":%f,\"ph\":%f,\"orp\":%f,\"soc\":%f,\"wifi\":%d}",temp,ph,orp,soc,wifi);
+}
+
+int measure(String arg) {
+  ph = 0;
+  orp = 0;
+  temp = 0;
+  measure_temp();
+  measure_ph();
+  measure_orp();
+  measure_wifi();
 }
 
 void measure_ph() {

  Particle.variable("pH", ph);
  Particle.variable("ORP", orp);
  Particle.variable("soc", soc);
  Particle.function("calibratePh",calibrate_ph);
  Particle.function("calibrateORP",calibrate_orp);
  Particle.function("check",check_calibrated);
  Particle.function("slope",check_slope);
  Particle.variable("wifi",wifi);


  Wire.beginTransmission(address);
  Wire.write(cmd);
  Wire.endTransmission();
  if(cmd=="R" | cmd.startsWith("Cal"))
    delay(900);
  else
    delay(300);
  Wire.requestFrom(address, 20);
  int val=Wire.read();
  switch (val) {
    case 1:
      Serial.println("Success");
      break;
    case 2:
      Serial.println("Failed");
      return String("Failed");
      break;
    case 254:
      Serial.println("Pending");
      break;
    case 255:
      Serial.println("No Data");
      break;
    default:
      Serial.printlnf("Invalid response %d",val);
      return String("Failed");
  }

