Need help with Node.js I2C /alternative
Maarten de Klerk last edited by Maarten de Klerk
For a project I want to read some data from my I2C sensor and post it to a blockchain. I use Ethereum and the Geth client (which works on the omega2+ with SWAP) for the blockchain. To interact with the smart contract I wanted to use Web3.js which I want to run on Node.js. To keep everything in node.js I decided it would be a good idea to install a I2C module for Node.js.
This turned out to be a problem because all I2C modules I have looked (i2c and i2c-bus) rely on node-gyp when building. node-gyp is a build tool to compile native addon modules for Node.js. It uses a library called lpthread which is a link to the pthread library source. The problem however is that gcc or g++ don't have this library (they have pthread but not lpthread). This causes a crash when trying to install the i2c library.
This is the error I get (I can also upload the full error log if necessary):
root@Omega-45B9:~/read_i2c# npm install --unsafe-perm -S i2c-bus npm WARN package.json firstname.lastname@example.org No description[0_1496260846988_error.txt](Uploading 100%) npm WARN package.json email@example.com No repository field. npm WARN package.json firstname.lastname@example.org No README data \ > email@example.com install /root/read_i2c/node_modules/i2c-bus > node-gyp rebuild make: Entering directory '/root/read_i2c/node_modules/i2c-bus/build' CXX(target) Release/obj.target/i2c/src/i2c.o SOLINK_MODULE(target) Release/obj.target/i2c.node /usr/bin/ld: cannot find -lpthread collect2: error: ld returned 1 exit status make: *** [i2c.target.mk:114: Release/obj.target/i2c.node] Error 1 make: Leaving directory '/root/read_i2c/node_modules/i2c-bus/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:270: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.4.46 gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /root/read_i2c/node_modules/i2c-bus gyp ERR! node -v v4.3.1 gyp ERR! node-gyp -v v3.0.3 gyp ERR! not ok npm ERR! Linux 4.4.46 npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "--unsafe-perm" "-S" "i2c-bus" npm ERR! node v4.3.1 npm ERR! npm v2.14.12 npm ERR! code ELIFECYCLE npm ERR! firstname.lastname@example.org install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the email@example.com install script 'node-gyp rebuild'. npm ERR! This is most likely a problem with the i2c-bus 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 their info via: npm ERR! npm owner ls i2c-bus npm ERR! There is likely additional logging output above. npm ERR! Please include the following file with any support request: npm ERR! /root/read_i2c/npm-debug.log
I have all the lasted version as of 31-05-2017:
omega: 0.1.10 b160
So the questions are:
Is there a workaround for this error?
Is there an alternative for this error?
I guess I could have python do the talking to the I2C and the link it to web3.js and node.js via RPC or something, but its not preferred.
get (I can also upload
I have same problem Need install i2c for node
I also needed lpthread so that I could install the i2c-bus module for the bme280-sensor package. Ended up running the code below and it worked.
ar -rc /usr/lib/libpthread.a
This created the missing file. Now npm has installed both i2c-bus and bme280-sensor.
Thanks to @Trey-Felton from this post: