"use strict";
var PORT = 4200;
var path = require('path');

//to control iRobot create2
var fs = require("fs");
var Repl = require("repl");
const five = require('johnny-five');

var Devices = require("../src/detect");

const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);

/*Devices.getArduinoComName().then(function (port) {
  board = new five.Board({
    "repl": false,
    port: port
  });
  board.on("ready", boardHandler);
  board.on("fail", function (event) {
    console.error(event);
  });
});*/
var board = null;
var led = null;

Devices.getArduinoComName().then(function (port) {
  console.log("hello arduino board");
  board = new five.Board({
    "repl": false,
    port: port
  });
  board.on("ready", boardHandler(led));
  board.on("fail", function (event) {
    console.error(event);
  });
});

app.get('/', function (req, res) {
  res.sendFile(path.join(__dirname, '../client/index.html'));
});

app.use("/", express.static(path.join(__dirname, '../client')));
app.use("/assets", express.static(path.join(__dirname, '../client/assets')));
http.listen(PORT, function () {
  console.log('Listen on ', PORT);
});

function boardHandler(l) {
  console.log("Board ready, lets add light");
  console.log(l);
  l = new five.Led(11);
  console.log("hey led");
  l.on();
  console.log("initial led on");
};

io.sockets.on('connection', function(socket) {
  console.log("hello socket");
  socket.on('ledStatus', function(status) {
    if (status) {
      console.log("Led on!!!");
      led.on();
    } else {
      console.log("Led off...");
      led.stop().off();
    }
  });
});

@@ -353,16 +353,51 @@
 http);%0A%0A
+var board = null;%0Avar led = null;%0A%0A
 /*Device
@@ -441,16 +441,54 @@
 port) %7B%0A
+  console.log(%22hello arduino board%22);%0A
   board 
@@ -578,16 +578,21 @@
 dHandler
+(led)
 );%0A  boa
@@ -665,42 +665,8 @@
 );*/
-%0Avar board = null;%0Avar led = null;
 %0A%0ADe
@@ -839,36 +839,219 @@
 ready%22, 
-boardHandler(led));%0A
+function () %7B%0A    console.log(%22Board ready, lets add light%22);%0A    //console.log(five);%0A    led = new five.Led(11);%0A    console.log(%22hey led%22);%0A    led.on();%0A    console.log(%22initial led on%22);  %0A    %7D;%0A  
   board.
@@ -1076,32 +1076,34 @@
 n (event) %7B%0A    
+  
 console.error(ev
@@ -1100,32 +1100,34 @@
 e.error(event);%0A
+  
   %7D);%0A%7D);%0A%0Aapp.g
@@ -1461,16 +1461,18 @@
 andler(l
+ed
 ) %7B%0A  co
@@ -1531,15 +1531,20 @@
 log(
-l
+five
 );%0A  l
+ed
  = n
@@ -1586,19 +1586,21 @@
  led%22);%0A
-
   l
+ed
 .on();%0A 

edit debug-led-blink