   setSyncProvider(getNtpTime);
   sched.every(1000,processSensors);
   sched.every(200,checkEthernet);
-  cntArr[0].last_send=now();
-  attachInterrupt(1, elmeter, CHANGE);
+  _counters=(int *) malloc(sizeof(int) * sizeof(cntArr) / sizeof(struct cnt));
+  for (int i=0;i<(sizeof(cntArr) / sizeof(struct cnt));i++) {
+    if (cntArr[i].irqno!=-1) {
+      cntArr[i].last_send=now();
+      attachInterrupt(cntArr[i].irqno,cntArr[i].irqh, CHANGE);
+    }
+  }
 }
 
 void loop()


// interrupt counter is not bound very elegantly to
// cntArr, I think about this later.
volatile unsigned int _kwCounter = 0;   // counter for the number of interrupts

IPAddress ip(192,168,1,177);
IPAddress gateway(192,168,1, 1);


  // counter build part
  for (int i=0;i<(sizeof(cntArr) / sizeof(struct cnt));i++) {
    if (cntArr[i].irqno!=-1) {
      if (cntArr[i].flags & FLAGS_DATACHANGE) {
	if (ts-cntArr[i].last_send > 30) {                   // value changed and there is more than 30 seconds after prev,
	  iot.addValue(cntAvg(i),buildTime(ts-10,prevtime)); // so this time we'll send two samples.
	}
	currval=cntArr[i].measured.analog;
	added=true;
      }
      else if (cntArr[i].flags & FLAGS_TIMEOUT) { // no big changes, only timeout
	currval=cntAvg(i);
	added=true;
      }
      if (added) {
	iot.name(cntArr[i].name);
	iot.addValue(currval,chbuf);
	iot.next();
	cntPrepareForNext(i,ts);
      }
    }
  }

