   }
 }
 
-
 bool checkButton( int buttonIndex ) {
     if(digitalRead( buttonPin[buttonIndex] ) == (buttonPullup[buttonIndex]?LOW:HIGH)) {
         if(buttonThresCounter[buttonIndex] < BUTTON_THRES)

}

void setup() {

  Serial.begin(115200);
  delay(10);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  for(int i=0; i<sizeof(message); i++) {
    message[i]=0; // init
  }
  initAllButtons();

  pinMode(STATUS_LED, OUTPUT);

  WiFi.hostByName(DESTINATION_HOST, serverIP); // resolve name

  // init header
  init_header();
}

void send() {
  // Serial.println("sending UDP packet...");
  // build package
  byte *msg = message + BUFFER_HEADER_SIZE;
  for( int i=0; i<buttonsAllocated; i++ ) {
    *msg = buttonLastState[i]?2:1;
    msg ++;
    *msg = buttonCode[i];
    msg ++;
  }   // TODO eventually check overflow

  udp.beginPacket(serverIP, DESTINATION_PORT);
  udp.write(message, BUFFER_HEADER_SIZE + buttonsAllocated*2);
  udp.endPacket();
}

void loop() {

#include "ulno_esp_utils.h"
#include "libni.h"

const char* ssid     = "iotempire";
const char* password = "internetofthings";
const char * DESTINATION_HOST = "192.168.23.175";
const int MY_ID = 2;

const int MAX_NUMBER_OF_BUTTONS = 16;
const int BUTTON_THRES = 16; // how many times has an on be counted to assume this button is on
//const int STATUS_LED = 2;
