2017-01-15 5 views
3

Amazon Dash Buttonからボタンを押したときに応答するNode.jsアプリケーションでRaspberry Piを設定しました。もともとはhttps://github.com/initialstate/silent-doorbellの静かな玄関ベルであるはずでしたが、私は地元のサウンドファイルを演奏したいと思います。私は十分に簡単だと思いますが、コーディングに慣れていないので、私はインターネット上で見つけた新しいものを試しています。Node.jsを使用してRPiでローカルファイルを再生

私は次のように端末からファイルを再生することができ、それがうまく果たしている:どんなに私は時にダッシュボタンNode.jsのアプリとトリガーにそれを置くことを試みる方法

$ omxplayer example.mp3 

しかし、押しても機能しません。

var dash_button = require('node-dash-button'), 
    dash = dash_button('XX:XX:XX:XX:XX:XX'), //REPLACE WITH YOUR ADDRESS 
    exec = require('child_process').exec; 
    Omx = require('node-omxplayer'); 
    player = Omx('~/node_modules/node-dash-button/example.mp3'); 

let spawn = require('child_process').spawn; 

dash.on('detected', function() { 
    console.log('Button pushed!'); 
    player.play(); 
}); 

上記のように私の最新で実行すると、私はこの取得:@Quentinにより示唆されるように、このサイトhttp://thisdavej.com/upgrading-to-more-recent-versions-of-node-js-on-the-raspberry-pi/の指示をアップグレードメジャーバージョンを使用して、最新バージョンへのNode.jsをアップグレードした後

/home/pi/node_modules/node-dash-button/doorbell.js:7 
let spawn = require('child_process').spawn; 
    ^^^^^ 
SyntaxError: Unexpected identifier 
    at exports.runInThisContext (vm.js:73:16) 
    at Module._compile (module.js:443:25) 
    at Object.Module._extensions..js (module.js:478:10) 
    at Module.load (module.js:355:32) 
    at Function.Module._load (module.js:310:12) 
    at Function.Module.runMain (module.js:501:10) 
    at startup (node.js:129:16) 
    at node.js:814:3 

を私はこれを乗り越えることができました。今、私はomxplayerを正しく使う方法を理解できません。 Node.jsのは、アップグレードした後、上記と同様のコードを実行しているとき、私は今、次にアプリをクラッシュアマゾンダッシュボタンを押した後にこのエラーが出る:

[email protected]:~/node_modules/node-dash-button $ sudo node doorbell.js 
Button pushed! 
/home/pi/node_modules/node-omxplayer/index.js:103 
         throw new Error('Player is closed.'); 
         ^

Error: Player is closed. 
    at writeStdin (/home/pi/node_modules/node-omxplayer/index.js:103:10) 
    at EventEmitter.Omx.omxplayer.play (/home/pi/node_modules/node-omxplayer/index.js:133:27) 
    at Readable.<anonymous> (/home/pi/node_modules/node-dash-button/doorbell.js:13:12) 
    at emitOne (events.js:96:13) 
    at Readable.emit (events.js:188:7) 
    at PcapSession.<anonymous> (/home/pi/node_modules/node-dash-button/index.js:87:28) 
    at emitOne (events.js:96:13) 
    at PcapSession.emit (events.js:188:7) 
    at PcapSession.on_packet_ready (/home/pi/node_modules/node-dash-button/node_modules/pcap/pcap.js:99:10) 
    at packet_ready (/home/pi/node_modules/node-dash-button/node_modules/pcap/pcap.js:44:14) 

私はにプレーヤーを試してみて、取得するには、いくつかの異なるものを試してみました運がない状態で産卵する。参照されているindex.jsファイルは、player.runningコマンドを使用するように記述していますが、これを使用しようとすると、プレイヤーにはクローズエラーが発生します。

答えて

0

4.xシリーズより古いバージョンのノードを使用しています。

したがって、キーワードではなく識別子としてletが表示されるため、別の識別子(spawn)がすぐに続くとは限りません。

ノードの現在のバージョンへのアップグレードをアップグレードします。


varのような別の変数宣言を使用することもできます。

+0

はい、問題ありました。ありがとうございます。私はラズベリーパイの最新バージョンを利用していると思っていました。少しの研究の後、私はそれを強制しなければならないことに気付きました。だから、このサイトhttp://tisdavej.com/upgrading-to-more-recent-versions-of-node-js-on-the-raspberry-pi/をメジャーバージョンアップグレードの下で使用して、私は最新のものになることができましたバージョン。その後、私は再建しなければならず、私の現在の問題は解決されました。今、なぜomxplayerが「Error:Player is closed」を投げているのですか? – Erik

関連する問題