       iot.name(ad[chan].name);
       iot.addValue(ad[chan].measured.analog,chbuf);
       iot.next();
-      sendingad=true;
     }
   }
 
   // counter build part
-  if (sendingad) // if already sending ad values, add counters a bit earlier to same packet
-    timeout=(ts-cntArr[0].last_send > measTimeout-300);
-  else
-    timeout=(ts-cntArr[0].last_send > measTimeout);
-  float diff=abs(cntArr[0].measured.analog-cntArr[0].prevsnd.analog);
-  bool changed;
-  float limit;
-  float val;
-
-  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) {
-        // calculate average from previous samples
-	val=(cntArr[0].avg_counter / cntArr[0].avg_samples) / (cntArr[0].scale.digital * cntArr[0].scale.analog);
+  for (int i=0;i<(sizeof(cntArr) / sizeof(struct cnt));i++) {
+    if (cntArr[i].flags & FLAGS_DATACHANGE) {
+      if (ts-cntArr[i].last_send > 30) { // value changed and there is more than 30 seconds after prev
+	if (cntArr[i].avg_samples > 3) {
+	  // calculate average from previous samples
+	  val=(cntArr[i].avg_counter / cntArr[i].avg_samples) / (cntArr[i].scale.digital * cntArr[i].scale.analog);
+	}
+	else
+	  val=cntArr[i].prev.analog;
+
+	buildTime(ts-10,prevtime);
+	iot.name(cntArr[i].name);
+	iot.addValue(val,prevtime);
+	iot.addValue(cntArr[i].measured.analog,chbuf);
+	iot.next();
+	cntPrepareForNext(i,ts);
       }
-      else
-	val=cntArr[0].prev.analog;
-
-      buildTime(ts-10,prevtime);
-      iot.name(cntArr[0].name);
-      iot.addValue(val,prevtime);
-      iot.addValue(cntArr[0].measured.analog,chbuf);
+      else { // value changed quicly after prev
+	iot.name(cntArr[i].name);
+	iot.addValue(cntArr[i].measured.analog,chbuf);
+	iot.next();
+	cntPrepareForNext(i,ts);
+      }
+    }
+    else if (cntArr[i].flags & FLAGS_TIMEOUT) { // no big changes, only timeout
+      val=(cntArr[i].avg_counter / cntArr[i].avg_samples) / (cntArr[i].scale.digital * cntArr[i].scale.analog);
+      iot.name(cntArr[i].name);
+      iot.addValue(val,chbuf);
       iot.next();
-      cntPrepareForNext(0,ts);
-     }
-    else {
-      iot.name(cntArr[0].name);
-      iot.addValue(cntArr[0].measured.analog,chbuf);
-      iot.next();
-      cntPrepareForNext(0,ts);
-    }
-  }
-  else if (timeout) {
-    val=(cntArr[0].avg_counter / cntArr[0].avg_samples) / (cntArr[0].scale.digital * cntArr[0].scale.analog); 
-    iot.name(cntArr[0].name);
-    iot.addValue(val,chbuf);
-    iot.next();
-    cntPrepareForNext(0,ts);
+      cntPrepareForNext(i,ts);
+    }
   }
 
 

{
  static int cnt=0;
  boolean timeouts=false;
  boolean changes=false;
  time_t ts=now();
  int chcnt=(sizeof(adArr) / sizeof(struct ad));


#define AD_SAMPLECNT 10
#define FLAGS_DATACHANGE 0x01
#define FLAGS_TIMEOUT 0x02

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// mx2 credentials are stored with a tcpip config connection
