【发布时间】:2018-03-10 10:56:03
【问题描述】:
这是我的代码
var webSocketUrl = "wss://api.artik.cloud/v1.1/websocket?ack=true";
var device_id = "########################"; // DEVICE ID
var device_token = "#####################"; // DEVICE TOKEN
// require websocket module to connect
// execute following two commands to your pi's terminal
// sudo apt-get update
// npm install websocket
var WebSocket = require('ws');
var isWebSocketReady = false;
var data="";
var ws = null;
// require serialport module to raspberry pi
// execute following command to terminal
// npm install serialport
var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var sp = new SerialPort("/dev/ttyACM0", { //for serial communication with
arduino
baudrate: 9600,
// we are using UNO so baudrate is 9600, you might need to change according
to your model
parser: serialport.parsers.readline("\n")
});
但是在我运行这个之后,我得到了一个这样的错误
/home/pi/parking.js:21
parser: serialport.parsers.readline("\n")
^
TypeError: serialport.parsers.readline is not a function
at Object.<anonymous> (/home/pi/rainbow-parking.js:21:32)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
任何人都可以帮助我解决这个问题。我尝试了很多。我这个问题是我的 nodejs 和 npm 版本问题。但不确定。
【问题讨论】:
标签: node.js npm arduino raspberry-pi serial-port