   #endif
 
   #ifdef TRANSMITTER_GSM
-//    wdt_enable(WDTO_8S);
+//    Watchdog.enable(8000);
   #endif
 }
 


#ifdef TRANSMITTER_GSM
  void transmit(float temperature_f, float humidity, float heat_index, uint32_t current_time) {
//    // POST example based on:
//    // https://github.com/adafruit/Adafruit_FONA/blob/d3d047bf9c47f4f4a2151525d48b5c044daba2e3/Adafruit_FONA.cpp#L1622
//
//    connect_to_fona();
//
//    if (!fona.enableGPRS(true)) {
//      Serial.println(F("Failed to turn on"));
//      while(true);
//    }
//
//    uint16_t statuscode;
//    int16_t length;
//    char *url = "requestb.in/1bl66u81";
//    char *data = "test1=true&test2=false&float=123.3";
//    
//    if (!fona.HTTP_POST_start(url, F("text/plain"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) {
//      Serial.println("Failed!");
//      while(true);
//    }
//
//    if (statuscode != 200) {
//      Serial.println("status not 200!");
//    }
//
//    fona.HTTP_POST_end();
  }

//  void connect_to_fona() {
//    fonaSerial->begin(4800);
//    if (! fona.begin(*fonaSerial)) {
//      Serial.println(F("Couldn't find FONA"));
//      while(true); // watchdog will reboot
//    }
//  }
#endif 

#ifdef TRANSMITTER_WIFI

  float heat_index;

  uint32_t current_time = rtc.now().unixtime();
  Serial.print("current_time: ");
  Serial.println(current_time);
//  uint32_t last_reading_time = get_last_reading_time();

//  if (current_time - last_reading_time < READING_INTERVAL_S) {
//    Serial.print("waiting to take next reading... time since last reading: ");
//    Serial.print(current_time - last_reading_time);
//    Serial.print(", current_time: ");
//    Serial.print(current_time);
//    Serial.print(", last_reading_time: ");
//    Serial.print(last_reading_time);
//    Serial.print(", reading_interval: ");
//    Serial.println(60000);
//    delay(1000);
//    return;
//  } else {
//    
//  }
  
  read_temperatures(&temperature_f, &humidity, &heat_index);
  log_to_sd(temperature_f, humidity, heat_index, current_time);
  update_last_reading_time(current_time);
  watchdog_feed();
  
  transmit(temperature_f, humidity, heat_index, current_time);

  watchdog_feed();

  delay(2000);
}

void read_temperatures(float *temperature_f, float *humidity, float *heat_index) {
  while (true) {
    bool success = true;

    *temperature_f = dht.readTemperature(true);
    *humidity = dht.readHumidity();
    
    if (!isnan(*temperature_f) && !isnan(*humidity)) {  
      *heat_index = dht.computeHeatIndex(*temperature_f, *humidity);
  
      Serial.print("Temperature: ");
      Serial.print(*temperature_f);
      Serial.println(" *F");
      
      Serial.print("Humidity: ");
      Serial.print(*humidity);
      Serial.println("%");
      
      Serial.print("Heat index: ");
      Serial.println(*heat_index);

      return;
      
    } else {
      Serial.println("Error reading temperatures!");
    }
  
    delay(2000);

    // if we continue to fail to read a temperature, the watchdog will
    // eventually cause a reboot
  }
}

void log_to_sd(float temperature_f, float humidity, float heat_index, uint32_t current_time) {
  Serial.println("writing to SD card...");
  
  if (data_file.open("data.csv", O_CREAT | O_APPEND | O_WRITE)) {
    data_file.print(current_time); data_file.print(",");
    data_file.print(temperature_f); data_file.print(",");
    data_file.print(humidity); data_file.print(",");
