 	// Start up the serial communication.
 	// Find out why this cuts off the next serial print.
 	Serial.begin(115200);
-        
+
 	for(int i = 0; i < 3; i++)
 		Serial.print(F("==============="));
 

	Serial.println(sensor_data.temperature_f);
	Serial.print(F("Sensor light reading: "));
	Serial.println(sensor_data.light);
  Serial.print(F("Sensor pressure reading: "));
  Serial.println(sensor_data.pressure);

  // Make our heartbeat LED blink at a normal rate again if we were panicking earlier
  // or it was shut off.
  Heartbeat::start();

  // try to send 5 times, if 5 fail restart the module
  for(int i = 0; i < 5; i++){
    Serial.print("Trying to send data: ");
    Serial.println(i);
    
    if(!network.send_packet(sensor_data)){
      if(i == 2){   
        // something went wrong with the connection - try to reconnect
        // Startup our network.
        while (!network.init_wireless(SSID, password)){
          Serial.println(F("Failed connecting to wireless network, retying in 3 seconds."));
          Heartbeat::panic();
          delay(3000);
        }
        delay(3000);
        
        // start panic mode
        Heartbeat::panic();
      }
    }
    else{
      // Make our heartbeat LED blink at a normal rate again if we were panicking earlier.
      Heartbeat::start();
      break;
    }
  }
  
	Serial.println(F("Waiting 1 min... - sleep time"));
  delay(60000); // wait

  // kill the led before taking measurements
  Heartbeat::stop();
  
}

// disable watchdog interrupt
ISR(WDT_vect){
  // disable the watchdog
  wdt_disable();
}

void EnableWatchDog(const byte time_to_sleep){
  MCUSR = 0;                         
  WDTCSR |= 0b00011000;              
  WDTCSR =  0b01000000 | time_to_sleep;   

  wdt_reset();
  set_sleep_mode (SLEEP_MODE_PWR_DOWN); 
  // sleep until we are interrupted
  sleep_mode();           
}


#include "TimerOne.h"
#include "SparkFunMPL3115A2.h"

// Global because arduno says we need setup and loop functions.
Network network;
Sensors sensors;

// Defines for our wifi credentials.
#define SSID "OpenWrt"
#define password "castle2004"

