Hello there,
I’m trying to configure my rockpi 4 with armbian bionic. I would like to write a script that causes a reboot when i press a button. Sometimes i loose ssh access to my rock when Plex crashes. I’m trying to debug this but now every time when a crash occurs i have to get attach a monitor mouse and keyboard, log in and reboot.
I’ve found the following script for the raspberry pi, but can anyone please tell me how i can incorporate this for the rockpi running armbian ?
Shutdown button
Thank you in advance.
I just made a gpio switch doing “halt” system.
Maybe you just change “halt” to “reboot”.
It needs libmraa.
#include <mraa/gpio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
sig_atomic_t volatile run_flag = 1;
void do_when_interrupted(int sig)
{
if (sig ==SIGINT)
run_flag = 0;
}
int main()
{
mraa_gpio_context led, button;
led = mraa_gpio_init(3);
button = mraa_gpio_init(7); //GPIO 7pin is switch for “halt”
mraa_gpio_dir(led, MRAA_GPIO_OUT);
mraa_gpio_dir(button, MRAA_GPIO_IN);
signal(SIGINT, do_when_interrupted);
while(run_flag)
{
int i;
i = mraa_gpio_read(button);
printf("%d\n", i);
if(i) // when switch is on, just turn on and off a led.
{
mraa_gpio_write(led, 1);
sleep(1);
mraa_gpio_write(led,0);
sleep(1);
}
else //when the switch is off, system halt.
system("halt"); //system("reboot") will reboot the system.
}
mraa_gpio_close(led);
return 0;
}
It’s my first GPIO program.
And I learned it from https://lasr.cs.ucla.edu/classes/edison_tutorials/gpio.pdf.
1 Like
I just added a ESP-01 and flashed it with https://github.com/jeelabs/esp-link and now I can have wifi-to-serial. Connected to the debug-port (ttyS0, I use some OrangePi for the moment) and have locked the speed in getty to 115200.
This will work for most (all) of the SBC’s with a debug port.
I will do a “How I did” instruction soon.
1 Like
Wow all what a nice replies! Thank you!