Closed bellerofonte closed 6 years ago
I'm struggling to understand this one. I don't see why converting channel
to a string before using it to lookup an object property would make any difference, because all object keys in JS are automatically converted to be strings anyway.
> var foo = { '3': 2, '5': 3 };
undefined
> foo[3]
2
> foo['3']
2
The error you're getting looks to be due to currentPins
being undefined rather than anything to do the channel
value.
You started with "Then I call following". Is there some missing code that you run before this that could have affected the value of currentPins
? Could there be an error occurring somewhere further up in your code that isn't being caught?
Hi! This issue occurred after clean install of nodejs and all dependencies, inc. rpi-gpio.js This code:
const GPIO = require('rpi-gpio');
GPIO.setup(13, GPIO.DIR_LOW, err => { .... });
thrown error
TypeError: Cannot read property '13' of undefined
at getPinRpi (/opt/radiobox/node_modules/rpi-gpio/rpi-gpio.js:358:27)
The only change I have made was: 13 -> '13' and
const GPIO = require('rpi-gpio');
GPIO.setup('13', GPIO.DIR_LOW, err => { .... });
worked fine
Just tried to revert changes. As you have expected,
const GPIO = require('rpi-gpio');
GPIO.setup(13, GPIO.DIR_LOW, err => { .... });
now works fine too. Magic...
Maybe issue appeared after clean install and has gone since reboot or smth else. Anyway, I cannot reproduce it anymore, so closing the issue. Thanks for your response!
Hi! Then I call following:
GPIO.setup(13, GPIO.DIR_LOW, err => { .... });
I get error:and obviously there is an error:
and currentPins are:
The solution is: