Background
I am trying to learn how to use the rpio
library (https://github.com/jperkin/node-rpio) in my nodejs application.
What do I want to do
So far I have been able to test the blink led example form the documentation, and I was trying to do the push button test ("Poll a button switch for events" as is it called at the documentation). I had copied the content of the example and tried to execute it both when a page loads, to execute it on the server-side through a post request, and tried also in simply executing it when the server starts. Here is the code:
rpio.open(15, rpio.INPUT, rpio.PULL_UP);
function pollcb(pin)
{
/*
* Wait for a small period of time to avoid rapid changes which
* can't all be caught with the 1ms polling frequency. If the
* pin is no longer down after the wait then ignore it.
*/
rpio.msleep(20);
if (rpio.read(pin))
return;
console.log('Button pressed on pin P%d', pin);
}
rpio.poll(15, pollcb, rpio.POLL_DOWN);
I am using the circuit schematic as shown at the image below:
The difference is that I dont have the switch, but I guess that just using wires to simulate the pessing of a button will do it
The problem
It is not working at all... Everytime when I call the function, my ssh command line gets stuck for 5-10 seconds and then my connection to the raspberry pi is reset, not allowing me to connect to the raspberry again; and then I have to unplug the raspberry to restart it! It is like the whole board collapses when I try to do this approach, which is also concerning me about the fact that I have to shut down my raspberry not in a safe way, what can consequently corrupt my sd card.
edit: It looks like that whenever I try to execute the rpio.poll function, it breaks the application and the board.
I appreciate any possible help about this issue.. Thank you!