我有这个代码用于从我的Arduino接收数据,但我想将数据发送回我的Arduino并在我的客户端页面上获得响应.我添加了一个监听功能,但是io.on is not a function当我从客户端页面发送数据时,我一直在收听.
test.js
io.listen(app.listen(3000)).on('connection', function (client) {
// store client into array
clients.push(client);
// on disconnect
client.on('disconnect', function() {
// remove client from array
clients.splice(clients.indexOf(client), 1);
});
// I added this to listen for event from my chart.JS
io.on('connection', function(socket){
socket.on('LED on', function (data) {
console.log(data);
});
socket.on('LED off', function (data) {
console.log(data);
});
});
});
Run Code Online (Sandbox Code Playgroud)