LoginSignup
5
3

More than 5 years have passed since last update.

node-red-contrib-usbhid がRaspberryPiでうまく入らないときの対処法

Posted at

Node-RED Advent Calendar 2016の19日目の記事です。

littleBits MAKEY MAKEYモジュールをNode-REDで読み取る に関連した記事です。

最近、RaspberryPiを使っていてnode-red-contrib-usbhid がRaspberryPiでうまく入らないときの対処法です。

すべての方に当てはまるわけではないと思いますが、ご参考までに。

すでに行っていること

sudo apt-get update
sudo apt-get upgrade

および

パッケージマネージャを利用した Node.js のインストール | Node.js

を参考にNode.jsをバージョン4の最新版に対応済み。

それなのになんだかうまく行かない状況。

RaspberryPi OSバージョン

RaspberryPi OSバージョンは以下の通り。

lsb_release -a

を実行して。

No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 8.0 (jessie)
Release:    8.0
Codename:   jessie

追加で色々インストール

以前、node-hidのインストールでハマったことを思い出して以下記事を参考に対応しました。

node.js - npm fail to install node-hid (faild to install last version of Nodejs) - Stack Overflow

すでに最新版だったりインストール済みだったりするものだけど念のためやったもの。

sudo apt-get install g++ curl
sudo apt-get install build-essential
sudo apt-get install pkg-config
sudo apt-get install libudev-dev
sudo apt-get install git-core

コマンド打ったら、更新なり、インストールが走ったもの。

sudo apt-get install libssl-dev apache2-utils
sudo npm install node-gyp -g
sudo apt-get install libusb-1.0-0-dev

治りました

以下のエラー内容を見るかぎり、sudo npm install node-gyp -g sudo apt-get install libusb-1.0-0-dev が原因としてかなり怪しいが、ひとまず記事に従って全インストールしたら、うまく治りました。

image

エラー内容

参考までにエラー内容も置いておきます。

node-pre-gyp ERR! Tried to download(404): https://github.com/node-hid/node-hid/releases/download/0.5.2/HID-v0.5.2-node-v46-linux-arm.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for node-hid@0.5.2 and node@4.7.0 (node-v46 ABI) (falling back to source compile with node-gyp) 
make: Entering directory '/home/pi/node_modules/node-hid/build'
  CC(target) Release/obj.target/hidapi/hidapi/libusb/hid.o
../hidapi/libusb/hid.c:47:20: fatal error: libusb.h: No such file or directory
 #include <libusb.h>
                    ^
compilation terminated.
hidapi.target.mk:96: recipe for target 'Release/obj.target/hidapi/hidapi/libusb/hid.o' failed
make: *** [Release/obj.target/hidapi/hidapi/libusb/hid.o] Error 1
make: Leaving directory '/home/pi/node_modules/node-hid/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:12)
gyp ERR! System Linux 4.1.19-v7+
gyp ERR! command "/usr/bin/nodejs" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/home/pi/node_modules/node-hid/build/HID/Release/HID.node" "--module_name=HID" "--module_path=/home/pi/node_modules/node-hid/build/HID/Release"
gyp ERR! cwd /home/pi/node_modules/node-hid
gyp ERR! node -v v4.7.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/bin/nodejs /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/pi/node_modules/node-hid/build/HID/Release/HID.node --module_name=HID --module_path=/home/pi/node_modules/node-hid/build/HID/Release' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/pi/node_modules/node-hid/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:854:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:222:5)
node-pre-gyp ERR! System Linux 4.1.19-v7+
node-pre-gyp ERR! command "/usr/bin/nodejs" "/home/pi/node_modules/node-hid/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/pi/node_modules/node-hid
node-pre-gyp ERR! node -v v4.7.0
node-pre-gyp ERR! node-pre-gyp -v v0.6.31
node-pre-gyp ERR! not ok 
Failed to execute '/usr/bin/nodejs /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/pi/node_modules/node-hid/build/HID/Release/HID.node --module_name=HID --module_path=/home/pi/node_modules/node-hid/build/HID/Release' (1)
npm WARN enoent ENOENT: no such file or directory, open '/home/pi/package.json'
npm WARN pi No description
npm WARN pi No repository field.
npm WARN pi No README data
npm WARN pi No license field.
npm ERR! Linux 4.1.19-v7+
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "i" "node-red-contrib-usbhid"
npm ERR! node v4.7.0
npm ERR! npm  v4.0.5
npm ERR! code ELIFECYCLE

npm ERR! node-hid@0.5.2 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-hid@0.5.2 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-hid package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-hid
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls node-hid
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/pi/npm-debug.log

node-pre-gypのPre-built binariesのTried to download(404)エラーはライブラリ入れると結構よく出てヒヤヒヤしますね。

node-pre-gyp ERR! Tried to download(404): https://github.com/node-hid/node-hid/releases/download/0.5.2/HID-v0.5.2-node-v46-linux-arm.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for node-hid@0.5.2 and node@4.7.0 (node-v46 ABI) (falling back to source compile with node-gyp) 

実際は

 #include <libusb.h>
                    ^
compilation terminated.
hidapi.target.mk:96: recipe for target 'Release/obj.target/hidapi/hidapi/libusb/hid.o' failed

あたりから、ズッコケています。

原因が特定できないまま、範囲広めの対処方法をやってみたという流れですが、よろしければご参考下さい。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3