   Wire.endTransmission();
 }
 
-
 int configInterval(String interval) // Particle function for data publishing interval
 {
-    if (interval == "10S")        // if function call = 10 seconds
+    if (interval == "10S")          // if function call = 10 seconds
     {
       DataInterval = TenSec;
       return 10;
     }
-    else if (interval == "1M")    // if function call = 1 minute
+    else if (interval == "1M")      // if function call = 1 minute
     {
       DataInterval = OneMin;
       return 60;
     }
-    else if (interval == "5M")    // if function call = 5 minutes
+    else if (interval == "5M")      // if function call = 5 minutes
     {
       DataInterval = FiveMin;
       return 300;
     }
-    else if (interval == "10M")   // if function call = 10 minutes
+    else if (interval == "10M")     // if function call = 10 minutes
     {
       DataInterval = TenMin;
       return 600;
     }
-    else if (interval == "15M")   // if function call = 10 minutes
+    else if (interval == "15M")     // if function call = 10 minutes
     {
       DataInterval = FifteenMin;
       return 900;
     }
     else return -1;
 
-    int addr = 10;              // define EEPROM data structure
+    int addr = 10;                  // define EEPROM data structure
     struct nvmobject
     {
       uint16_t verifyEE;

  EEPROM.get(addr, nvmobj);       // read EEPROM data
  if (nvmobj.verifyEE == 0xaa55)  // if the verification value is true
  {
    DataInterval = nvmobj.interval;
  }
  else { DataInterval = OneMin;}
}

void loop()
{
  RoomTemp = ht1.getRoomTmp();   // read and calculate room temp 1
  Thermocouple = ht1.getThmc();  // read and calculate thermocouple temp 1
  SwitchMux(0x01);                  // switch to i2c mux input 1
  ReadAccelerometer(GAccI2C);       // read the accelerometer
  event = "Pump1Acc1";
  PublishData();                    // publish data to Particle cloud
//  for(int j = 0; j < 8; j++){A1data[j] = Adata[j];}  // copy data
  SwitchMux(0x02);                  // switch to i2c mux input 2
  ReadAccelerometer(GAccI2C);       // read the accelerometer
  event = "Pump1Acc2";
  PublishData();                    // publish data to Particle cloud
//  for(int j = 0; j < 8; j++){A2data[j] = Adata[j];} // copy data
  RoomTemp = ht2.getRoomTmp();   // read and calculate room temp 2
  Thermocouple = ht2.getThmc();  // read and calculate thermocouple temp 2
  SwitchMux(0x04);                  // switch to i2c mux input 1
  ReadAccelerometer(GAccI2C);       // read the accelerometer
  event = "Pump2Acc3";
  PublishData();                    // publish data to Particle cloud
//  for(int j = 0; j < 8; j++){A3data[j] = Adata[j];}  // copy data
  SwitchMux(0x08);                  // switch to i2c mux input 1
  ReadAccelerometer(GAccI2C);       // read the accelerometer
  event = "Pump2Acc4";
  PublishData();                    // publish data to Particle cloud
//  for(int j = 0; j < 8; j++){A4data[j] = Adata[j];}  // copy data
//  ReadPressure(PS1I2C);             // read pressure sensor
//  Pressure1 = Pressure;             // copy pressure data
//  PTemp1 = PTemp;                   // copy temperature data
  delay(DataInterval);          // wait interval, then repeat main loop
}

int configAcc(String command)     // Particle function for accelerometer calibration
{
    if (command == "calibrate")   // if function call = "calibrate"
    {
      Acal1 = A1data[1];          // set calilbration values to amplitude 1
      Acal2 = A2data[1];
      Acal3 = A3data[1];
      Acal4 = A4data[1];

      int addr = 10;              // define EEPROM data structure
      struct nvmobject
      {
        uint16_t verifyEE;
        int Acal1;
        int Acal2;
        int Acal3;
        int Acal4;
      };

      nvmobject nvmobj = { 0xaa55, Acal1, Acal2, Acal3, Acal4};
      EEPROM.put(addr, nvmobj);     // write values to the EEPROM
      return 1;
    }
    else if (command == "reset")    // if function call = "reset"
    {
      Acal1 = 0;                    // set calibration values to zero
      Acal2 = 0;
      Acal3 = 0;
      Acal4 = 0;
      int addr = 10;
      uint16_t verifyEE = 0;
      EEPROM.write(addr, verifyEE); // reset EEPROM verification value
      return 0;
    }
    else return -1;
}

void ReadAccelerometer(int i2c_address)   // function to read/average accelerometer values

  // calculate amplitude by summing the squares, divide vectors by 100 to keep number manageable
      Adata[f] += (xdata[i]*xdata[i])/100 + (ydata[i]*ydata[i])/100 + (zdata[i]*zdata[i])/100;
    }
    Adata[f] = sqrt(Adata[f]);          // Amplitude = squareroot of sum of the squares
  }
}

