我在Rasberry pi 3上使用npm v2.14.7运行Node v4.2.1。该项目是一个在javascript上运行的浏览器控制的节点js机器人。
我收到此错误:
Express server listening on port 3000
/home/pi/rover/node_modules/async/dist/async.js:228
return supportsSymbol && fn[Symbol.toStringTag] === 'AsyncFunction';
其次是:
TypeError: Cannot read property 'undefined' of undefined
at isAsync (/home/pi/rover/node_modules/async/dist/async.js:228:32)
at wrapAsync (/home/pi/rover/node_modules/async/dist/async.js:232:12)
at /home/pi/rover/node_modules/async/dist/async.js:3866:9
at eachOfArrayLike (/home/pi/rover/node_modules/async/dist/async.js:1055:9)
at eachOf (/home/pi/rover/node_modules/async/dist/async.js:1103:5)
at _parallel (/home/pi/rover/node_modules/async/dist/async.js:3865:5)
at Object.parallelLimit [as parallel] (/home/pi/rover/node_modules/async/dist/async.js:3948:5)
at Object.tank.moveForward (/home/pi/rover/app.js:46:11)
at Socket.<anonymous> (/home/pi/rover/app.js:87:14)
at emitOne (events.js:77:13)
代码大约5年,所以我很确定代码需要更新。
App.js代码:
var express = require('express'),
http = require('http'),
path = require('path'),
async = require('async'),
gpio = require('pi-gpio'),
app = express();
//set the port
app.set('port', process.env.PORT || 3000);
//serve static files from /static directory
app.use(express.static(path.join(__dirname, '/static')));
//create the server
var http = http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
//init socket.io
var io = require('socket.io')(http);
//the actual tank code starts here
//----------------------------------
//create the tank object
var tank = {
//assign pin numbers to variables for later use
motors: {
leftFront: 11,
leftBack: 12,
rightFront: 15,
rightBack: 16
},
//open the gpio pins and set them as outputs
init: function(){
gpio.open(this.motors.leftFront, "output");
gpio.open(this.motors.leftBack, "output");
gpio.open(this.motors.rightFront, "output");
gpio.open(this.motors.rightBack, "output");
},
//for moving forward we power both motors
moveForward: function(){
async.parallel([
gpio.write(this.motors.leftFront, 1),
gpio.write(this.motors.rightFront, 1)
]);
},
//for moving backward we power both motors but in backward mode
moveBackward: function(){
async.parallel([
gpio.write(this.motors.leftBack, 1),
gpio.write(this.motors.rightBack, 1)
]);
},
//for turning right we power the left motor
moveLeft: function(){
gpio.write(this.motors.leftFront, 1);
},
//for turning left we power the right motor
moveRight: function(){
gpio.write(this.motors.rightFront, 1)
},
//stop both motors in all directions
stop: function(){
async.parallel([
gpio.write(this.motors.leftFront, 0),
gpio.write(this.motors.leftBack, 0),
gpio.write(this.motors.rightFront, 0),
gpio.write(this.motors.rightBack, 0)
]);
}
};
//listen for socket connection
io.sockets.on('connection', function(socket) {
//listen for move signal
socket.on('move', function(direction) {
switch(direction){
case 'up':
tank.moveForward();
break;
case 'down':
tank.moveBackward();
break;
case 'left':
tank.moveLeft();
break;
case 'right':
tank.moveRight();
break;
}
});
//listen for stop signal
socket.on('stop', function(dir){
tank.stop();
});
});
tank.init();