fivdi / pigpio

Fast GPIO, PWM, servo control, state change notification and interrupt handling with Node.js on the Raspberry Pi
MIT License
948 stars 89 forks source link

pigpio C library is not available .... but it's there. #111

Closed adopudi closed 4 years ago

adopudi commented 4 years ago

OS: Raspbian 10.3 Node version: 14.2.0 Node module: gpio 3.2.1

I am trying to test the nodejs gpio module but got stuck with the following error:

pi@rpi:~/dev/server $ sudo node gpio-info
Warning: The pigpio C library is not available on this machine and any attempt to use it will fail.
/home/pi/dev/server/node_modules/pigpio/pigpio.js:29
    pigpio.gpioInitialise();
         ^

TypeError: pigpio.gpioInitialise is not a function
    at initializePigpio (/home/pi/dev/server/node_modules/pigpio/pigpio.js:29:12)
    at new Gpio (/home/pi/dev/server/node_modules/pigpio/pigpio.js:133:5)
    at Object.<anonymous> (/home/pi/dev/server/gpio-info.js:6:16)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)

From the error message it would seem the pigpio C library is not installed. But it's actually there:

pi@rpi:~/dev/server $ pigpiod -v
71

pi@rpi:~/dev/server $ ls -la /usr/include/pigpio*
-rw-r--r-- 1 root root 106391 Aug 14  2019 /usr/include/pigpiod_if2.h
-rw-r--r-- 1 root root  74503 Aug 14  2019 /usr/include/pigpiod_if.h
-rw-r--r-- 1 root root 154678 Aug 14  2019 /usr/include/pigpio.h

pi@rpi:~/dev/server $ ls -la /usr/bin/pigpio* 
-rwxr-xr-x 1 root root 9784 Aug 14  2019 /usr/bin/pigpiod

... and pigpiod is not running.

pi@rpi:~/dev/server $ ps aux | grep pigpio*
pi        1820  1.0  0.1   3252  1764 pts/0    S+   16:39   0:00 grep --color=auto pigpio*

I have uninstalled and reinstalled both the C library and nodejs module several times without any benefit.

Any help is appreciated.

fivdi commented 4 years ago

This issue is related to a recent change to the pigpio Node.js module. To help figure out what the problem is, can you please provide the following information:

What is the output of the following commands when run on the Raspberry Pi?

which pigpiod
which pigpiod | wc -l

And what is the output of the following commands when run on the Raspberry Pi?

cd /home/pi/dev/server/node_modules/pigpio
find .
adopudi commented 4 years ago

Here is the output of those commands:

pi@rpi:~/dev/server $ which pigpiod
/usr/bin/pigpiod
pi@rpi:~/dev/server $ which pigpiod | wc -l
1
pi@rpi:~/dev/server $ cd /home/pi/dev/server/node_modules/pigpio
pi@rpi:~/dev/server/node_modules/pigpio $ find .
.
./README.md
./.travis.yml
./LICENSE
./build
./build/pigpio.target.mk
./build/config.gypi
./build/Makefile
./build/binding.Makefile
./build/Release
./build/Release/.deps
./build/Release/.deps/Release
./build/Release/.deps/Release/obj.target
./build/Release/.deps/Release/obj.target/pigpio
./build/Release/.deps/Release/obj.target/pigpio/src
./build/Release/.deps/Release/obj.target/pigpio/src/pigpio.o.d
./build/Release/.deps/Release/obj.target/pigpio.node.d
./build/Release/.deps/Release/pigpio.node.d
./build/Release/obj.target
./build/Release/obj.target/pigpio
./build/Release/obj.target/pigpio/src
./build/Release/obj.target/pigpio/src/pigpio.o
./build/Release/obj.target/pigpio.node
./build/Release/pigpio.node
./binding.gyp
./pigpio.d.ts
./package.json
./test
./test/wave-add.js
./test/pwm.js
./test/stress
./test/stress/notifier-leak-check.js
./test/stress/notifier-stress.js
./test/light-switch.js
./test/gpio-numbers.js
./test/pulse-led.js
./test/notifier-pwm.js
./test/isr-timeouts.js
./test/isr-performance.js
./test/alert-pwm-measurement.js
./test/alert-trigger-pulse-measurement.js
./test/gpio-mode.js
./test/hardware-revision.js
./test/pull-up-down.js
./test/do-nothing.js
./test/isr-enable-disable.js
./test/isr-timeouts-2.js
./test/waves.js
./test/tick.js
./test/isr-multiple-sources.js
./test/wave-chain.js
./test/blinky-pwm.js
./test/notifier.js
./test/digital-read-performance.js
./test/terminate.js
./test/servo-control.js
./test/digital-write-performance.js
./test/alert.js
./test/blinky.js
./test/gpio-glitch-filter.js
./test/run-tests
./test/trigger-led.js
./test/banked-leds.js
./pigpio.js
./History.md
./example
./example/light-switch.js
./example/pulse-led.js
./example/servo.png
./example/waveform.js
./example/button-debounce.js
./example/distance-hc-sr04.png
./example/wave-chain.js
./example/gpio-info.js
./example/distance-hc-sr04.js
./example/button-debounce.png
./example/alert.js
./example/blinky.js
./example/servo.js
./example/led-button.png
./src
./src/pigpio.cc
./doc
./doc/troubleshooting.md
./doc/gpiobank.md
./doc/gpio.md
./doc/global.md
./doc/notifier.md
fivdi commented 4 years ago

Ok, that looks good.

What's the output of the following command:

sudo which pigpiod
adopudi commented 4 years ago
pi@rpi:~/dev/server/node_modules/pigpio $ sudo which pigpiod
/usr/bin/pigpiod
fivdi commented 4 years ago

Can you edit pigpio.js and replace these lines of code with this:

const pigpio = require('bindings')('pigpio.node');

Then try to run your test program again. I think an error will be thrown. Please post the complete exception stack trace.

adopudi commented 4 years ago
pi@rpi:~/dev/server $ sudo node gpio-info
/home/pi/dev/server/node_modules/bindings/bindings.js:121
        throw e;
        ^

Error: The module '/home/pi/dev/server/node_modules/pigpio/build/Release/pigpio.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 83. This version of Node.js requires
NODE_MODULE_VERSION 64. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:807:18)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at bindings (/home/pi/dev/server/node_modules/bindings/bindings.js:112:48)
    at Object.<anonymous> (/home/pi/dev/server/node_modules/pigpio/pigpio.js:21:35)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
pi@rpi:~/dev/server $ 
fivdi commented 4 years ago

We're getting there. Different major versions of Node.js were used at install time and run time. Perhaps this is because users root and pi have access to different versions of Node.js.

What's the output of the following commands:

node -v
sudo node -v
adopudi commented 4 years ago
pi@rpi:~/dev/server $ node -v
v14.2.0
pi@rpi:~/dev/server $ sudo node -v
v10.20.1
fivdi commented 4 years ago

This isn't a pigpio issue. The pi isn't set up correctly. You'll need to set it up so that users root and pi use the same version of Node.js.

fivdi commented 4 years ago

Alternatively, you could use the following command to run your application:

sudo $(which node) gpio-info
adopudi commented 4 years ago

This is the easiest option to fix it and it works great.

sudo $(which node) gpio-info

Thanks a lot for your help

fivdi commented 4 years ago

In order to see the error shown in this comment the code in pigpio.js had to be modified. The code had to be modified because it was swallowing the error and hiding it from the user. This isn't good and the error should be displayed.

fivdi commented 4 years ago

Fixed by 8c958c115f1f3c7b1b4bf049714d0c2a9ae5c3da