JamesBarwell / rpi-gpio.js

Control Raspberry Pi GPIO pins with node.js
MIT License
657 stars 116 forks source link

Getting undefined when using promises #105

Open lffv opened 4 years ago

lffv commented 4 years ago

Hi Guys, I am getting undefined when trying to use promises. everything works well without promises, but when I change it to promises I am getting undefined from import.

Here is a sample code, any ideias?

var gpiop = require('rpi-gpio').promise;

gpiop.setup(38, gpiop.DIR_OUT)
    .then(() => {
        return gpiop.write(38, true)
    })
    .catch((err) => {
        console.log('Error: ', err.toString())
    })

The error is:

gpiop.setup(38, gpiop.DIR_OUT)
      ^

TypeError: Cannot read property 'setup' of undefined
    at Object.<anonymous> (/home/pi/Projects/RaspberryPiRelayControl/index.js:10:7)
JamesBarwell commented 4 years ago

That's really odd. Could you run these commands and give us the output, just to help sanity check?

node -v
npm ls

Maybe you could try running this as well to see what object is being imported, and why it seems to lack the promise interface:

var gpio = require('rpi-gpio');
console.log(gpio);