kelly / node-i2c

Node.js native bindings for i2c-dev. Plays well with Raspberry Pi and Beaglebone.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

npm install i2c failed

goog opened this issue · comments

pi@raspberrypi:~ $ sudo npm install -g --unsafe-perm i2c

> i2c@0.2.1 install /usr/local/lib/node_modules/i2c
> node-gyp rebuild

make: Entering directory '/usr/local/lib/node_modules/i2c/build'
  CXX(target) Release/obj.target/i2c/src/i2c.o
../src/i2c.cc: In function ‘void ReadBlock(const v8::FunctionCallbackInfo<v8::Value>&)’:
../src/i2c.cc:162:47: error: no matching function for call to ‘New(int32_t&)’
   Local<Object> buffer = node::Buffer::New(len);
                                               ^
../src/i2c.cc:162:47: note: candidates are:
In file included from ../src/i2c.cc:2:0:
/root/.node-gyp/4.2.1/include/node/node_buffer.h:28:40: note: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, size_t)
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
                                        ^
/root/.node-gyp/4.2.1/include/node/node_buffer.h:28:40: note:   candidate expects 2 arguments, 1 provided
/root/.node-gyp/4.2.1/include/node/node_buffer.h:31:40: note: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, v8::Local<v8::String>, node::encoding)
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                        ^
/root/.node-gyp/4.2.1/include/node/node_buffer.h:31:40: note:   candidate expects 3 arguments, 1 provided
/root/.node-gyp/4.2.1/include/node/node_buffer.h:36:40: note: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, char*, size_t, node::Buffer::FreeCallback, void*)
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                        ^
/root/.node-gyp/4.2.1/include/node/node_buffer.h:36:40: note:   candidate expects 5 arguments, 1 provided
/root/.node-gyp/4.2.1/include/node/node_buffer.h:43:40: note: v8::MaybeLocal<v8::Object> node::Buffer::New(v8::Isolate*, char*, size_t)
 NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                        ^
/root/.node-gyp/4.2.1/include/node/node_buffer.h:43:40: note:   candidate expects 3 arguments, 1 provided
i2c.target.mk:86: recipe for target 'Release/obj.target/i2c/src/i2c.o' failed
make: *** [Release/obj.target/i2c/src/i2c.o] Error 1
make: Leaving directory '/usr/local/lib/node_modules/i2c/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/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:200:12)
gyp ERR! System Linux 4.1.19-v7+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/i2c
gyp ERR! node -v v4.2.1
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok 
npm ERR! Linux 4.1.19-v7+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "--unsafe-perm" "i2c"
npm ERR! node v4.2.1
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE

npm ERR! i2c@0.2.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the i2c@0.2.1 install script 'node-gyp rebuild'.
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 i2c package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs i2c
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls i2c
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

I have the same problem on node v4.2.1 and npm v2.14.7.

commented

+1

commented

+1

+1

I ran to same problem and then gave rasp2c a try.
worked very well.

Thanks @doorbash, but I don't like, that it forks a new process for every setting using the cli tools. A real alternative could be i2c-bus . However, I implemented the crucial parts in C now and passing the results back to node later.

For anyone having this issue on the Raspberry Pi. It's an incompatibility between the I2C package and newer versions of Node.js. As a workaround you can install Node.js version 0.12.6 (which still works with the library) from here - http://node-arm.herokuapp.com/node_archive_armhf.deb

If the author doesn't fix this soon I'll fork it and get it running for Node >= 4.x as this package is starting to look abandoned...

@alphacharlie -- Please do!!!

@alphacharlie Oh Charlie, please do :-)

commented

A fix would be appreciated, there's quite a few projects that depend on i2c and are now broken.

I forked the code off and updated it to use 'nan' for buffer creation. Will someone please try this and let me know how it works for them? https://github.com/alphacharlie/node-i2c

(Otherwise I'll have to put some hardware together to test it myself. Probably take a few days for me to get to it...)

For any developers who wish to test you would need to clone the repo into your project and install it manually. This would look something like-

cd ~
mkdir tmp
cd tmp
git clone [https://github.com/alphacharlie/node-i2c.git
cd [your project dir]
npm install --save ~/tmp/node-i2c/

This should put the new i2c package in your node_modules and package.json. You would also want to remove any reference to the i2c package on npmjs.com.

@alphacharlie

I have a setup laying in the office, I'll test it tomorrow and report back

I installed node 4.4.5 and then the newest version of node-i2c on a Rasperry 1 B and it failed.
see:
npm-debug.txt

@Maus34 - how exactly did you try to install it? (you would have to download it from the link above not from npm...)
Try -

sudo apt-get update
sudo apt-get upgrade
mkdir tmp
cd tmp
git clone https://github.com/alphacharlie/node-i2c
npm install ./node-i2c

Note - I don't have a raspberry pi 1b to test with. But the above compiles and installs successfully for me on both Node 4.x and Node 6.x on the raspberry pi 2b. (Whether it actually works remains to be seen. I don't have the hardware set up to test it right now...)

@alphacharlie
I tried it again with exactly the commands above ( new download to tmp, that I dont used before)
see the last messages from the terminal
mess.txt
and the log file
npm-debug.txt
Maybe its a probem of rights

@Maus34 - Hmmm not sure what is going on... From your debug file it is trying to install it into ~/tmp/node_modules/i2c and failing. But from the commands I gave, it should just build in place in ~/tmp/node-i2c

Can you give more of the terminal output (mess.txt)? I think whatever the actual error was is probably 10-20 lines above what you\ posted...

@ Alphacharlie
seems the c++11 compiler was not foud
typescript.txt

@Maus34 - You might do -
sudo apt-get install build-essential
and try again.

Also, The code at https://github.com/alphacharlie/node-i2c has been updated. (I finished the conversion to the Nan module.) So anyone testing the fix will want to re-download it.

If it works for everybody I'll do a pull request and see if @kelly will merge it.

@alphacharlie
I checked with gcc --version 4.6.3
updated it to 4.8 (for C++11), search for: "raspberry c++11"
check with gcc --version 4.8
then it worked

@Maus34 - Huzzah!

If you get a chance to test it, please post back with any results... :-)

Hello All

Good News - Just got done testing this package on actual I2c hardware (ADS1015 ADC) and it worked for me without errors!

Looking for more developers to confirm that it also works for them. To test you can replace the dependency in the applicable Package.json file. So this:

"dependencies": {
  "i2c": "^0.2.1"
},

becomes this:

  "dependencies": {
    "i2c": "https://github.com/alphacharlie/node-i2c"
  }

then rebuild the your node app.

**Note - if you are an end user trying to fix a broken install, then you'll probably have to do -
npm install force
in your app directory, then go digging for the broken dependency. (or dependencies?) until the changes are merged.

commented

@alphacharlie awesome! Thanks for putting this together and making the switch to Nan. Send me a PR when you have a chance. I'll look everything over and get it merged in.

@alphacharlie
I start my application with node app.js for my node module node-HDC1000 and got the error
Cannot find module 'i2c'

@Maus34 - Can you post your package.json?