 }
 
 void loop() {
-  if (WiFi.status() == WL_CONNECTED) {
-    if (bdata_is_rdy) {
-      while (!digitalRead(DATA_IS_RDY_PIN)) {
+  if (WiFi.status() == WL_CONNECTED) 
+  {
+    if (bdata_is_rdy) 
+    {
+      while (!digitalRead(DATA_IS_RDY_PIN)) 
+      {
         delay(5);
       }
       ok = get_i2c_data();
-      if (sensor_data.pls_ts > 1) {
+      if (sensor_data.pls_ts > 1) 
+      {
         pls_p = (float(( 3600  * 1000 ) / ( 600 * float(sensor_data.pls_ts) ) ) * 1000);
-      } else {
+      } 
+      else 
+      {
         pls_p = 0;
       }
+      ave1.push(sensor_data.ct3_rp);
       //send_raw_data();
       sendtoInfluxdb();
       bdata_is_rdy = false;
     }
-    if (!client.connected()) {
+    if (!client.connected()) 
+    {
       syslogPayload = "failed, rc= ";
       syslogPayload += client.state();
       sendUdpSyslog(syslogPayload);
 
       unsigned long now = millis();
-      if (now - lastReconnectAttempt > 200) {
+      if (now - lastReconnectAttempt > 200) 
+      {
         lastReconnectAttempt = now;
-        if (reconnect()) {
+        if (reconnect()) 
+        {
           lastReconnectAttempt = 0;
         }
       }
-    } else {
-      if (bdoor_status != sensor_data.door) {
+    } 
+    else 
+    {
+      if (bdoor_status != sensor_data.door) 
+      {
         doorpayload = "{\"DOOR\":";
-        if ( sensor_data.door == 0 ) {
+        if ( sensor_data.door == 0 ) 
+        {
           doorpayload += "\"CLOSED\"";
         }
-        else {
+        else 
+        {
           doorpayload += "\"OPEN\"";
         }
         doorpayload += "}";

  client.loop();
}

void ICACHE_RAM_ATTR callback(char* intopic, byte* inpayload, unsigned int length) {
  String receivedtopic = intopic;
  String receivedpayload ;

  for (int i = 0; i < length; i++) {
    receivedpayload += (char)inpayload[i];
  }


  delay(100);
}

void ICACHE_RAM_ATTR sendUdpSyslog(String msgtosend) 
{
  unsigned int msg_length = msgtosend.length();
  byte* p = (byte*)malloc(msg_length);
  memcpy(p, (char*) msgtosend.c_str(), msg_length);
