ni-c / heimcontrol.js

Home-Automation with node.js and Raspberry PI
MIT License
1.41k stars 297 forks source link

gpio input not working #101

Open kratostav opened 9 years ago

kratostav commented 9 years ago

Gpio input shows as down. It doesnt go up. raspberry pi revision 0000d

tjanson commented 9 years ago

What’s the output of ls /sys/devices/virtual/gpio? Without more info I’d suspect that the Pin isn’t exported, because, well, apparently the GPIO plugin doesn’t do that. So a manual gpio export [pin] in (where [pin] is the BCM pin number [why!?]) should fix it. Of course this really should be done by the plugin, or at least documented better.

kratostav commented 9 years ago

ls gives: pi@schretterpi ~ $ ls /sys/devices/virtual/gpio gpiochip0 pi@schretterpi ~ $

gpio export (command not found?? pi@schretterpi ~ $ gpio export pin 17 in -bash: gpio: command not found

Why is there a gpiochip0 only? Output is working properly

kratostav commented 9 years ago

got it working with pi@schretterpi ~ $ echo 17 > /sys/class/gpio/export pi@schretterpi ~ $ echo in > /sys/class/gpio/gpio17/direction

gpio

but why i have to do this manually?

tjanson commented 9 years ago

I’m not familiar with this part of the code. Looks like it was simply forgotten. I’ll look into it.

ni-c commented 9 years ago

Maybe it works if you change line 80 in plugins/gpio/index.js (https://github.com/ni-c/heimcontrol.js/blob/master/plugins/gpio/index.js#L80) from

gpio.setDirection(parseInt(item.pin), "input", function(err) {

to

gpio.open(parseInt(item.pin), "input", function(err) {

I have no time to test it now, but i think this could be the problem.

tjanson commented 9 years ago

I'm working on a fix. I'll rewrite the pi-gpio library.

Seems drastic, but it's overdue. Switching the underlying export mechanism from quick2wire's gpio-admin to Wiring Pi's gpio should improve lots of things including this issue, because its export can be called multiple times, whereas gpio-admin export errors if called on an open pin. (See rakeshpai/pi-gpio#24.)

tjanson commented 9 years ago

Here’s what I’ve been working on: tjanson/heimcontrol.js@ad79484f1ccd8cb130512be2df0e9868bbae7cb6 (which uses a rewritten version of pi-gpio, which uses a wrapper of Wiring Pi gpio util).

Feel free to give it a try. I’ll write a PR once I have some feedback here: rakeshpai/pi-gpio#25.