       
       readDHT11();
    }
-  //selectAll();
 }
 
 void selectAll() {

    
      db.append(DB_REC myrec);
}


// Variables to use for the interval
unsigned long previousMillis = 0;
long logInterval = 2000;

// Variables
dht11 DHT11;
DB db;
int travelTime; // Total travel time in s
int maxLogs = 255;
String msg;
boolean msgComplete = false;
boolean logData = true;

struct MyRec {
  int humidity;
  double temperature;
} myrec;

int avgHumidity;
int avgTemp;

void setup() {
  // Initialize pins
  pinMode(ledPin, OUTPUT);
  
  if (logInterval == 0) logData = false;
  
  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();
  
