  * Listens for serial data from an IMC Eagle solar water heater controller and
  * uploads it to a waiting server.
  *
- * Assumes an CC3000-based wireless network connectiom shield and serial connection
- * via SoftwareSerial on pins 6 and 7.
+ * Assumes an CC3000-based wireless network connectiom shield and serial
+ * connection to athe Eagle controller via hardware serial.
  */
 
 #include <Adafruit_CC3000.h>
+#include "utility/debug.h"
 #include <SPI.h>
-#include <SoftwareSerial.h>
 
 #include "keys.h"
 

#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)) {

  Serial.println(F("wireless connection successful."));

  while (!cc3000.checkDHCP()) {
    delay(100);
  }

  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  if (!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv)) {
    Serial.println(F("Unable to retrieve network info!"));
  } else {
    Serial.print(F("  IP Addr: ")); cc3000.printIPdotsRev(ipAddress); Serial.println();
  }

  initThermometer();

  Serial.println(F("Waiting for data..."));
}
