Tag: raspberry

在这种情况下recursion是否好? (JavaScript的/的node.js)

我正尝试用树莓派制作一个电视,用javascript,一次又一次播放相同的播放列表。 播放文件不是问题,但我坚持在javascript的asynchronous部分这里的代码极其困扰我: function play (file) { exec('home/pi/play.sh', [file], function (error, stdout, stderr){ if (PIndice != Playlist.length-1){ PIndice=PIndice+1; }else{ PIndice=0; } play(Playlist[PIndice]); }); 当我确定其中有一个path名时,另一个函数用播放列表[0]调用它。 我的问题是:安全吗? 不会recursion最终会杀死CPU? 我虽然关于使用setTimeOut,但我没有find任何方式来获得video的持续时间。 我已经尝试过在循环中调用播放,但是我只是在同一时间播放整个播放列表。 我不要求一个全function的解决scheme,只是暗示我在哪里可以find一个方法来做到这一点是否有一种方法等待播放结束再次调用之前,即使JavaScript是asynchronous? 编辑:所有的文件在MPEG4,播放列表只是一个string数组,至less包含播放video文件的path名。 它应该没有互联网播放,所以没有浏览器,我不能使用HTML请求,让video的元数据得到它的持续时间。 编辑2:我忘记告诉play.sh只是启动播放器,如果没有其他实例,它只是一个以前的版本,我不知道execFile的callback

节点应用程序获取“错误:EACCES:权限被拒绝,mkdir'.tmp'

我在我的覆盆子pi上运行node-red,并试图find一个我自己编写的节点。 该节点在我的Windows PC上工作正常,但我还没有能够得到它在我的pi工作。 我的节点使用mailin来设置SMTP服务器,但我不认为这是该包的问题。 邮件试图创build一个临时文件夹,但它显然没有权限。 我如何给节点的权限,它需要能够创build此文件夹? 完整的错误: 5 Apr 20:06:22 – [info] Starting flows shell.js: internal error Error: EACCES: permission denied, mkdir '.tmp' at Error (native) at Object.fs.mkdirSync (fs.js:794:18) at mkdirSyncRecursive (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/node_modules/shelljs/src/mkdir.js:11:8) at /home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/node_modules/shelljs/src/mkdir.js:63:7 at Array.forEach (native) at Object._mkdir (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/node_modules/shelljs/src/mkdir.js:48:8) at Object.mkdir (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/node_modules/shelljs/src/common.js:186:23) at Mailin.start (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/node_modules/mailin/lib/mailin.js:73:15) at new MailinSMTP (/home/pi/.node-red/node_modules/node-red-contrib-mailin-smtp/mailinSMTP.js:15:10) at createNode (/usr/lib/node_modules/node-red/red/runtime/nodes/flows/Flow.js:276:18) at Flow.start […]

Linux杀掉我的进程内存不足,怎么看我用了多less?

继我以前的问题( 防止我的node.js应用程序被操作系统杀死 ),我已经重写了我如何下载文件的gestion。 为了使它简短,我需要下载一些video文件(testing文件是3video,MP4,〜3分钟),我一次全部下载,过程中被杀死,dmesg说(2下载完成后): Out of memory: kill process (node) score 824 or sacrifice child Killed process (node)… 所以我通过下载video一个又一个地重试,但在第二次下载,我得到完全相同的消息,我的程序被杀害。 有什么方法可以看到我的代码的哪一部分出错了,或防止Linux杀死我的进程? 顺便说一句,不是三个同时下载比一个吃了更多的内存? 那么,为什么我会一个接一个地杀人呢? 该应用程序运行在树莓派,没有GUI,raspbian,我相信是唯一的应用程序正在运行(除了系统进程) 编辑:关于function的一些细节,以及我认为现在如何工作:应用程序是在节点启动,而不是在任何浏览器。 由于一个接一个下载video,我以为会less吃点内存,但是因为我一下子下载了更多的数据,似乎是错误的,原因是停止似乎是一样的。 这里的下载function,以防万一它可以帮助: file_url的types是http://adress.com/rpi/test.mp4 function download (file_url, callback){ var option={host:url.parse(file_url).host, port:80, path:url.parse(file_url).pathname}; var file_name=url.parse(file_url).pathname.split('/').pop(); var file=fs.createWriteStream(DOWNLOAD_DIR+file_name); //Seems to crash while here: http.get(options, function(res){ res.on('data', function(data){ file.write(data); }).on('end'), function(){ file.end(); callback(DOWNLOAD_DIR+file_name); }); }); […]

Node.JS onoff没有正确拾取GPIO

我build立一个简单的红外breakbeam电路插入我的RPi 2.我有一些工作代码在python成功地拿起,当我的红外光束坏了,但我想用node.js而不是python。 这是我的Python代码,很好,很简单: import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN) try: while True: print(GPIO.input(7)) time.sleep(0.01) except KeyboardInterrupt: GPIO.cleanup() 现在我做了一些关于node.js的不同软件包的阅读,这些软件包允许我在Pi上使用GPIO,并决定onoff看起来像最好的一个,因为它与我想要使用的callbackasynchronous工作。 这是我正在尝试用于节点的代码: var Gpio = require('onoff').Gpio, infrared = new Gpio(7, 'in'); var interval = setInterval(function() { console.log(infrared.readSync() ^ 1); }, 100); function exit() { infrared.unexport(); process.exit(); } process.on('SIGINT', exit); 问题是节点我总是得到相同的0信号,不pipe我做什么。 我试图通过使用一个简单的button来消除我的电路问题,甚至不工作(我使用pythontesting了相同的电路,并且工作正常)。 这甚至不使用它的asynchronous部分(因为没有发生中断,所以它也不起作用)。 我曾尝试使用GPIOpipe理导出我正在使用的引脚: pi@counter ~ […]

