 ApplicationWatchdog wd(180000, System.reset);
 
 DS18B20 ds18b20(TEMP_SENSOR);
-int nextSampleTime, nextSleepTime, sleepInterval;
+unsigned int nextSampleTime, nextSleepTime, sleepInterval;
 
 double temp = 0;
 double ph = 0;

  Wire.beginTransmission(address);
  Wire.write(cmd);
  Wire.endTransmission();
  if(cmd=="R" | cmd.startsWith("Cal"))
    delay(900);
  else
    delay(300);

  Particle.variable("pH", ph);
  Particle.variable("ORP", orp);
  Particle.variable("soc", soc);
  Particle.variable("calibrating", calibrationmode);
  Particle.variable("temponly", temponly);
  Particle.function("switchcalmode", switchcalibrationmode);
  Particle.function("switchtemponly", switchtemponly);
  Particle.function("calibratePH", calibrate_ph);
  Particle.function("calibrateORP", calibrate_orp);
  Particle.function("check", check_calibrated);
  Particle.function("slope", check_slope);
  Particle.variable("wifi", wifi);

  nextSleepTime = millis() + WAKE_INTERVAL;
  //Serial.begin(9600);
}

void loop() {
  // Always measure every sample time interval
  if (millis() > nextSampleTime) {
      measure_temp();
      if(temponly == 0) {
        compensate_temp_ph();
        measure_ph();
        measure_orp();
      }
      measure_wifi();
      nextSampleTime = millis() + SAMPLE_INTERVAL;
      soc = lipo.getSOC();
  }

  // Publish results before going to sleep
  if(millis() > nextSleepTime) {
    Particle.publish("pooldata", water_data(), PRIVATE);
    // Only go to sleep when not in calibration mode
    if (!calibrationmode) {
      if(soc <= 10)
        sleepInterval = 60 * 60;
      else if(soc <= 20)
