   struct dig2a delta;
 };
 
-/*
+
 struct cnt {
-  int *counter;
+  unsigned int counter;
   char *name;
   int flags;
-  int last_send;
+  time_t last_send;
+  long avg_counter;
+  int avg_samples;
   struct dig2a prev;
+  struct dig2a prevsnd;
   struct dig2a diff;
+  struct dig2a diff_factor;
   struct dig2a scale;
   struct dig2a measured;
 };
-*/
+
 
 struct ad adArr[]= {          //prev   dif    min       max         meas    delta
   {0,"boiler",       0,0,     0,0.0, 0,0.5, 174,21.0, 935, 100.0,  0,0.0,  0,0.0},

  setSyncProvider(getNtpTime);
  sched.every(1000,processAD);
  sched.every(200,checkEthernet);
  attachInterrupt(1, elmeter, CHANGE);
}


      ats[m2xpos]=chbuf;
      streamNames[m2xpos]=ad[chan].name;
      m2xpos++;
      samplecnt++;
    }
  }

  // counter build part
  timeout=(ts-cntArr[0].last_send > measTimeout);
  float diff=abs(cntArr[0].measured.analog-cntArr[0].prevsnd.analog);
  bool changed;
  float average;
  float limit;

  limit =  cntArr[0].diff.analog * (1.0 + cntArr[0].measured.analog * cntArr[0].diff_factor.analog);
  changed=(diff > limit);
  if (changed) {
    if (ts-cntArr[0].last_send > 30) {
      if (cntArr[0].avg_samples > 3) {
	average=(cntArr[0].avg_counter / cntArr[0].avg_samples) / (cntArr[0].scale.digital * cntArr[0].scale.analog); 
	values[m2xpos]=average;
      }
      else
	values[m2xpos]=cntArr[0].prev.analog;
      values[m2xpos+1]=cntArr[0].measured.analog;
      counts[m2xpos]=2;
      buildTime(ts-10,prevtime);
      samplecnt=m2xpos;
      ats[m2xpos]=prevtime;
      ats[m2xpos+1]=chbuf;
      samplecnt=m2xpos+1;
      streamNames[m2xpos]=cntArr[0].name;
      cntArr[0].last_send=ts;
      cntArr[0].prevsnd.analog=cntArr[0].measured.analog;
      cntArr[0].avg_samples=0;
      cntArr[0].avg_counter=0;
      m2xpos++;
      samplecnt++;
    }
    else {
      values[m2xpos]=cntArr[0].measured.analog;
      counts[m2xpos]=1;
      ats[m2xpos]=chbuf;
      streamNames[m2xpos]=cntArr[0].name;
      cntArr[0].last_send=ts;
      cntArr[0].prevsnd.analog=cntArr[0].measured.analog;
      cntArr[0].avg_samples=0;
      cntArr[0].avg_counter=0;
      m2xpos++;
      samplecnt=m2xpos;
    }
  }
  else if (timeout) {
    values[m2xpos]=cntArr[0].measured.analog;
    counts[m2xpos]=1;
    ats[m2xpos]=chbuf;
    streamNames[m2xpos]=cntArr[0].name;
    cntArr[0].last_send=ts;
    cntArr[0].prevsnd.analog=cntArr[0].measured.analog;
    cntArr[0].avg_samples=0;
    cntArr[0].avg_counter=0;
    m2xpos++;
    samplecnt=m2xpos;
  }
  // send part
  if (m2xpos) {
    if (feedId[0]==0) {
      Serial.println("feed id not known");
