 }
 
 // read soil sensor data
-byte readSoilSensor1() {
-  unsigned int currentSoil1 = readSoilSensor(soilSensor1);
-  int soilDiff = currentSoil1 - soil1;
-  soil1 = (currentSoil1 + soil1) / 2;
-
-  if (soilDiff > 100) {
-    return 1; // indicate soil increase above threshold
-  } else if (soilDiff < 100){
-    return 2; // indicate soil decrease above threshold
-  } else {
-    return 0; // indicate normal reading
-  }
-}
-
-int readSoilSensor(int soilSensor) {
-    unsigned int val = 0;
+int readSoilSensor(int soilSensor, unsigned int &soilValue) {
+    unsigned int currentSoil = 0;
     digitalWrite(led, HIGH);
     digitalWrite(soilPower, HIGH); //turn sensor power on
     delay(10);
-    val = analogRead(soilSensor);
+    currentSoil = analogRead(soilSensor);
     digitalWrite(soilPower, LOW); //turn sensor power off
     delay(190);
     digitalWrite(led, LOW);
-    return val;
+
+    int soilDiff = currentSoil - soilValue;
+    soilValue = (currentSoil + soilValue) / 2;
+
+    if (soilDiff > 100) {
+      return 1; // indicate soil increase above threshold
+    } else if (soilDiff < 100){
+      return 2; // indicate soil decrease above threshold
+    } else {
+      return 0; // indicate normal reading
+    }
 }
 
 void dumpSerial() {

}

// read BME280 sensor data
byte readBMESensor() {
  double currentTemperature = 0;
  digitalWrite(led, HIGH);
  currentTemperature = bme.readTemperature();

Phant phant(server, publicKey, privateKey);

// interval counters for measurement and post
const int MEASUREMENT_RATE = 30000; // read sensor data every 30 sec
const int POST_RATE = 15 * 60000; // post data every 15 minutes
elapsedMillis lastMeasurement;
elapsedMillis lastPost;
