       }
 
       if (((millis() - sentMills) > REPORT_INTERVAL ) && ( irStatus == oldirStatus )) {
-        sendmqttMsg(topic, payload);
+      sendmqttMsg(topic, payload);
         sentMills = millis();
       }
 
       if ( irStatus != oldirStatus ) {
-        sendmqttMsg(topic, payload);
+      sendmqttMsg(topic, payload);
         sentMills = millis();
         oldirStatus = irStatus ;
         oldrevValue = revValue ;

        average = ave.mean();
      }

      //if ( revMills > 600 ) {
      if ( irStatus == oldirStatus ) {
        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 {


  if (( millis() - startMills ) < 600 ) {
    return;
  }
  if (( millis() - startMills ) < ( revMills / 4 )) {
    return;
  } else {
    revMills   = (millis() - startMills)  ;
    startMills = millis();