覆盆子pi邻近检测nodejs

我有一个运动和接近传感器连接到树莓派。 我想要发生的事情是,当运动传感器检测到运动时,它从接近传感器获取读数以查看人的距离。一旦人进入一定的距离,就会显示一条消息。 运动传感器正在被触发,我正从接近传感器读取数据,但接近传感器陷入一个循环,数值不会更新(即使有人在其上)。 议案: import gpio from 'gpio'; import proximity from './proximity'; const gpio4 = gpio.export(4, { direction: 'in', }); // bind to the "change" event gpio4.on('change', (val) => { // value will report either 1 or 0 (number) when the value changes if (val === 1) { console.log('checking proximity'); proximity.getDistance(); } }); 接近 : […]

在节点中不可能安装包

我想安装一个树莓派3.我想安装和运行节点代码,但是在使用npm安装软件包时遇到问题。 我尝试了几个版本的节点(包括armhf最新和更旧的版本),但我总是得到以下错误(在安装槽[npm安装槽] groove@2.5.1 install /home/pi/node_modules/groove node-gyp rebuild make: Entering directory '/home/pi/node_modules/groove/build' CXX(target) Release/obj.target/groove/src/groove.o In file included from ../src/groove.cc:4:0: ../src/file.h:6:27: fatal error: groove/groove.h: Aucun fichier ou dossier de ce type #include <groove/groove.h> ^ compilation terminated. groove.target.mk:95: recipe for target 'Release/obj.target/groove/src/groove.o' failed make: *** [Release/obj.target/groove/src/groove.o] Error 1 make: Leaving directory '/home/pi/node_modules/groove/build' gyp ERR! build error gyp ERR! […]

在MongoDb聚合上出错

我一直在本地build立我的应用程序,所有工作正常,它使用最新的MongoDB 3.4和我的聚合调用工作正常。 app.get('/random_menu', function (req, res) { Menus.aggregate([{$sample: {size: 1}}], function (err, data) { res.json(data); }); }); 我现在已经把我的代码移动到了我的树莓派,它仅限于MongoDB 2.4.10,看起来我的聚合函数不能工作。 我的应用程序不返回任何数据,并没有任何错误。 为了testing,我通过RoboMongo尝试了下面这个,它在当地的3.4版本上工作正常: db.getCollection('menus').aggregate([{$sample: {size: 1}}]) 但是,当我尝试通过RoboMongo pi分贝,我得到以下错误: assert: command failed: { "errmsg" : "Pipeline::parseCommand(): unrecognized field \"cursor", "ok" : 0 } : aggregate failed _getErrorWithCode@src/mongo/shell/utils.js:23:13 doassert@src/mongo/shell/assert.js:13:14 assert.commandWorked@src/mongo/shell/assert.js:266:5 DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1215:5 @(shell):1:1 Error: command failed: { "errmsg" : "Pipeline::parseCommand(): […]

将node.js服务器应用到Web服务器

我正在学习如何使用Node.js和Web套接字来创build简单的多用户交互式JavaScript程序。 我使用Daniel Shiffman的这个系列教程来创build这个示例项目。 我的下一步是使用WinSCP将其上传到我的RaspberryPi apache2 Web服务器,但是我还没有find一种方法来编辑代码,以便使其工作,而且我不知道该用什么要执行的程序才能正常工作。 任何援助将是伟大的。 我的Node / Socket.io知识的程度完全来自上面提到的video系列,所以你可以假设我几乎不知道其他东西。

运行Meteor bundle的Raspberry Pi会抛出调用堆栈exception

我已经在Raspberry Pi上安装了Node.js,我正在试图运行Meteor.js排行榜的例子。 我已经捆绑了它,并将其复制到Pi。 我已经安装了我的MONGO_URL和NPM光纤(经过一些麻烦)。 当我尝试运行时: $ node main.js 我得到Maximum call stack size exceededexception。 /home/pi/bundle/server/server.js:143 }).run(); ^ RangeError: Maximum call stack size exceeded 我用–trace运行命令,得到这个: /home/pi/bundle/server/server.js:143 1: GetLineNumber+56(this=0x4e92928d <JS Object>, 0x26693f79 <JSMessageObject>) { 2: ScriptLocationFromPosition+64(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636, 0x4e9080a1 <true>) { 3: ScriptLineFromPosition+60(this=0x26693f25 <a Script value = 0x4e953839 <Script>>, 4636) { 4: ScriptLineCount+40(this=0x26693f25 […]

Raspberryp上的node.js]不显示任何terminal输出

我已经在我的RaspberryPi上运行Raspbian上安装了node.js sudo apt-get install nodejs npm 它看起来好像已经安装,我没有安装错误,但是当我检查版本,我没有得到任何terminal输出node -v或node –version 。 我写了一个简单的js文件,只是输出testing到控制台,当我从命令行运行node index.js ,我也没有得到任何输出在命令行。 有什么我在这里做错了吗? 是Raspbianterminal在某种程度上不同于其他平台(我无法想象它是)。 我也安装了这个post的指导(直到configuration服务器) http://blog.rueedlinger.ch/2013/03/raspberry-pi-and-nodejs-basic-setup/并得到相同的结果,在控制台中没有输出