   float temperatureSum = tempRead / 16;
 
   return temperatureSum;
-
 }
 
-void setup(void)
-{
+void setup(void) {
+  
   Serial.begin(115200);
-
-  //  SD.begin();
-
+  
   // Configure digital output connected to rtc module.
   pinMode(RTC_POWER_PIN, OUTPUT);
-
-  // Configure digital output connected to sensor.
-  pinMode(TEMP_POWER_PIN, OUTPUT);
-
-  // turn on power to the rtc module
   digitalWrite(RTC_POWER_PIN, HIGH);
-  delay(100); // TODO necessary?
-
   Wire.begin(); // I2C init as master
   RTC.begin();
-
-  // Turn off power to the rtc module.
   digitalWrite(RTC_POWER_PIN, LOW);
 
-  // Turn off power to the sensor.
-  digitalWrite(TEMP_POWER_PIN, LOW);
-
-  // Setup the watchdog timer to run an interrupt which
-  // wakes the Arduino from sleep every 8 seconds.
-
-  // Note that the default behavior of resetting the Arduino
-  // with the watchdog will be disabled.
-
-  // This next section of code is timing critical, so interrupts are disabled.
-  // See more details of how to change the watchdog in the ATmega328P datasheet
-  // around page 50, Watchdog Timer.
-  noInterrupts();
-
-  // Set the watchdog reset bit in the MCU status register to 0.
-  MCUSR &= ~(1 << WDRF);
-
-  // Set WDCE and WDE bits in the watchdog control register.
-  WDTCSR |= (1 << WDCE) | (1 << WDE);
-
-  // Set watchdog clock prescaler bits to a value of 8 seconds.
-  WDTCSR = (1 << WDP0) | (1 << WDP3);
-
-  // Enable watchdog as interrupt only (no reset).
-  WDTCSR |= (1 << WDIE);
-
-  // Enable interrupts again.
-  interrupts();
-
+  pinMode(10, OUTPUT);
+  pinMode(SD_CARD_SELECT, OUTPUT);
+  SD.begin(SD_CARD_SELECT);
+  
   Serial.println(F("Setup complete."));
 }
 
-void loop(void)
-{
-  // Don't do anything unless the watchdog timer interrupt has fired.
-  if (watchdogActivated)
-  {
-    watchdogActivated = false;
-    // Increase the count of sleep iterations and take a sensor
-    // reading once the max number of iterations has been hit.
-    sleepIterations += 1;
-    if (sleepIterations >= MAX_SLEEP_ITERATIONS) {
-      // Reset the number of sleep iterations.
-      sleepIterations = 0;
+void loop(void) {
+  
+  // Log the sensor reading
+  logSensorReading();
 
-      delay(ADDITIONAL_SLEEP * 1000);
-
-      // Log the sensor reading
-      logSensorReading();
-    }
-  }
-
-  // Go to sleep!
-  sleep();
+  Sleepy::loseSomeTime(LOGGING_FREQ_SECONDS * 1000);
 }
 

  delay(100);
}

float getTemp() {
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

#include <JeeLib.h>

#include <Wire.h>
#include <RTC_DS3231.h>

#include <OneWire.h> // update at http://www.pjrc.com/teensy/arduino_libraries/OneWire.zip

#include <SPI.h>
#include <SD.h>

#define LOGGING_FREQ_SECONDS   10

#define RTC_POWER_PIN          A3
RTC_DS3231 RTC;

#define TEMP_SIGNAL_PIN        8
OneWire ds(TEMP_SIGNAL_PIN);

#define SD_CARD_SELECT         9
String stationId;

// Define watchdog timer interrupt.
ISR(WDT_vect) { Sleepy::watchdogEvent(); }

// Take a sensor reading and send it to the server.
void logSensorReading() {
  
  DateTime now = getTime();
  float temperature = getTemp();
  
  File file;
  if (file = SD.open("data.txt", FILE_WRITE)) {
    file.print(now.year(), DEC);
    file.print('-');
    file.print(now.month(), DEC);
    file.print('-');
    file.print(now.day(), DEC);
    file.print('T');
    file.print(now.hour(), DEC);
    file.print(':');
    file.print(now.minute(), DEC);
    file.print(':');
    file.print(now.second(), DEC);
    file.print('Z');
    file.print('\t');
    file.println(temperature, 3);
    file.close(); 
  }

  // Connect to the server and send the reading.
  Serial.print(now.year(), DEC);
  Serial.print('-');
  Serial.print(now.month(), DEC);
