TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: ALL
from: A. DUMAS
date: 2018-02-01 15:16:00
subject: Re: How to enable cgi scr

On 01/02/2018 12:38, Bengt Törnqvist wrote:
> One goal is to, via buttons in a browser html form), switch on and of
> equipment connected to a Rasberrypi in a remote room.
Simply have the server side script (cgi, python, php, whatever works on
your web server) call the "gpio" program. See "man gpio".

E.g. somewhere on a web page called switch.php: Device
1 = On. And in the php code section of that same switch.php:

if (isset($_GET['d1'])) {
 if (!strcmp($_GET['d1'], 'on')) {
  system('gpio -g mode 17 output');
  system('gpio -g write 17 1');
 }
}

(Cleaner/better/fancier would be to separate the display page and script
with the system call, and execute the script through an ajax call.)

Now you just have to figure out what permissions you need for the web
server user (www-data, probably) to be able to execute the gpio program.
If you go the sudo way (in the system call: sudo gpio etc.), which I
wouldn't recommend but is probably easiest, then you probably want to
use "sudo visudo" and add:

www-data ALL=(ALL) NOPASSWD: /usr/bin/gpio

Or, a completely different solution, move the logic to the client with
http://gpiozero.readthedocs.io/en/stable/remote_gpio.html

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.