 
   // If we haven't updated in 5 minutes, send along a "PING" to keep showing something.
   if (now > lastWebUpdateTime + 300000 || now < lastWebUpdateTime) {
+    //strcpy(eagle_data, "0.05  120.0  110.0  12.0  159.0  100.0  110.0  ON  OFF  ");
+    //updateWeb();
+
     data_index = 0;
     eagle_data[data_index] = '\0';
     updateWeb();
   }
+}
 
-  if (data_port.available()) {
-    char c = data_port.read();
+
+void serialEvent() {
+  while (Serial.available()) {
+    char c = Serial.read();
     if (c) UDR0 = c;
 
     // Assume a LF is the end of the line
     if (c == '\n' && strlen(eagle_data) > 0) {
       // Update once per minute
       // Also, don't send any Eagle header messages we come across.
+      unsigned long now = millis();
+
       if ((now > lastWebUpdateTime + 60000 || now < lastWebUpdateTime) && strncmp(eagle_data, "RUNTIME", 7) != 0) {
         updateWeb();
       }

#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

#define IDLE_TIMEOUT_MS  3000

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIVIDER);
Adafruit_CC3000_Client client;

SoftwareSerial data_port(6, 7);
unsigned long lastWebUpdateTime = 0;
char eagle_data[81];
uint8_t data_index = 0;


void setup () {
  Serial.begin(115200);
  Serial.println(F("\nWater Heater Monitor"));

  // CC3000 setup
  Serial.print(F("initializing network... "));
  if (!cc3000.begin()) {
    Serial.println(F("unable to initialise the CC3000! Check your wiring?"));
    while(1);
  }
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {

    }

    client.close();
    lastWebUpdateTime = millis();
    Serial.println(F("Done."));
  } else {
    Serial.println(F("Web server connection failed."));
  }
}
