       Serial.println("Overload warning !");
       Serial.println(bytes);
     }
-    
+
     *from = -1;
-    
+
     for (int i=0; i < N_PANNEL; i++)
     {
-        if (ip[i] == _udpIn.remoteIP()) { *from = i; break; }
-    }
-    
+      if (ip[i] == _udpIn.remoteIP()) { 
+        *from = i; 
+        break; 
+      }
+    }
+
     if (bytes >0) 
     {
       if (buffer[0] == '#') b.fill(buffer,bytes);

  // 
  //}

  
  _udpIn.begin(3333);
  _udpIn.listen();
  
  //pthread magic !
   pthread_t oscThread;
   pthread_create(&oscThread,NULL,osc_loop,0);
  
  //pthread magic end
  
  Serial.println("Starting WebSocket");
  initWebsocket();  
    
    
}


int getNextMessage(OSCBundle &b, int* from)
{
  
  int bytes  = _udpIn.parsePacket();
  if (bytes)
  {

// Process recieved message here.... 
//------------------------------------------------------------
void processTouch(char* in) {

  Serial.print("input: "); 
  Serial.println(in);
  if(String(in) == "trigger"){
    Serial.println("Trigger found");
    if(currentLED){
      digitalWrite(led, LOW);
      currentLED = false;
    }
    else{
      digitalWrite(led, HIGH);
      currentLED = true;
    } 
    //delay(500);
  }

}

/*
This part of the code is inspired by the stock example coming with libsockets.
 Check it for more details.
 */

int force_exit = 0;
enum lyt_protocols {
  PROTOCOL_HTTP = 0,
  PROTOCOL_LYT,
  PROTOCOL_COUNT
};


#define LOCAL_RESOURCE_PATH "/home/root/srv/"

struct serveable {
  const char *urlpath;
  const char *mimetype;
}; 

static const struct serveable whitelist[] = {
  { 
    "/favicon.ico", "image/x-icon"   }
  ,
  { 
    "/img/2s.png", "image/png"   }
  ,
  { 
    "/img/splash.png", "image/png"   }
  ,
  { 
    "/img/splash2.png", "image/png"   }
  ,
  { 
    "/img/placeholder.png", "image/png"   }
  ,
  { 
    "/img/placeholder-on.png", "image/png"   }
  ,
  { 
    "/css/phone.css", "text/css"   }
  ,
  { 
    "/js/jquery-2.0.3.min.js", "application/javascript"   }
  ,
  { 
    "/js/phone.js", "application/javascript"   }
  ,
  { 
    "/js/pixel.js", "application/javascript"   }
  ,
  { 
    "/js/pixelView.js", "application/javascript"   }
  ,
  { 
    "/js/socketController.js", "application/javascript"   }
  ,

  /* last one is the default served if no match */
  { 
    "/index.html", "text/html"   }
  ,
};

/* this protocol server (always the first one) just knows how to do HTTP */

static int callback_http(struct libwebsocket_context *context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason, void *user,
void *in, size_t len)
{
  //     Serial.println("callback_http()");
  // WE ARE ALWAYS HITTING THIS POINT

  char buf[256];
  int n;

  switch (reason) {

  case LWS_CALLBACK_HTTP:
    lwsl_notice("LWS_CALLBACK_HTTP");

    for (n = 0; n < (sizeof(whitelist) / sizeof(whitelist[0]) - 1); n++)
      if (in && strcmp((const char *)in, whitelist[n].urlpath) == 0)
        break;

    sprintf(buf, LOCAL_RESOURCE_PATH"%s", whitelist[n].urlpath);

    if (libwebsockets_serve_http_file(context, wsi, buf, whitelist[n].mimetype))
      return 1; /* through completion or error, close the socket */

    /*
		 * notice that the sending of the file completes asynchronously,
     		 * we'll get a LWS_CALLBACK_HTTP_FILE_COMPLETION callback when
     		 * it's done
     		 */

    break;

  case LWS_CALLBACK_HTTP_FILE_COMPLETION:

    lwsl_notice("LWS_FILE_COMPLETION");
    return 1;


  default:
    break;
  }

  return 0;
}

/* lyt_protocol*/
static int
callback_lyt_protocol(struct libwebsocket_context *context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason,
void *user, void *in, size_t len)
{

  //Serial.println("callback_lyt_protocol()");
  // WE ARE ALWAYS HITTING THIS POINT

  int n;
  unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 + LWS_SEND_BUFFER_POST_PADDING];
  unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];

  switch (reason) {


  case LWS_CALLBACK_SERVER_WRITEABLE:
    sensor1 = analogRead(sensor1Pin);
    n = sprintf((char *)p, "%d,%d", currentLED, sensor1);//colors);
    Serial.print("Output Message:");
    Serial.println(n);
    n = libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
    if (n < 0) {
      lwsl_err("ERROR %d writing to socket\n", n);
      return 1;
    }

    break;

  case LWS_CALLBACK_RECEIVE:

    processTouch((char*) in); 		


    break;


  default:
    break;
  }

  return 0;
}


