Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将输入数据从Arduino转换为HTML和日志文件?_Javascript_Html_Arduino_Johnny Five - Fatal编程技术网

Javascript 如何将输入数据从Arduino转换为HTML和日志文件?

Javascript 如何将输入数据从Arduino转换为HTML和日志文件?,javascript,html,arduino,johnny-five,Javascript,Html,Arduino,Johnny Five,我发现了一个代码,可以使用Johnny Five将数据从HTML输出到Arduino。现在,我需要您的帮助来解释,如何将输入数据从Arduino获取并保存到HTML和日志文件(可以是纯文本、xml或其他类型)。这样,我就可以处理变量了 这是我的输出数据生成器 <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></scr

我发现了一个代码,可以使用Johnny Five将数据从HTML输出到Arduino。现在,我需要您的帮助来解释,如何将输入数据从Arduino获取并保存到HTML和日志文件(可以是纯文本、xml或其他类型)。这样,我就可以处理变量了

这是我的输出数据生成器

<html>
<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  <script src="/socket.io/socket.io.js"></script>
  <script>
    $(document).ready(function() {
      var socket = io.connect('http://localhost:8080');
      $('#button').click(function(e){
        socket.emit('click');
        e.preventDefault();
      });
    });  
  </script>
</head>
<body>
  <button id="button" href="#">LED ON/OFF</button>
</body>
</html>
现在,我需要你的帮助来展示一些代码并解释它是如何工作的

var app = require('http').createServer(handler),
     io = require('socket.io').listen(app),
     fs = require('fs'),
   five = require('johnny-five');

app.listen(8080);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

board = new five.Board();

board.on("ready", function() {
  led = new five.Led(13);

  io.sockets.on('connection', function (socket) {
    socket.on('click', function () {
      led.toggle();
    });
  }); 
});