 #include "EmonLib.h" // Include Emon Library
 #include <Average.h>
 
+extern "C" {
+#include "user_interface.h"
+}
+
 #define _IS_MY_HOME
 // WIFI
 #ifdef _IS_MY_HOME
-//#include "/usr/local/src/ap_settingii.h"
 #include "/usr/local/src/ap_setting.h"
 #else
 #include "ap_setting.h"
 #endif
+
+#define RTC_MAGIC 12345678
+
+typedef struct _tagPoint {
+  uint32 magic;
+  uint32 salt;
+} RTC_REVCOUNT;
+
+RTC_REVCOUNT rtc_mem_revcount;
 
 #define DEBUG_PRINT 0
 

      }

      if ( revMills > 600 ) {
      revValue = (float(( 3600  * 1000 ) / ( 600 * float(revMills) ) ) * 1000);
      }

      if ( oldrevValue == 0 ) {
      oldrevValue = revValue;
    }

    if ( oldrevMills == 0 ) {
      oldrevMills = revMills;
    }

    payload = "{\"VIrms\":";
              payload += average;
              payload += ",\"revValue\":";
              payload += revValue;
              payload += ",\"revMills\":";
              payload += revMills;
              payload += ",\"powerAvg\":";
              payload += (( average + revValue ) / 2) ;
              payload += ",\"Stddev\":";
              payload += ave.stddev();
              payload += ",\"calcIrmsmillis\":";
              payload += calcIrmsmillis;
              payload += ",\"revCounts\":";
              payload += revCounts;
              payload += ",\"FreeHeap\":";
              payload += ESP.getFreeHeap();
              payload += ",\"RSSI\":";
              payload += WiFi.RSSI();
              payload += ",\"millis\":";
              payload += (millis() - timemillis);
              payload += "}";

    if ( doorStatus != olddoorStatus ) {

      doorpayload = "{\"DOOR\":";

      if ( doorStatus == 0 ) {
          doorpayload += "\"CLOSED\"";
        }
        else {

    Serial.begin(115200);
  }
  delay(20);

  rtc_check();

  if (DEBUG_PRINT) {
    Serial.println("power meter test!");

