Button to Turn Browser on RPi On (and Off if possible) #981
Replies: 2 comments 1 reply
-
I adapted a Python script to start and stop the rAudio localbrowser service using two hardware buttons. However, this method has some quirks that I don't understand, which is explained in detail below. What I think would work better is if I could emulate the commands called when Browser on RPi in Features (BRPi) is turned on and off, but I couldn't figure out what those are. Here is the python script I used for the start button, located in an executable file: /usr/bin/hw_localbrowserstart.py
To make the script run automatically, I created a service file: /etc/systemd/system/hw_localbrowserstart.service
The python script for the stop button (/usr/bin/hw_localbrowserstop.py) was the same, except for the Pin Number (16) and the last line: I created a second service file: /etc/systemd/system/hw_localbrowserstop.service, which was the same as the start service, except it calls /usr/bin/hw_localbrowserstop.py. I enabled and started both services. When I normally start rAudio with BRPi ON, my screen starts white, switches to black, the rAudio logo appears, and the Browser starts up. When I turn rAudio off, the rAudio logo appears and the Pi shuts down. Now, with BRPi on, when I turn rAudio on, my Stop button turns off the browser and I get a black screen--just what I wanted. But my Start button to enable the browser does nothing. After logging in to rAudio from a browser on a PC and turning BRPi on again, my Stop button properly turns off the browser, but the Start button still does nothing. However, if I turn off rAudio with BRPi OFF, when I turn on rAudio, I get a terminal screen with the boot sequence. After boot is complete, my Start button will start the browser, but the Stop button does nothing. I can turn off the browser by turning off BRPi, and then turn the screen on again with my Start button. If I shut down rAudio at this point (with the browser on after a push of my Start button, I get a terminal shutdown readout, and the Pi shuts down. But when I start rAudio again, I get a terminal screen and my Start button does nothing. It seems that the only way I get workable functionality is to make sure I turn off BRPi before I shut down. Then when I turn on rAudio, I can turn on the browser using my Start button and turn off the browser by turning off BRPi. But as I said, this only works if I have BRPi off when I shut down. My Stop button only works if I start with BRPi On, but then my On button doesn't work, and I'm out of luck. Given the way these scripts operate, I clearly am doing something wrong, which is why it might be better if I could just emulate turning BRPi on and off using the hardware buttons. @rern , any ideas? Thanks very much!! rAudio 20220824, kernel 5.15.53-1, RPi4B, Adafruit 2.8" Capacitive Touchscreen (2423) |
Beta Was this translation helpful? Give feedback.
-
Try:
cat << 'EOF' > /srv/http/bash/localbrowserbutton.sh
#!/bin/bash
pin=13
setButton() {
gpio -1 mode $pin in
gpio -1 mode $pin up
gpio -1 wfi $pin falling
[[ $( systemctl is-active localbrowser ) == active ]] && systemctl stop localbrowser || systemctl start localbrowser
setButton
}
setButton
EOF
cat << EOF > /etc/systemd/system/localbrowserbutton.service
[Unit]
Description=GPIO button to start/stop localbrowser
After=localbrowser.service
[Service]
Type=simple
ExecStart=/srv/http/bash/localbrowserbutton.sh
[Install]
WantedBy=multi-user.target
EOF
chmod +x /srv/http/bash/localbrowserbutton.sh
systemctl enable --now localbrowserbutton
systemctl disable --now localbrowserbutton
rm /srv/http/bash/localbrowserbutton.sh /etc/systemd/system/localbrowserbutton.service |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm using a capacitive touchscreen (Adafruit 2.8" PiTFT No. 2443) on a Raspberry Pi 4 with an external USB DAC (Chord Mojo) in a portable 3D Printed Enclosure. I find that with this screen, I often get inadvertent screen touches when the device is in my pocket or when I handle it.
Since the Browser on RPi switch under Features works on the fly, I can turn off the screen on the portable device by turning off Browser on RPi, but then there is no way to turn the screen on again since the screen is off (except by logging into rAudio from another device and turning Browser on RPi on from there).
The Adafruit screen has 4 tactile buttons that are set to 4 GPIOs on the Pi. I use one of them to turn off the Pi. Does anyone know of a way I could program one of those buttons to turn the Browser on RPi switch on and off (or at least just on, since I can turn the browser off in the rAudio software).
Thanks very much!
Beta Was this translation helpful? Give feedback.
All reactions