     Serial.print("Heat index: ");
     Serial.print(hic);
     Serial.print(" *C ");
-    
+
+    //setup wifi
+    //in loop to re init connection if necessary
+    setupWifi();
+
     postData(t, h, hic);    
   } else {
+    Serial.println();
     Serial.println("Failed to read from DHT sensor!");
   }
 
-     // Wait a few seconds between measurements.
-  delay(30000);
+  Serial.println("Total uptime: " + String(millis() - startTime));
+
+  // deep sleep between measurements.
+  // for lower power consumptions
+  Serial.println("Going to deep sleep for " + String(thingSpeakUpdateInterval / (1000 * 1000)) + " sec.");
+  //Need to connect GPIO16 to RST otherwise deep sleep will not work
+  ESP.deepSleep(thingSpeakUpdateInterval, WAKE_RF_DEFAULT);
 }
+
+
+
+
+


//wifi client
WiFiClient client;
//byte lastClientStatus = WL_DISCONNECTED;
//#define deepSleepTime 120000000 //2 minutes
//#define wakeTime 120000 //2 minutes 

// === wifi section
void setupWifi() {

  if (!isnan(h) && !isnan(t)) {
    // Compute heat index in Celsius (isFahreheit = false)
    float hic = dht.computeHeatIndex(t, h, false);

    Serial.println();
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
