This is how I did it:
- Clone MRAA to your system
git clone https://github.com/eclipse/mraa
- Install dependencies (removed nodejs-dev because it was giving error)
sudo apt-get install git build-essential swig3.0 python-dev cmake libjson-c-dev
- Modify gpio_advanced.c example to use your pin and your command
cd mraa/examples/c
sudo nano gpio_advanced.c
Modify #define GPIO_PIN 6
to pin that you want (not all pins work, pins 13, 22, 23, 24 seem to work).
Now lets modify interrupt code to use your command:
int_handler(void* args)
{
fprintf(stdout, "ISR triggered\n");
// Add your command here, I used: system("shutdown now");
}
In the bottom of the file, there is following line:
/* wait 30 seconds isr trigger */
sleep(30);
Modify it to be
while(1) {
sleep(30);
}
- Build mraa by following commands:
cd mraa
mkdir build
cd build
cmake ..
make
- Enable the pin that you used in the gpio_advanced.c example by doing following:
cd /sys/class/gpio
su root
echo 23 > export
after this command, when you type ls, pin23 should be visible.
- Run the program
su rock
cd mraa/build/examples/c
sudo ./gpio_advanced
If it gives you error, try other pin.
If it works, let me know. I can also show how to automate it inside shell script/service.