 }
 
 void doWork() {
+  if (connectToInternet()) {
+    String subject =  "Device ";
+    subject =  subject + ESP.getChipId();
+    subject =  subject + " is DO WORK!!!. Count: ";
+    subject =  subject + rtcStore[2];
+    String message =  "Battery Power: ";
+    message = message + ESP.getVcc();
+    sendEmail(subject, message);
+    disconnectInternet();
+  }
+
   digitalWrite(14, HIGH);
   delay(1000);
   yield();

uint32_t doCalculation() {
  uint32_t nextSleep = TEN_MIN_TIME;

  int timeInSecs = ss;
  timeInSecs = timeInSecs + (mm * 60);
  timeInSecs = timeInSecs + (hh * 60 * 60);
  
  if(){
  }

  
  return nextSleep;
}


    system_rtc_mem_write(RTC_BASE, rtcStore, 3);
  }

  switch (rtcStore[1]) {
    case STATE_COLDSTART:
      if (connectToInternet()) {
        getTime();
        nextSleep = doCalculation();

        String subject =  "Device ";
        subject =  subject + ESP.getChipId();
        subject =  subject + " has Powered up.";
        String message =  "Battery Power: ";
        message = message + ESP.getVcc();
        message = message + " Power Up Time: " + hh + ":" + mm + ":" + ss;
        message = message + " Count: ";
        message = message + rtcStore[2];

        if (ESP.getVcc() < 2650) {
          subject = "WARNING: Battery LOW - " + subject;
        }

        Serial.println(subject);
        Serial.println(message);

        sendEmail(subject, message);
        disconnectInternet();
        rtcStore[1] = STATE_SLEEP_WAKE;
        system_rtc_mem_write(RTC_BASE, rtcStore, 3);
      }
      break;
    case STATE_SLEEP_WAKE:
      if (rtcStore[2] < 72) {
        doWork();
      } else {
        if (connectToInternet()) {
          String subject =  "Device ";
          subject = subject + ESP.getChipId();
          subject = subject + " is Just wake up for Count!!!. Count: ";
          subject = subject + rtcStore[2];
          String message =  "Battery Power: ";
          message = message + ESP.getVcc();
          sendEmail(subject, message);
          disconnectInternet();
        }

      }
      if (rtcStore[2] >= 83) {
        rtcStore[1] = STATE_HOUSKEEPING;
        system_rtc_mem_write(RTC_BASE, rtcStore, 3);
        nextSleep = ONE_HOU_TIME - TEN_MIN_TIME;
        ESP.deepSleep(nextSleep, WAKE_RFCAL);
      }
      break;
    case STATE_HOUSKEEPING:
      if (connectToInternet()) {
        getTime();
        nextSleep = doCalculation();
        String subject =  "Device ";
        subject =  subject + ESP.getChipId();
        subject =  subject + " Syncronizing with time.";
        String message =  "Battery Power: ";
        message = message + ESP.getVcc();
        message = message + " Power Up Time: " + hh + ":" + mm + ":" + ss;

        if (ESP.getVcc() < 2650) {
          subject = "WARNING: Battery LOW - " + subject;
        }
        Serial.println(subject);
        Serial.println(message);
        sendEmail(subject, message);
        disconnectInternet();
        rtcStore[1] = STATE_SLEEP_WAKE;
        system_rtc_mem_write(RTC_BASE, rtcStore, 3);
      }
      break;
  }

  rtcStore[2]++;
