 int travelTime; // Total travel time in s
 int maxLogs = 255;
 String msg;
-boolean msgComplete = false;
 boolean logData = true;
 
 struct MyRec {

  
  DHT11.attach(dht11Pin);
  Serial.begin(9600);
  while (!Serial) { }
  Serial.println("Type a command");
  
  db.create(TABLE, sizeof(myrec));
  db.open(TABLE);
}

void serialEvent() {
    while (Serial.available()) {
     char recieved = Serial.read();
     msg += recieved;
     
     if (recieved == '\n') msgComplete = true;
     
     if (msgComplete) {
         if (msg == "viewData") selectAll();
         else if (msg == "stopLogging") {
             Serial.println("Stopping with logging data");
             logData = false;
         } else if (msg == "setTravelTime") setTravelTime();
     }
   }
}

void loop() {
   // put your main code here, to run repeatedly:
//   while (Serial.available() > 0) {
//     char recieved = Serial.read();
//     msg += recieved;
//     
//     if (msg == "viewData") selectAll();
//     else if (msg == "stopLogging") {
//         Serial.println("Stopping with logging data");
//         logData = false;
//     } else if (msg == "setTravelTime") setTravelTime();
//   }
  
   unsigned long currentMillis = millis();
  
   if(currentMillis - previousMillis >= logInterval && logData) {
      previousMillis = currentMillis;
      
      readDHT11();
   }
}

void selectAll() {

        avgHumidity = totalHumidity / cases;
    }
}

void calcAvgTemp() {
    int totalTemp = 0;
    int cases = 0;
    if (db.nRecs()) {
        for (int i = 1; i <= db.nRecs(); i++) {
            db.read(i, DB_REC myrec);
            totalTemp += myrec.temperature;
            cases++;
        }
        avgTemp = totalTemp / cases;
    }
}
