 
   //  RTCが初期化されていないならWifiに接続してsntpで時刻を取得
   rtc.setup(0x20);
-  if (rtc.isPowerOn()) {
+  if (rtc.isPowerOn() || storage.uni.datas.nextAdjust == 0) {
     Serial.println("RTC is not initilized");
     startWifi();
-    time_t forRTC = getTimestamp();
-    rtc.writeRTC(&forRTC);
-    Serial.println(forRTC);
+    adjustRTCwithSNTP();
   } else {
     Serial.println("RTC is already initalized");
   }

      Serial.println("alloc fail!");
    }
  }
  
  JsonObject& root = jsonBuffer.createObject();
  root["writeKey"] = ambient_write_key_ESP_BME280_To_Ambient;    // ambientのapi write key



  ESP.deepSleep(kInterval * 1000 * 1000, WAKE_RF_DEFAULT);
  delay(1000);
}


void adjustRTCwithSNTP() {
  Serial.println("getting sntp");
  
  time_t sntpTime = getTimestamp(); //sntp

  time_t rtcTime;
  rtc.readRTC(&rtcTime);
  
  Serial.print("rtc - sntp = ");
  Serial.println(rtcTime - sntpTime);
  
  rtc.writeRTC(&sntpTime);

  Serial.println("new adjust timing has been set");
  storage.uni.datas.nextAdjust = rtcTime + 24 * 3600 * 1000;  // 1day later
}


